├── .gitignore ├── Dockerfile ├── Gopkg.lock ├── Gopkg.toml ├── README.md ├── activity-simulator.go ├── cmd └── main.go └── vendor └── github.com ├── beorn7 └── perks │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ └── quantile │ ├── bench_test.go │ ├── example_test.go │ ├── exampledata.txt │ ├── stream.go │ └── stream_test.go ├── golang └── protobuf │ ├── .gitignore │ ├── .travis.yml │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── Make.protobuf │ ├── Makefile │ ├── README.md │ └── proto │ ├── Makefile │ ├── all_test.go │ ├── any_test.go │ ├── clone.go │ ├── clone_test.go │ ├── decode.go │ ├── decode_test.go │ ├── discard.go │ ├── encode.go │ ├── encode_test.go │ ├── equal.go │ ├── equal_test.go │ ├── extensions.go │ ├── extensions_test.go │ ├── lib.go │ ├── map_test.go │ ├── message_set.go │ ├── message_set_test.go │ ├── pointer_reflect.go │ ├── pointer_unsafe.go │ ├── properties.go │ ├── proto3_test.go │ ├── size2_test.go │ ├── size_test.go │ ├── text.go │ ├── text_parser.go │ ├── text_parser_test.go │ └── text_test.go ├── gorilla ├── context │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── context.go │ ├── context_test.go │ └── doc.go └── mux │ ├── .travis.yml │ ├── ISSUE_TEMPLATE.md │ ├── LICENSE │ ├── README.md │ ├── bench_test.go │ ├── context_gorilla.go │ ├── context_gorilla_test.go │ ├── context_native.go │ ├── context_native_test.go │ ├── doc.go │ ├── example_route_test.go │ ├── middleware.go │ ├── middleware_test.go │ ├── mux.go │ ├── mux_test.go │ ├── old_test.go │ ├── regexp.go │ ├── route.go │ └── test_helpers.go ├── matttproud └── golang_protobuf_extensions │ ├── .travis.yml │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ └── pbutil │ ├── all_test.go │ ├── decode.go │ ├── decode_test.go │ ├── doc.go │ ├── encode.go │ ├── encode_test.go │ └── fixtures_test.go └── prometheus ├── client_golang ├── .gitignore ├── .travis.yml ├── AUTHORS.md ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── VERSION └── prometheus │ ├── .gitignore │ ├── README.md │ ├── benchmark_test.go │ ├── collector.go │ ├── counter.go │ ├── counter_test.go │ ├── desc.go │ ├── doc.go │ ├── example_clustermanager_test.go │ ├── examples_test.go │ ├── expvar_collector.go │ ├── expvar_collector_test.go │ ├── fnv.go │ ├── gauge.go │ ├── gauge_test.go │ ├── go_collector.go │ ├── go_collector_test.go │ ├── histogram.go │ ├── histogram_test.go │ ├── http.go │ ├── http_test.go │ ├── metric.go │ ├── metric_test.go │ ├── process_collector.go │ ├── process_collector_test.go │ ├── promhttp │ ├── http.go │ └── http_test.go │ ├── registry.go │ ├── registry_test.go │ ├── summary.go │ ├── summary_test.go │ ├── untyped.go │ ├── value.go │ ├── vec.go │ └── vec_test.go ├── client_model ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── MAINTAINERS.md ├── Makefile ├── NOTICE ├── README.md ├── go │ └── metrics.pb.go ├── metrics.proto ├── pom.xml └── setup.py ├── common ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MAINTAINERS.md ├── NOTICE ├── README.md ├── expfmt │ ├── bench_test.go │ ├── decode.go │ ├── decode_test.go │ ├── encode.go │ ├── expfmt.go │ ├── fuzz.go │ ├── text_create.go │ ├── text_create_test.go │ ├── text_parse.go │ └── text_parse_test.go ├── internal │ └── bitbucket.org │ │ └── ww │ │ └── goautoneg │ │ ├── README.txt │ │ ├── autoneg.go │ │ └── autoneg_test.go └── model │ ├── alert.go │ ├── alert_test.go │ ├── fingerprinting.go │ ├── fnv.go │ ├── labels.go │ ├── labels_test.go │ ├── labelset.go │ ├── metric.go │ ├── metric_test.go │ ├── model.go │ ├── signature.go │ ├── signature_test.go │ ├── silence.go │ ├── silence_test.go │ ├── time.go │ ├── time_test.go │ ├── value.go │ └── value_test.go └── procfs ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MAINTAINERS.md ├── Makefile ├── NOTICE ├── README.md ├── buddyinfo.go ├── buddyinfo_test.go ├── doc.go ├── fs.go ├── fs_test.go ├── internal └── util │ └── parse.go ├── ipvs.go ├── ipvs_test.go ├── mdstat.go ├── mdstat_test.go ├── mountstats.go ├── mountstats_test.go ├── net_dev.go ├── net_dev_test.go ├── nfs ├── nfs.go ├── parse.go ├── parse_nfs.go ├── parse_nfs_test.go ├── parse_nfsd.go └── parse_nfsd_test.go ├── proc.go ├── proc_io.go ├── proc_io_test.go ├── proc_limits.go ├── proc_limits_test.go ├── proc_ns.go ├── proc_ns_test.go ├── proc_stat.go ├── proc_stat_test.go ├── proc_test.go ├── stat.go ├── stat_test.go ├── ttar ├── xfrm.go ├── xfrm_test.go └── xfs ├── parse.go ├── parse_test.go └── xfs.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Multi-stage Dockerfile 2 | 3 | FROM golang:1.9 4 | WORKDIR /go/src/github.com/PierreVincent/prom-http-simulator/ 5 | COPY vendor vendor 6 | COPY cmd cmd 7 | COPY *.go . 8 | RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -v -o bin/prom-http-simulator cmd/main.go 9 | 10 | FROM alpine:3.6 11 | COPY --from=0 /go/src/github.com/PierreVincent/prom-http-simulator/bin/prom-http-simulator /usr/local/bin/prom-http-simulator 12 | ENTRYPOINT ["prom-http-simulator"] -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | name = "github.com/beorn7/perks" 7 | packages = ["quantile"] 8 | revision = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9" 9 | 10 | [[projects]] 11 | name = "github.com/golang/protobuf" 12 | packages = ["proto"] 13 | revision = "925541529c1fa6821df4e44ce2723319eb2be768" 14 | version = "v1.0.0" 15 | 16 | [[projects]] 17 | name = "github.com/gorilla/context" 18 | packages = ["."] 19 | revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" 20 | version = "v1.1" 21 | 22 | [[projects]] 23 | name = "github.com/gorilla/mux" 24 | packages = ["."] 25 | revision = "53c1911da2b537f792e7cafcb446b05ffe33b996" 26 | version = "v1.6.1" 27 | 28 | [[projects]] 29 | name = "github.com/matttproud/golang_protobuf_extensions" 30 | packages = ["pbutil"] 31 | revision = "3247c84500bff8d9fb6d579d800f20b3e091582c" 32 | version = "v1.0.0" 33 | 34 | [[projects]] 35 | name = "github.com/prometheus/client_golang" 36 | packages = [ 37 | "prometheus", 38 | "prometheus/promhttp" 39 | ] 40 | revision = "c5b7fccd204277076155f10851dad72b76a49317" 41 | version = "v0.8.0" 42 | 43 | [[projects]] 44 | branch = "master" 45 | name = "github.com/prometheus/client_model" 46 | packages = ["go"] 47 | revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c" 48 | 49 | [[projects]] 50 | branch = "master" 51 | name = "github.com/prometheus/common" 52 | packages = [ 53 | "expfmt", 54 | "internal/bitbucket.org/ww/goautoneg", 55 | "model" 56 | ] 57 | revision = "89604d197083d4781071d3c65855d24ecfb0a563" 58 | 59 | [[projects]] 60 | branch = "master" 61 | name = "github.com/prometheus/procfs" 62 | packages = [ 63 | ".", 64 | "internal/util", 65 | "nfs", 66 | "xfs" 67 | ] 68 | revision = "cb4147076ac75738c9a7d279075a253c0cc5acbd" 69 | 70 | [solve-meta] 71 | analyzer-name = "dep" 72 | analyzer-version = 1 73 | inputs-digest = "7621e14e535d2a688b2df0e00bbd2e52df2de1eb75c117761fed29f8e5bf7b6f" 74 | solver-name = "gps-cdcl" 75 | solver-version = 1 76 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [prune] 2 | non-go = true 3 | 4 | [[constraint]] 5 | name = "github.com/gorilla/mux" 6 | version = "1.6.0" 7 | 8 | [[constraint]] 9 | name = "github.com/prometheus/client_golang" 10 | version = "0.8.0" 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prometheus HTTP Metrics Simulator 2 | 3 | This service simulates Prometheus metrics for what would be a simple HTTP API microservice. 4 | 5 | The simplest way to use this simulator is through the published docker image: 6 | 7 | ``` 8 | docker run -p 8080:8080 pierrevincent/prom-http-simulator:0.1 9 | ``` 10 | 11 | ## Exposed metrics 12 | 13 | It exposes the following Prometheus metrics under the `/metrics` endpoint: 14 | - Standard Golang metrics 15 | - `http_requests_total`: Request counter, label by `endpoint` and `status` 16 | - `http_request_duration_milliseconds`: Request latency histogram 17 | 18 | ## Runtime options 19 | 20 | Endpoints, request rate and latency profiles are hardcoded, but come with some uncertainty so that metrics look somewhat realistic. 21 | 22 | It is also possible to simulate variation of metrics while the service is running, 23 | 24 | ### Spike Mode 25 | 26 | Under spike mode, the number of requests is multiplied by a factor between 5 and 15, and latency is doubled. 27 | 28 | Spike mode can be on, off or random. Changing spike mode can be done with: 29 | ``` 30 | # ON 31 | curl -X POST http://SERVICE_URL:8080/spike/on 32 | 33 | # OFF 34 | curl -X POST http://SERVICE_URL:8080/spike/off 35 | 36 | # RANDOM 37 | curl -X POST http://SERVICE_URL:8080/spike/random 38 | ``` 39 | 40 | ### Error rate 41 | 42 | Error rate by default is 1%. It can be changed to a number between 0 and 100 with: 43 | ``` 44 | # Setting error rate to 50% 45 | curl -H 'Content-Type: application/json' -X PUT -d '{"error_rate": 50}' http://SERVICE_URL:8080/error_rate 46 | ``` 47 | -------------------------------------------------------------------------------- /cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus/promhttp" 5 | "net/http" 6 | "github.com/PierreVincent/prom-http-simulator" 7 | "github.com/gorilla/mux" 8 | "encoding/json" 9 | ) 10 | 11 | func main() { 12 | s := prom_http_simulator.NewSimulator(prom_http_simulator.SimulatorOpts{ 13 | Endpoints: []string{ 14 | "/login", "/login", "/login", "/login", "/login", "/login", "/login", 15 | "/users", "/users", "/users", 16 | "/users/{id}", 17 | "/register", "/register", 18 | "/logout", "/logout", "/logout", "/logout", 19 | }, 20 | 21 | RequestRate: 1000, 22 | RequestRateUncertainty: 70, 23 | 24 | LatencyMin: 10, 25 | LatencyP50: 25, 26 | LatencyP90: 150, 27 | LatencyP99: 750, 28 | LatencyMax: 10000, 29 | LatencyUncertainty: 70, 30 | 31 | ErrorRate: 1, 32 | 33 | SpikeStartChance: 5, 34 | SpikeEndChance: 30, 35 | }) 36 | go s.Run() 37 | startHTTPServer(s) 38 | } 39 | 40 | func startHTTPServer(s *prom_http_simulator.Simulator) { 41 | 42 | router := mux.NewRouter() 43 | router.KeepContext = true 44 | router.Handle("/spike/{mode}", newSpikeModeHandler(s)).Methods("POST") 45 | router.Handle("/error_rate", newErrorRateHandler(s)).Methods("PUT") 46 | 47 | router.Handle("/metrics", promhttp.Handler()) 48 | 49 | panic(http.ListenAndServe(":8080", router)) 50 | } 51 | 52 | func newSpikeModeHandler(s *prom_http_simulator.Simulator) http.HandlerFunc { 53 | return func(rw http.ResponseWriter, r *http.Request) { 54 | mode := mux.Vars(r)["mode"] 55 | s.SetSpikeMode(mode) 56 | } 57 | } 58 | 59 | func newErrorRateHandler(s *prom_http_simulator.Simulator) http.HandlerFunc { 60 | return func(rw http.ResponseWriter, r *http.Request) { 61 | decoder := json.NewDecoder(r.Body) 62 | defer r.Body.Close() 63 | 64 | var t struct{ ErrorRate int `json:"error_rate"` } 65 | err := decoder.Decode(&t) 66 | if err != nil { 67 | rw.WriteHeader(400) 68 | } 69 | s.SetErrorRate(t.ErrorRate) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/.gitignore: -------------------------------------------------------------------------------- 1 | *.test 2 | *.prof 3 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Blake Mizerany 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/README.md: -------------------------------------------------------------------------------- 1 | # Perks for Go (golang.org) 2 | 3 | Perks contains the Go package quantile that computes approximate quantiles over 4 | an unbounded data stream within low memory and CPU bounds. 5 | 6 | For more information and examples, see: 7 | http://godoc.org/github.com/bmizerany/perks 8 | 9 | A very special thank you and shout out to Graham Cormode (Rutgers University), 10 | Flip Korn (AT&T Labs–Research), S. Muthukrishnan (Rutgers University), and 11 | Divesh Srivastava (AT&T Labs–Research) for their research and publication of 12 | [Effective Computation of Biased Quantiles over Data Streams](http://www.cs.rutgers.edu/~muthu/bquant.pdf) 13 | 14 | Thank you, also: 15 | * Armon Dadgar (@armon) 16 | * Andrew Gerrand (@nf) 17 | * Brad Fitzpatrick (@bradfitz) 18 | * Keith Rarick (@kr) 19 | 20 | FAQ: 21 | 22 | Q: Why not move the quantile package into the project root? 23 | A: I want to add more packages to perks later. 24 | 25 | Copyright (C) 2013 Blake Mizerany 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/quantile/bench_test.go: -------------------------------------------------------------------------------- 1 | package quantile 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func BenchmarkInsertTargeted(b *testing.B) { 8 | b.ReportAllocs() 9 | 10 | s := NewTargeted(Targets) 11 | b.ResetTimer() 12 | for i := float64(0); i < float64(b.N); i++ { 13 | s.Insert(i) 14 | } 15 | } 16 | 17 | func BenchmarkInsertTargetedSmallEpsilon(b *testing.B) { 18 | s := NewTargeted(TargetsSmallEpsilon) 19 | b.ResetTimer() 20 | for i := float64(0); i < float64(b.N); i++ { 21 | s.Insert(i) 22 | } 23 | } 24 | 25 | func BenchmarkInsertBiased(b *testing.B) { 26 | s := NewLowBiased(0.01) 27 | b.ResetTimer() 28 | for i := float64(0); i < float64(b.N); i++ { 29 | s.Insert(i) 30 | } 31 | } 32 | 33 | func BenchmarkInsertBiasedSmallEpsilon(b *testing.B) { 34 | s := NewLowBiased(0.0001) 35 | b.ResetTimer() 36 | for i := float64(0); i < float64(b.N); i++ { 37 | s.Insert(i) 38 | } 39 | } 40 | 41 | func BenchmarkQuery(b *testing.B) { 42 | s := NewTargeted(Targets) 43 | for i := float64(0); i < 1e6; i++ { 44 | s.Insert(i) 45 | } 46 | b.ResetTimer() 47 | n := float64(b.N) 48 | for i := float64(0); i < n; i++ { 49 | s.Query(i / n) 50 | } 51 | } 52 | 53 | func BenchmarkQuerySmallEpsilon(b *testing.B) { 54 | s := NewTargeted(TargetsSmallEpsilon) 55 | for i := float64(0); i < 1e6; i++ { 56 | s.Insert(i) 57 | } 58 | b.ResetTimer() 59 | n := float64(b.N) 60 | for i := float64(0); i < n; i++ { 61 | s.Query(i / n) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/quantile/example_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.1 2 | 3 | package quantile_test 4 | 5 | import ( 6 | "bufio" 7 | "fmt" 8 | "log" 9 | "os" 10 | "strconv" 11 | "time" 12 | 13 | "github.com/beorn7/perks/quantile" 14 | ) 15 | 16 | func Example_simple() { 17 | ch := make(chan float64) 18 | go sendFloats(ch) 19 | 20 | // Compute the 50th, 90th, and 99th percentile. 21 | q := quantile.NewTargeted(map[float64]float64{ 22 | 0.50: 0.005, 23 | 0.90: 0.001, 24 | 0.99: 0.0001, 25 | }) 26 | for v := range ch { 27 | q.Insert(v) 28 | } 29 | 30 | fmt.Println("perc50:", q.Query(0.50)) 31 | fmt.Println("perc90:", q.Query(0.90)) 32 | fmt.Println("perc99:", q.Query(0.99)) 33 | fmt.Println("count:", q.Count()) 34 | // Output: 35 | // perc50: 5 36 | // perc90: 16 37 | // perc99: 223 38 | // count: 2388 39 | } 40 | 41 | func Example_mergeMultipleStreams() { 42 | // Scenario: 43 | // We have multiple database shards. On each shard, there is a process 44 | // collecting query response times from the database logs and inserting 45 | // them into a Stream (created via NewTargeted(0.90)), much like the 46 | // Simple example. These processes expose a network interface for us to 47 | // ask them to serialize and send us the results of their 48 | // Stream.Samples so we may Merge and Query them. 49 | // 50 | // NOTES: 51 | // * These sample sets are small, allowing us to get them 52 | // across the network much faster than sending the entire list of data 53 | // points. 54 | // 55 | // * For this to work correctly, we must supply the same quantiles 56 | // a priori the process collecting the samples supplied to NewTargeted, 57 | // even if we do not plan to query them all here. 58 | ch := make(chan quantile.Samples) 59 | getDBQuerySamples(ch) 60 | q := quantile.NewTargeted(map[float64]float64{0.90: 0.001}) 61 | for samples := range ch { 62 | q.Merge(samples) 63 | } 64 | fmt.Println("perc90:", q.Query(0.90)) 65 | } 66 | 67 | func Example_window() { 68 | // Scenario: We want the 90th, 95th, and 99th percentiles for each 69 | // minute. 70 | 71 | ch := make(chan float64) 72 | go sendStreamValues(ch) 73 | 74 | tick := time.NewTicker(1 * time.Minute) 75 | q := quantile.NewTargeted(map[float64]float64{ 76 | 0.90: 0.001, 77 | 0.95: 0.0005, 78 | 0.99: 0.0001, 79 | }) 80 | for { 81 | select { 82 | case t := <-tick.C: 83 | flushToDB(t, q.Samples()) 84 | q.Reset() 85 | case v := <-ch: 86 | q.Insert(v) 87 | } 88 | } 89 | } 90 | 91 | func sendStreamValues(ch chan float64) { 92 | // Use your imagination 93 | } 94 | 95 | func flushToDB(t time.Time, samples quantile.Samples) { 96 | // Use your imagination 97 | } 98 | 99 | // This is a stub for the above example. In reality this would hit the remote 100 | // servers via http or something like it. 101 | func getDBQuerySamples(ch chan quantile.Samples) {} 102 | 103 | func sendFloats(ch chan<- float64) { 104 | f, err := os.Open("exampledata.txt") 105 | if err != nil { 106 | log.Fatal(err) 107 | } 108 | sc := bufio.NewScanner(f) 109 | for sc.Scan() { 110 | b := sc.Bytes() 111 | v, err := strconv.ParseFloat(string(b), 64) 112 | if err != nil { 113 | log.Fatal(err) 114 | } 115 | ch <- v 116 | } 117 | if sc.Err() != nil { 118 | log.Fatal(sc.Err()) 119 | } 120 | close(ch) 121 | } 122 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.[568ao] 3 | *.ao 4 | *.so 5 | *.pyc 6 | ._* 7 | .nfs.* 8 | [568a].out 9 | *~ 10 | *.orig 11 | core 12 | _obj 13 | _test 14 | _testmain.go 15 | protoc-gen-go/testdata/multi/*.pb.go 16 | _conformance/_conformance 17 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.6.x 5 | - 1.7.x 6 | - 1.8.x 7 | - 1.9.x 8 | 9 | install: 10 | - go get -v -d -t github.com/golang/protobuf/... 11 | - curl -L https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip -o /tmp/protoc.zip 12 | - unzip /tmp/protoc.zip -d $HOME/protoc 13 | 14 | env: 15 | - PATH=$HOME/protoc/bin:$PATH 16 | 17 | script: 18 | - make all test 19 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/Make.protobuf: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Includable Makefile to add a rule for generating .pb.go files from .proto files 33 | # (Google protocol buffer descriptions). 34 | # Typical use if myproto.proto is a file in package mypackage in this directory: 35 | # 36 | # include $(GOROOT)/src/pkg/github.com/golang/protobuf/Make.protobuf 37 | 38 | %.pb.go: %.proto 39 | protoc --go_out=. $< 40 | 41 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 33 | all: install 34 | 35 | install: 36 | go install ./proto ./jsonpb ./ptypes 37 | go install ./protoc-gen-go 38 | 39 | test: 40 | go test ./proto ./jsonpb ./ptypes 41 | make -C protoc-gen-go/testdata test 42 | 43 | clean: 44 | go clean ./... 45 | 46 | nuke: 47 | go clean -i ./... 48 | 49 | regenerate: 50 | make -C protoc-gen-go/descriptor regenerate 51 | make -C protoc-gen-go/plugin regenerate 52 | make -C protoc-gen-go/testdata regenerate 53 | make -C proto/testdata regenerate 54 | make -C jsonpb/jsonpb_test_proto regenerate 55 | make -C _conformance regenerate 56 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/encode_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // +build go1.7 33 | 34 | package proto_test 35 | 36 | import ( 37 | "strconv" 38 | "testing" 39 | 40 | "github.com/golang/protobuf/proto" 41 | tpb "github.com/golang/protobuf/proto/proto3_proto" 42 | "github.com/golang/protobuf/ptypes" 43 | ) 44 | 45 | var ( 46 | blackhole []byte 47 | ) 48 | 49 | // BenchmarkAny creates increasingly large arbitrary Any messages. The type is always the 50 | // same. 51 | func BenchmarkAny(b *testing.B) { 52 | data := make([]byte, 1<<20) 53 | quantum := 1 << 10 54 | for i := uint(0); i <= 10; i++ { 55 | b.Run(strconv.Itoa(quantum<= len(headerBuf) { 46 | return bytesRead, errInvalidVarint 47 | } 48 | // We have to read byte by byte here to avoid reading more bytes 49 | // than required. Each read byte is appended to what we have 50 | // read before. 51 | newBytesRead, err := r.Read(headerBuf[bytesRead : bytesRead+1]) 52 | if newBytesRead == 0 { 53 | if err != nil { 54 | return bytesRead, err 55 | } 56 | // A Reader should not return (0, nil), but if it does, 57 | // it should be treated as no-op (according to the 58 | // Reader contract). So let's go on... 59 | continue 60 | } 61 | bytesRead += newBytesRead 62 | // Now present everything read so far to the varint decoder and 63 | // see if a varint can be decoded already. 64 | messageLength, varIntBytes = proto.DecodeVarint(headerBuf[:bytesRead]) 65 | } 66 | 67 | messageBuf := make([]byte, messageLength) 68 | newBytesRead, err := io.ReadFull(r, messageBuf) 69 | bytesRead += newBytesRead 70 | if err != nil { 71 | return bytesRead, err 72 | } 73 | 74 | return bytesRead, proto.Unmarshal(messageBuf, m) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "bytes" 19 | "io" 20 | "testing" 21 | "testing/iotest" 22 | ) 23 | 24 | func TestReadDelimitedIllegalVarint(t *testing.T) { 25 | t.Parallel() 26 | var tests = []struct { 27 | in []byte 28 | n int 29 | err error 30 | }{ 31 | { 32 | in: []byte{255, 255, 255, 255, 255}, 33 | n: 5, 34 | err: errInvalidVarint, 35 | }, 36 | { 37 | in: []byte{255, 255, 255, 255, 255, 255}, 38 | n: 5, 39 | err: errInvalidVarint, 40 | }, 41 | } 42 | for _, test := range tests { 43 | n, err := ReadDelimited(bytes.NewReader(test.in), nil) 44 | if got, want := n, test.n; got != want { 45 | t.Errorf("ReadDelimited(%#v, nil) = %#v, ?; want = %v#, ?", test.in, got, want) 46 | } 47 | if got, want := err, test.err; got != want { 48 | t.Errorf("ReadDelimited(%#v, nil) = ?, %#v; want = ?, %#v", test.in, got, want) 49 | } 50 | } 51 | } 52 | 53 | func TestReadDelimitedPrematureHeader(t *testing.T) { 54 | t.Parallel() 55 | var data = []byte{128, 5} // 256 + 256 + 128 56 | n, err := ReadDelimited(bytes.NewReader(data[0:1]), nil) 57 | if got, want := n, 1; got != want { 58 | t.Errorf("ReadDelimited(%#v, nil) = %#v, ?; want = %v#, ?", data[0:1], got, want) 59 | } 60 | if got, want := err, io.EOF; got != want { 61 | t.Errorf("ReadDelimited(%#v, nil) = ?, %#v; want = ?, %#v", data[0:1], got, want) 62 | } 63 | } 64 | 65 | func TestReadDelimitedPrematureBody(t *testing.T) { 66 | t.Parallel() 67 | var data = []byte{128, 5, 0, 0, 0} // 256 + 256 + 128 68 | n, err := ReadDelimited(bytes.NewReader(data[:]), nil) 69 | if got, want := n, 5; got != want { 70 | t.Errorf("ReadDelimited(%#v, nil) = %#v, ?; want = %v#, ?", data, got, want) 71 | } 72 | if got, want := err, io.ErrUnexpectedEOF; got != want { 73 | t.Errorf("ReadDelimited(%#v, nil) = ?, %#v; want = ?, %#v", data, got, want) 74 | } 75 | } 76 | 77 | func TestReadDelimitedPrematureHeaderIncremental(t *testing.T) { 78 | t.Parallel() 79 | var data = []byte{128, 5} // 256 + 256 + 128 80 | n, err := ReadDelimited(iotest.OneByteReader(bytes.NewReader(data[0:1])), nil) 81 | if got, want := n, 1; got != want { 82 | t.Errorf("ReadDelimited(%#v, nil) = %#v, ?; want = %v#, ?", data[0:1], got, want) 83 | } 84 | if got, want := err, io.EOF; got != want { 85 | t.Errorf("ReadDelimited(%#v, nil) = ?, %#v; want = ?, %#v", data[0:1], got, want) 86 | } 87 | } 88 | 89 | func TestReadDelimitedPrematureBodyIncremental(t *testing.T) { 90 | t.Parallel() 91 | var data = []byte{128, 5, 0, 0, 0} // 256 + 256 + 128 92 | n, err := ReadDelimited(iotest.OneByteReader(bytes.NewReader(data[:])), nil) 93 | if got, want := n, 5; got != want { 94 | t.Errorf("ReadDelimited(%#v, nil) = %#v, ?; want = %v#, ?", data, got, want) 95 | } 96 | if got, want := err, io.ErrUnexpectedEOF; got != want { 97 | t.Errorf("ReadDelimited(%#v, nil) = ?, %#v; want = ?, %#v", data, got, want) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package pbutil provides record length-delimited Protocol Buffer streaming. 16 | package pbutil 17 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "io" 20 | 21 | "github.com/golang/protobuf/proto" 22 | ) 23 | 24 | // WriteDelimited encodes and dumps a message to the provided writer prefixed 25 | // with a 32-bit varint indicating the length of the encoded message, producing 26 | // a length-delimited record stream, which can be used to chain together 27 | // encoded messages of the same type together in a file. It returns the total 28 | // number of bytes written and any applicable error. This is roughly 29 | // equivalent to the companion Java API's MessageLite#writeDelimitedTo. 30 | func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) { 31 | buffer, err := proto.Marshal(m) 32 | if err != nil { 33 | return 0, err 34 | } 35 | 36 | var buf [binary.MaxVarintLen32]byte 37 | encodedLength := binary.PutUvarint(buf[:], uint64(len(buffer))) 38 | 39 | sync, err := w.Write(buf[:encodedLength]) 40 | if err != nil { 41 | return sync, err 42 | } 43 | 44 | n, err = w.Write(buffer) 45 | return n + sync, err 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "bytes" 19 | "errors" 20 | "testing" 21 | 22 | "github.com/golang/protobuf/proto" 23 | ) 24 | 25 | var errMarshal = errors.New("pbutil: can't marshal") 26 | 27 | type cantMarshal struct{ proto.Message } 28 | 29 | func (cantMarshal) Marshal() ([]byte, error) { return nil, errMarshal } 30 | 31 | var _ proto.Message = cantMarshal{} 32 | 33 | func TestWriteDelimitedMarshalErr(t *testing.T) { 34 | t.Parallel() 35 | var data cantMarshal 36 | var buf bytes.Buffer 37 | n, err := WriteDelimited(&buf, data) 38 | if got, want := n, 0; got != want { 39 | t.Errorf("WriteDelimited(buf, %#v) = %#v, ?; want = %v#, ?", data, got, want) 40 | } 41 | if got, want := err, errMarshal; got != want { 42 | t.Errorf("WriteDelimited(buf, %#v) = ?, %#v; want = ?, %#v", data, got, want) 43 | } 44 | } 45 | 46 | type canMarshal struct{ proto.Message } 47 | 48 | func (canMarshal) Marshal() ([]byte, error) { return []byte{0, 1, 2, 3, 4, 5}, nil } 49 | 50 | var errWrite = errors.New("pbutil: can't write") 51 | 52 | type cantWrite struct{} 53 | 54 | func (cantWrite) Write([]byte) (int, error) { return 0, errWrite } 55 | 56 | func TestWriteDelimitedWriteErr(t *testing.T) { 57 | t.Parallel() 58 | var data canMarshal 59 | var buf cantWrite 60 | n, err := WriteDelimited(buf, data) 61 | if got, want := n, 0; got != want { 62 | t.Errorf("WriteDelimited(buf, %#v) = %#v, ?; want = %v#, ?", data, got, want) 63 | } 64 | if got, want := err, errWrite; got != want { 65 | t.Errorf("WriteDelimited(buf, %#v) = ?, %#v; want = ?, %#v", data, got, want) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // http://github.com/golang/protobuf/ 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | package pbutil 31 | 32 | import ( 33 | . "github.com/golang/protobuf/proto" 34 | . "github.com/golang/protobuf/proto/testdata" 35 | ) 36 | 37 | // FROM https://github.com/golang/protobuf/blob/master/proto/all_test.go. 38 | 39 | func initGoTestField() *GoTestField { 40 | f := new(GoTestField) 41 | f.Label = String("label") 42 | f.Type = String("type") 43 | return f 44 | } 45 | 46 | // These are all structurally equivalent but the tag numbers differ. 47 | // (It's remarkable that required, optional, and repeated all have 48 | // 8 letters.) 49 | func initGoTest_RequiredGroup() *GoTest_RequiredGroup { 50 | return &GoTest_RequiredGroup{ 51 | RequiredField: String("required"), 52 | } 53 | } 54 | 55 | func initGoTest_OptionalGroup() *GoTest_OptionalGroup { 56 | return &GoTest_OptionalGroup{ 57 | RequiredField: String("optional"), 58 | } 59 | } 60 | 61 | func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup { 62 | return &GoTest_RepeatedGroup{ 63 | RequiredField: String("repeated"), 64 | } 65 | } 66 | 67 | func initGoTest(setdefaults bool) *GoTest { 68 | pb := new(GoTest) 69 | if setdefaults { 70 | pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted) 71 | pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted) 72 | pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted) 73 | pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted) 74 | pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted) 75 | pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted) 76 | pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted) 77 | pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted) 78 | pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted) 79 | pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted) 80 | pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted 81 | pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted) 82 | pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted) 83 | } 84 | 85 | pb.Kind = GoTest_TIME.Enum() 86 | pb.RequiredField = initGoTestField() 87 | pb.F_BoolRequired = Bool(true) 88 | pb.F_Int32Required = Int32(3) 89 | pb.F_Int64Required = Int64(6) 90 | pb.F_Fixed32Required = Uint32(32) 91 | pb.F_Fixed64Required = Uint64(64) 92 | pb.F_Uint32Required = Uint32(3232) 93 | pb.F_Uint64Required = Uint64(6464) 94 | pb.F_FloatRequired = Float32(3232) 95 | pb.F_DoubleRequired = Float64(6464) 96 | pb.F_StringRequired = String("string") 97 | pb.F_BytesRequired = []byte("bytes") 98 | pb.F_Sint32Required = Int32(-32) 99 | pb.F_Sint64Required = Int64(-64) 100 | pb.Requiredgroup = initGoTest_RequiredGroup() 101 | 102 | return pb 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | *~ 25 | *# 26 | .build 27 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | 4 | go: 5 | - 1.5.4 6 | - 1.6.2 7 | 8 | script: 9 | - go test -short ./... 10 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/AUTHORS.md: -------------------------------------------------------------------------------- 1 | The Prometheus project was started by Matt T. Proud (emeritus) and 2 | Julius Volz in 2012. 3 | 4 | Maintainers of this repository: 5 | 6 | * Björn Rabenstein 7 | 8 | The following individuals have contributed code to this repository 9 | (listed in alphabetical order): 10 | 11 | * Bernerd Schaefer 12 | * Björn Rabenstein 13 | * Daniel Bornkessel 14 | * Jeff Younker 15 | * Julius Volz 16 | * Matt T. Proud 17 | * Tobias Schmidt 18 | 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull 6 | request, addressing (with `@...`) one or more of the maintainers 7 | (see [AUTHORS.md](AUTHORS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/NOTICE: -------------------------------------------------------------------------------- 1 | Prometheus instrumentation library for Go applications 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | 7 | 8 | The following components are included in this product: 9 | 10 | perks - a fork of https://github.com/bmizerany/perks 11 | https://github.com/beorn7/perks 12 | Copyright 2013-2015 Blake Mizerany, Björn Rabenstein 13 | See https://github.com/beorn7/perks/blob/master/README.md for license details. 14 | 15 | Go support for Protocol Buffers - Google's data interchange format 16 | http://github.com/golang/protobuf/ 17 | Copyright 2010 The Go Authors 18 | See source code for license details. 19 | 20 | Support for streaming Protocol Buffer messages for the Go language (golang). 21 | https://github.com/matttproud/golang_protobuf_extensions 22 | Copyright 2013 Matt T. Proud 23 | Licensed under the Apache License, Version 2.0 24 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/README.md: -------------------------------------------------------------------------------- 1 | # Prometheus Go client library 2 | 3 | [![Build Status](https://travis-ci.org/prometheus/client_golang.svg?branch=master)](https://travis-ci.org/prometheus/client_golang) 4 | 5 | This is the [Go](http://golang.org) client library for 6 | [Prometheus](http://prometheus.io). It has two separate parts, one for 7 | instrumenting application code, and one for creating clients that talk to the 8 | Prometheus HTTP API. 9 | 10 | ## Instrumenting applications 11 | 12 | [![code-coverage](http://gocover.io/_badge/github.com/prometheus/client_golang/prometheus)](http://gocover.io/github.com/prometheus/client_golang/prometheus) [![go-doc](https://godoc.org/github.com/prometheus/client_golang/prometheus?status.svg)](https://godoc.org/github.com/prometheus/client_golang/prometheus) 13 | 14 | The 15 | [`prometheus` directory](https://github.com/prometheus/client_golang/tree/master/prometheus) 16 | contains the instrumentation library. See the 17 | [best practices section](http://prometheus.io/docs/practices/naming/) of the 18 | Prometheus documentation to learn more about instrumenting applications. 19 | 20 | The 21 | [`examples` directory](https://github.com/prometheus/client_golang/tree/master/examples) 22 | contains simple examples of instrumented code. 23 | 24 | ## Client for the Prometheus HTTP API 25 | 26 | [![code-coverage](http://gocover.io/_badge/github.com/prometheus/client_golang/api/prometheus)](http://gocover.io/github.com/prometheus/client_golang/api/prometheus) [![go-doc](https://godoc.org/github.com/prometheus/client_golang/api/prometheus?status.svg)](https://godoc.org/github.com/prometheus/client_golang/api/prometheus) 27 | 28 | The 29 | [`api/prometheus` directory](https://github.com/prometheus/client_golang/tree/master/api/prometheus) 30 | contains the client for the 31 | [Prometheus HTTP API](http://prometheus.io/docs/querying/api/). It allows you 32 | to write Go applications that query time series data from a Prometheus server. 33 | 34 | ## Where is `model`, `extraction`, and `text`? 35 | 36 | The `model` packages has been moved to 37 | [`prometheus/common/model`](https://github.com/prometheus/common/tree/master/model). 38 | 39 | The `extraction` and `text` packages are now contained in 40 | [`prometheus/common/expfmt`](https://github.com/prometheus/common/tree/master/expfmt). 41 | 42 | ## Contributing and community 43 | 44 | See the [contributing guidelines](CONTRIBUTING.md) and the 45 | [Community section](http://prometheus.io/community/) of the homepage. 46 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/VERSION: -------------------------------------------------------------------------------- 1 | 0.8.0 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | command-line-arguments.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/README.md: -------------------------------------------------------------------------------- 1 | See [![go-doc](https://godoc.org/github.com/prometheus/client_golang/prometheus?status.svg)](https://godoc.org/github.com/prometheus/client_golang/prometheus). 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/collector.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | // Collector is the interface implemented by anything that can be used by 17 | // Prometheus to collect metrics. A Collector has to be registered for 18 | // collection. See Registerer.Register. 19 | // 20 | // The stock metrics provided by this package (Gauge, Counter, Summary, 21 | // Histogram, Untyped) are also Collectors (which only ever collect one metric, 22 | // namely itself). An implementer of Collector may, however, collect multiple 23 | // metrics in a coordinated fashion and/or create metrics on the fly. Examples 24 | // for collectors already implemented in this library are the metric vectors 25 | // (i.e. collection of multiple instances of the same Metric but with different 26 | // label values) like GaugeVec or SummaryVec, and the ExpvarCollector. 27 | type Collector interface { 28 | // Describe sends the super-set of all possible descriptors of metrics 29 | // collected by this Collector to the provided channel and returns once 30 | // the last descriptor has been sent. The sent descriptors fulfill the 31 | // consistency and uniqueness requirements described in the Desc 32 | // documentation. (It is valid if one and the same Collector sends 33 | // duplicate descriptors. Those duplicates are simply ignored. However, 34 | // two different Collectors must not send duplicate descriptors.) This 35 | // method idempotently sends the same descriptors throughout the 36 | // lifetime of the Collector. If a Collector encounters an error while 37 | // executing this method, it must send an invalid descriptor (created 38 | // with NewInvalidDesc) to signal the error to the registry. 39 | Describe(chan<- *Desc) 40 | // Collect is called by the Prometheus registry when collecting 41 | // metrics. The implementation sends each collected metric via the 42 | // provided channel and returns once the last metric has been sent. The 43 | // descriptor of each sent metric is one of those returned by 44 | // Describe. Returned metrics that share the same descriptor must differ 45 | // in their variable label values. This method may be called 46 | // concurrently and must therefore be implemented in a concurrency safe 47 | // way. Blocking occurs at the expense of total performance of rendering 48 | // all registered metrics. Ideally, Collector implementations support 49 | // concurrent readers. 50 | Collect(chan<- Metric) 51 | } 52 | 53 | // selfCollector implements Collector for a single Metric so that the Metric 54 | // collects itself. Add it as an anonymous field to a struct that implements 55 | // Metric, and call init with the Metric itself as an argument. 56 | type selfCollector struct { 57 | self Metric 58 | } 59 | 60 | // init provides the selfCollector with a reference to the metric it is supposed 61 | // to collect. It is usually called within the factory function to create a 62 | // metric. See example. 63 | func (c *selfCollector) init(self Metric) { 64 | c.self = self 65 | } 66 | 67 | // Describe implements Collector. 68 | func (c *selfCollector) Describe(ch chan<- *Desc) { 69 | ch <- c.self.Desc() 70 | } 71 | 72 | // Collect implements Collector. 73 | func (c *selfCollector) Collect(ch chan<- Metric) { 74 | ch <- c.self 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/counter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | import ( 17 | "math" 18 | "testing" 19 | 20 | dto "github.com/prometheus/client_model/go" 21 | ) 22 | 23 | func TestCounterAdd(t *testing.T) { 24 | counter := NewCounter(CounterOpts{ 25 | Name: "test", 26 | Help: "test help", 27 | ConstLabels: Labels{"a": "1", "b": "2"}, 28 | }).(*counter) 29 | counter.Inc() 30 | if expected, got := 1., math.Float64frombits(counter.valBits); expected != got { 31 | t.Errorf("Expected %f, got %f.", expected, got) 32 | } 33 | counter.Add(42) 34 | if expected, got := 43., math.Float64frombits(counter.valBits); expected != got { 35 | t.Errorf("Expected %f, got %f.", expected, got) 36 | } 37 | 38 | if expected, got := "counter cannot decrease in value", decreaseCounter(counter).Error(); expected != got { 39 | t.Errorf("Expected error %q, got %q.", expected, got) 40 | } 41 | 42 | m := &dto.Metric{} 43 | counter.Write(m) 44 | 45 | if expected, got := `label: label: counter: `, m.String(); expected != got { 46 | t.Errorf("expected %q, got %q", expected, got) 47 | } 48 | } 49 | 50 | func decreaseCounter(c *counter) (err error) { 51 | defer func() { 52 | if e := recover(); e != nil { 53 | err = e.(error) 54 | } 55 | }() 56 | c.Add(-1) 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | import ( 17 | "encoding/json" 18 | "expvar" 19 | ) 20 | 21 | type expvarCollector struct { 22 | exports map[string]*Desc 23 | } 24 | 25 | // NewExpvarCollector returns a newly allocated expvar Collector that still has 26 | // to be registered with a Prometheus registry. 27 | // 28 | // An expvar Collector collects metrics from the expvar interface. It provides a 29 | // quick way to expose numeric values that are already exported via expvar as 30 | // Prometheus metrics. Note that the data models of expvar and Prometheus are 31 | // fundamentally different, and that the expvar Collector is inherently slower 32 | // than native Prometheus metrics. Thus, the expvar Collector is probably great 33 | // for experiments and prototying, but you should seriously consider a more 34 | // direct implementation of Prometheus metrics for monitoring production 35 | // systems. 36 | // 37 | // The exports map has the following meaning: 38 | // 39 | // The keys in the map correspond to expvar keys, i.e. for every expvar key you 40 | // want to export as Prometheus metric, you need an entry in the exports 41 | // map. The descriptor mapped to each key describes how to export the expvar 42 | // value. It defines the name and the help string of the Prometheus metric 43 | // proxying the expvar value. The type will always be Untyped. 44 | // 45 | // For descriptors without variable labels, the expvar value must be a number or 46 | // a bool. The number is then directly exported as the Prometheus sample 47 | // value. (For a bool, 'false' translates to 0 and 'true' to 1). Expvar values 48 | // that are not numbers or bools are silently ignored. 49 | // 50 | // If the descriptor has one variable label, the expvar value must be an expvar 51 | // map. The keys in the expvar map become the various values of the one 52 | // Prometheus label. The values in the expvar map must be numbers or bools again 53 | // as above. 54 | // 55 | // For descriptors with more than one variable label, the expvar must be a 56 | // nested expvar map, i.e. where the values of the topmost map are maps again 57 | // etc. until a depth is reached that corresponds to the number of labels. The 58 | // leaves of that structure must be numbers or bools as above to serve as the 59 | // sample values. 60 | // 61 | // Anything that does not fit into the scheme above is silently ignored. 62 | func NewExpvarCollector(exports map[string]*Desc) Collector { 63 | return &expvarCollector{ 64 | exports: exports, 65 | } 66 | } 67 | 68 | // Describe implements Collector. 69 | func (e *expvarCollector) Describe(ch chan<- *Desc) { 70 | for _, desc := range e.exports { 71 | ch <- desc 72 | } 73 | } 74 | 75 | // Collect implements Collector. 76 | func (e *expvarCollector) Collect(ch chan<- Metric) { 77 | for name, desc := range e.exports { 78 | var m Metric 79 | expVar := expvar.Get(name) 80 | if expVar == nil { 81 | continue 82 | } 83 | var v interface{} 84 | labels := make([]string, len(desc.variableLabels)) 85 | if err := json.Unmarshal([]byte(expVar.String()), &v); err != nil { 86 | ch <- NewInvalidMetric(desc, err) 87 | continue 88 | } 89 | var processValue func(v interface{}, i int) 90 | processValue = func(v interface{}, i int) { 91 | if i >= len(labels) { 92 | copiedLabels := append(make([]string, 0, len(labels)), labels...) 93 | switch v := v.(type) { 94 | case float64: 95 | m = MustNewConstMetric(desc, UntypedValue, v, copiedLabels...) 96 | case bool: 97 | if v { 98 | m = MustNewConstMetric(desc, UntypedValue, 1, copiedLabels...) 99 | } else { 100 | m = MustNewConstMetric(desc, UntypedValue, 0, copiedLabels...) 101 | } 102 | default: 103 | return 104 | } 105 | ch <- m 106 | return 107 | } 108 | vm, ok := v.(map[string]interface{}) 109 | if !ok { 110 | return 111 | } 112 | for lv, val := range vm { 113 | labels[i] = lv 114 | processValue(val, i+1) 115 | } 116 | } 117 | processValue(v, 0) 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/expvar_collector_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus_test 15 | 16 | import ( 17 | "expvar" 18 | "fmt" 19 | "sort" 20 | "strings" 21 | 22 | dto "github.com/prometheus/client_model/go" 23 | 24 | "github.com/prometheus/client_golang/prometheus" 25 | ) 26 | 27 | func ExampleExpvarCollector() { 28 | expvarCollector := prometheus.NewExpvarCollector(map[string]*prometheus.Desc{ 29 | "memstats": prometheus.NewDesc( 30 | "expvar_memstats", 31 | "All numeric memstats as one metric family. Not a good role-model, actually... ;-)", 32 | []string{"type"}, nil, 33 | ), 34 | "lone-int": prometheus.NewDesc( 35 | "expvar_lone_int", 36 | "Just an expvar int as an example.", 37 | nil, nil, 38 | ), 39 | "http-request-map": prometheus.NewDesc( 40 | "expvar_http_request_total", 41 | "How many http requests processed, partitioned by status code and http method.", 42 | []string{"code", "method"}, nil, 43 | ), 44 | }) 45 | prometheus.MustRegister(expvarCollector) 46 | 47 | // The Prometheus part is done here. But to show that this example is 48 | // doing anything, we have to manually export something via expvar. In 49 | // real-life use-cases, some library would already have exported via 50 | // expvar what we want to re-export as Prometheus metrics. 51 | expvar.NewInt("lone-int").Set(42) 52 | expvarMap := expvar.NewMap("http-request-map") 53 | var ( 54 | expvarMap1, expvarMap2 expvar.Map 55 | expvarInt11, expvarInt12, expvarInt21, expvarInt22 expvar.Int 56 | ) 57 | expvarMap1.Init() 58 | expvarMap2.Init() 59 | expvarInt11.Set(3) 60 | expvarInt12.Set(13) 61 | expvarInt21.Set(11) 62 | expvarInt22.Set(212) 63 | expvarMap1.Set("POST", &expvarInt11) 64 | expvarMap1.Set("GET", &expvarInt12) 65 | expvarMap2.Set("POST", &expvarInt21) 66 | expvarMap2.Set("GET", &expvarInt22) 67 | expvarMap.Set("404", &expvarMap1) 68 | expvarMap.Set("200", &expvarMap2) 69 | // Results in the following expvar map: 70 | // "http-request-count": {"200": {"POST": 11, "GET": 212}, "404": {"POST": 3, "GET": 13}} 71 | 72 | // Let's see what the scrape would yield, but exclude the memstats metrics. 73 | metricStrings := []string{} 74 | metric := dto.Metric{} 75 | metricChan := make(chan prometheus.Metric) 76 | go func() { 77 | expvarCollector.Collect(metricChan) 78 | close(metricChan) 79 | }() 80 | for m := range metricChan { 81 | if strings.Index(m.Desc().String(), "expvar_memstats") == -1 { 82 | metric.Reset() 83 | m.Write(&metric) 84 | metricStrings = append(metricStrings, metric.String()) 85 | } 86 | } 87 | sort.Strings(metricStrings) 88 | for _, s := range metricStrings { 89 | fmt.Println(strings.TrimRight(s, " ")) 90 | } 91 | // Output: 92 | // label: label: untyped: 93 | // label: label: untyped: 94 | // label: label: untyped: 95 | // label: label: untyped: 96 | // untyped: 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/fnv.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | // Inline and byte-free variant of hash/fnv's fnv64a. 4 | 5 | const ( 6 | offset64 = 14695981039346656037 7 | prime64 = 1099511628211 8 | ) 9 | 10 | // hashNew initializies a new fnv64a hash value. 11 | func hashNew() uint64 { 12 | return offset64 13 | } 14 | 15 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 16 | func hashAdd(h uint64, s string) uint64 { 17 | for i := 0; i < len(s); i++ { 18 | h ^= uint64(s[i]) 19 | h *= prime64 20 | } 21 | return h 22 | } 23 | 24 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 25 | func hashAddByte(h uint64, b byte) uint64 { 26 | h ^= uint64(b) 27 | h *= prime64 28 | return h 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/go_collector_test.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | "time" 7 | 8 | dto "github.com/prometheus/client_model/go" 9 | ) 10 | 11 | func TestGoCollector(t *testing.T) { 12 | var ( 13 | c = NewGoCollector() 14 | ch = make(chan Metric) 15 | waitc = make(chan struct{}) 16 | closec = make(chan struct{}) 17 | old = -1 18 | ) 19 | defer close(closec) 20 | 21 | go func() { 22 | c.Collect(ch) 23 | go func(c <-chan struct{}) { 24 | <-c 25 | }(closec) 26 | <-waitc 27 | c.Collect(ch) 28 | }() 29 | 30 | for { 31 | select { 32 | case metric := <-ch: 33 | switch m := metric.(type) { 34 | // Attention, this also catches Counter... 35 | case Gauge: 36 | pb := &dto.Metric{} 37 | m.Write(pb) 38 | if pb.GetGauge() == nil { 39 | continue 40 | } 41 | 42 | if old == -1 { 43 | old = int(pb.GetGauge().GetValue()) 44 | close(waitc) 45 | continue 46 | } 47 | 48 | if diff := int(pb.GetGauge().GetValue()) - old; diff != 1 { 49 | // TODO: This is flaky in highly concurrent situations. 50 | t.Errorf("want 1 new goroutine, got %d", diff) 51 | } 52 | 53 | // GoCollector performs two sends per call. 54 | // On line 27 we need to receive the second send 55 | // to shut down cleanly. 56 | <-ch 57 | return 58 | } 59 | case <-time.After(1 * time.Second): 60 | t.Fatalf("expected collect timed out") 61 | } 62 | } 63 | } 64 | 65 | func TestGCCollector(t *testing.T) { 66 | var ( 67 | c = NewGoCollector() 68 | ch = make(chan Metric) 69 | waitc = make(chan struct{}) 70 | closec = make(chan struct{}) 71 | oldGC uint64 72 | oldPause float64 73 | ) 74 | defer close(closec) 75 | 76 | go func() { 77 | c.Collect(ch) 78 | // force GC 79 | runtime.GC() 80 | <-waitc 81 | c.Collect(ch) 82 | }() 83 | 84 | first := true 85 | for { 86 | select { 87 | case metric := <-ch: 88 | switch m := metric.(type) { 89 | case *constSummary, *value: 90 | pb := &dto.Metric{} 91 | m.Write(pb) 92 | if pb.GetSummary() == nil { 93 | continue 94 | } 95 | 96 | if len(pb.GetSummary().Quantile) != 5 { 97 | t.Errorf("expected 4 buckets, got %d", len(pb.GetSummary().Quantile)) 98 | } 99 | for idx, want := range []float64{0.0, 0.25, 0.5, 0.75, 1.0} { 100 | if *pb.GetSummary().Quantile[idx].Quantile != want { 101 | t.Errorf("bucket #%d is off, got %f, want %f", idx, *pb.GetSummary().Quantile[idx].Quantile, want) 102 | } 103 | } 104 | if first { 105 | first = false 106 | oldGC = *pb.GetSummary().SampleCount 107 | oldPause = *pb.GetSummary().SampleSum 108 | close(waitc) 109 | continue 110 | } 111 | if diff := *pb.GetSummary().SampleCount - oldGC; diff != 1 { 112 | t.Errorf("want 1 new garbage collection run, got %d", diff) 113 | } 114 | if diff := *pb.GetSummary().SampleSum - oldPause; diff <= 0 { 115 | t.Errorf("want moar pause, got %f", diff) 116 | } 117 | return 118 | } 119 | case <-time.After(1 * time.Second): 120 | t.Fatalf("expected collect timed out") 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/http_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | import ( 17 | "net/http" 18 | "net/http/httptest" 19 | "testing" 20 | "time" 21 | 22 | dto "github.com/prometheus/client_model/go" 23 | ) 24 | 25 | type respBody string 26 | 27 | func (b respBody) ServeHTTP(w http.ResponseWriter, r *http.Request) { 28 | w.WriteHeader(http.StatusTeapot) 29 | w.Write([]byte(b)) 30 | } 31 | 32 | func TestInstrumentHandler(t *testing.T) { 33 | defer func(n nower) { 34 | now = n.(nower) 35 | }(now) 36 | 37 | instant := time.Now() 38 | end := instant.Add(30 * time.Second) 39 | now = nowSeries(instant, end) 40 | respBody := respBody("Howdy there!") 41 | 42 | hndlr := InstrumentHandler("test-handler", respBody) 43 | 44 | opts := SummaryOpts{ 45 | Subsystem: "http", 46 | ConstLabels: Labels{"handler": "test-handler"}, 47 | } 48 | 49 | reqCnt := MustRegisterOrGet(NewCounterVec( 50 | CounterOpts{ 51 | Namespace: opts.Namespace, 52 | Subsystem: opts.Subsystem, 53 | Name: "requests_total", 54 | Help: "Total number of HTTP requests made.", 55 | ConstLabels: opts.ConstLabels, 56 | }, 57 | instLabels, 58 | )).(*CounterVec) 59 | 60 | opts.Name = "request_duration_microseconds" 61 | opts.Help = "The HTTP request latencies in microseconds." 62 | reqDur := MustRegisterOrGet(NewSummary(opts)).(Summary) 63 | 64 | opts.Name = "request_size_bytes" 65 | opts.Help = "The HTTP request sizes in bytes." 66 | MustRegisterOrGet(NewSummary(opts)) 67 | 68 | opts.Name = "response_size_bytes" 69 | opts.Help = "The HTTP response sizes in bytes." 70 | MustRegisterOrGet(NewSummary(opts)) 71 | 72 | reqCnt.Reset() 73 | 74 | resp := httptest.NewRecorder() 75 | req := &http.Request{ 76 | Method: "GET", 77 | } 78 | 79 | hndlr.ServeHTTP(resp, req) 80 | 81 | if resp.Code != http.StatusTeapot { 82 | t.Fatalf("expected status %d, got %d", http.StatusTeapot, resp.Code) 83 | } 84 | if string(resp.Body.Bytes()) != "Howdy there!" { 85 | t.Fatalf("expected body %s, got %s", "Howdy there!", string(resp.Body.Bytes())) 86 | } 87 | 88 | out := &dto.Metric{} 89 | reqDur.Write(out) 90 | if want, got := "test-handler", out.Label[0].GetValue(); want != got { 91 | t.Errorf("want label value %q in reqDur, got %q", want, got) 92 | } 93 | if want, got := uint64(1), out.Summary.GetSampleCount(); want != got { 94 | t.Errorf("want sample count %d in reqDur, got %d", want, got) 95 | } 96 | 97 | out.Reset() 98 | if want, got := 1, len(reqCnt.children); want != got { 99 | t.Errorf("want %d children in reqCnt, got %d", want, got) 100 | } 101 | cnt, err := reqCnt.GetMetricWithLabelValues("get", "418") 102 | if err != nil { 103 | t.Fatal(err) 104 | } 105 | cnt.Write(out) 106 | if want, got := "418", out.Label[0].GetValue(); want != got { 107 | t.Errorf("want label value %q in reqCnt, got %q", want, got) 108 | } 109 | if want, got := "test-handler", out.Label[1].GetValue(); want != got { 110 | t.Errorf("want label value %q in reqCnt, got %q", want, got) 111 | } 112 | if want, got := "get", out.Label[2].GetValue(); want != got { 113 | t.Errorf("want label value %q in reqCnt, got %q", want, got) 114 | } 115 | if out.Counter == nil { 116 | t.Fatal("expected non-nil counter in reqCnt") 117 | } 118 | if want, got := 1., out.Counter.GetValue(); want != got { 119 | t.Errorf("want reqCnt of %f, got %f", want, got) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/metric_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | import "testing" 17 | 18 | func TestBuildFQName(t *testing.T) { 19 | scenarios := []struct{ namespace, subsystem, name, result string }{ 20 | {"a", "b", "c", "a_b_c"}, 21 | {"", "b", "c", "b_c"}, 22 | {"a", "", "c", "a_c"}, 23 | {"", "", "c", "c"}, 24 | {"a", "b", "", ""}, 25 | {"a", "", "", ""}, 26 | {"", "b", "", ""}, 27 | {" ", "", "", ""}, 28 | } 29 | 30 | for i, s := range scenarios { 31 | if want, got := s.result, BuildFQName(s.namespace, s.subsystem, s.name); want != got { 32 | t.Errorf("%d. want %s, got %s", i, want, got) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/process_collector.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | import "github.com/prometheus/procfs" 17 | 18 | type processCollector struct { 19 | pid int 20 | collectFn func(chan<- Metric) 21 | pidFn func() (int, error) 22 | cpuTotal Counter 23 | openFDs, maxFDs Gauge 24 | vsize, rss Gauge 25 | startTime Gauge 26 | } 27 | 28 | // NewProcessCollector returns a collector which exports the current state of 29 | // process metrics including cpu, memory and file descriptor usage as well as 30 | // the process start time for the given process id under the given namespace. 31 | func NewProcessCollector(pid int, namespace string) Collector { 32 | return NewProcessCollectorPIDFn( 33 | func() (int, error) { return pid, nil }, 34 | namespace, 35 | ) 36 | } 37 | 38 | // NewProcessCollectorPIDFn returns a collector which exports the current state 39 | // of process metrics including cpu, memory and file descriptor usage as well 40 | // as the process start time under the given namespace. The given pidFn is 41 | // called on each collect and is used to determine the process to export 42 | // metrics for. 43 | func NewProcessCollectorPIDFn( 44 | pidFn func() (int, error), 45 | namespace string, 46 | ) Collector { 47 | c := processCollector{ 48 | pidFn: pidFn, 49 | collectFn: func(chan<- Metric) {}, 50 | 51 | cpuTotal: NewCounter(CounterOpts{ 52 | Namespace: namespace, 53 | Name: "process_cpu_seconds_total", 54 | Help: "Total user and system CPU time spent in seconds.", 55 | }), 56 | openFDs: NewGauge(GaugeOpts{ 57 | Namespace: namespace, 58 | Name: "process_open_fds", 59 | Help: "Number of open file descriptors.", 60 | }), 61 | maxFDs: NewGauge(GaugeOpts{ 62 | Namespace: namespace, 63 | Name: "process_max_fds", 64 | Help: "Maximum number of open file descriptors.", 65 | }), 66 | vsize: NewGauge(GaugeOpts{ 67 | Namespace: namespace, 68 | Name: "process_virtual_memory_bytes", 69 | Help: "Virtual memory size in bytes.", 70 | }), 71 | rss: NewGauge(GaugeOpts{ 72 | Namespace: namespace, 73 | Name: "process_resident_memory_bytes", 74 | Help: "Resident memory size in bytes.", 75 | }), 76 | startTime: NewGauge(GaugeOpts{ 77 | Namespace: namespace, 78 | Name: "process_start_time_seconds", 79 | Help: "Start time of the process since unix epoch in seconds.", 80 | }), 81 | } 82 | 83 | // Set up process metric collection if supported by the runtime. 84 | if _, err := procfs.NewStat(); err == nil { 85 | c.collectFn = c.processCollect 86 | } 87 | 88 | return &c 89 | } 90 | 91 | // Describe returns all descriptions of the collector. 92 | func (c *processCollector) Describe(ch chan<- *Desc) { 93 | ch <- c.cpuTotal.Desc() 94 | ch <- c.openFDs.Desc() 95 | ch <- c.maxFDs.Desc() 96 | ch <- c.vsize.Desc() 97 | ch <- c.rss.Desc() 98 | ch <- c.startTime.Desc() 99 | } 100 | 101 | // Collect returns the current state of all metrics of the collector. 102 | func (c *processCollector) Collect(ch chan<- Metric) { 103 | c.collectFn(ch) 104 | } 105 | 106 | // TODO(ts): Bring back error reporting by reverting 7faf9e7 as soon as the 107 | // client allows users to configure the error behavior. 108 | func (c *processCollector) processCollect(ch chan<- Metric) { 109 | pid, err := c.pidFn() 110 | if err != nil { 111 | return 112 | } 113 | 114 | p, err := procfs.NewProc(pid) 115 | if err != nil { 116 | return 117 | } 118 | 119 | if stat, err := p.NewStat(); err == nil { 120 | c.cpuTotal.Set(stat.CPUTime()) 121 | ch <- c.cpuTotal 122 | c.vsize.Set(float64(stat.VirtualMemory())) 123 | ch <- c.vsize 124 | c.rss.Set(float64(stat.ResidentMemory())) 125 | ch <- c.rss 126 | 127 | if startTime, err := stat.StartTime(); err == nil { 128 | c.startTime.Set(startTime) 129 | ch <- c.startTime 130 | } 131 | } 132 | 133 | if fds, err := p.FileDescriptorsLen(); err == nil { 134 | c.openFDs.Set(float64(fds)) 135 | ch <- c.openFDs 136 | } 137 | 138 | if limits, err := p.NewLimits(); err == nil { 139 | c.maxFDs.Set(float64(limits.OpenFiles)) 140 | ch <- c.maxFDs 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/process_collector_test.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "regexp" 7 | "testing" 8 | 9 | "github.com/prometheus/common/expfmt" 10 | "github.com/prometheus/procfs" 11 | ) 12 | 13 | func TestProcessCollector(t *testing.T) { 14 | if _, err := procfs.Self(); err != nil { 15 | t.Skipf("skipping TestProcessCollector, procfs not available: %s", err) 16 | } 17 | 18 | registry := NewRegistry() 19 | if err := registry.Register(NewProcessCollector(os.Getpid(), "")); err != nil { 20 | t.Fatal(err) 21 | } 22 | if err := registry.Register(NewProcessCollectorPIDFn( 23 | func() (int, error) { return os.Getpid(), nil }, "foobar"), 24 | ); err != nil { 25 | t.Fatal(err) 26 | } 27 | 28 | mfs, err := registry.Gather() 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | 33 | var buf bytes.Buffer 34 | for _, mf := range mfs { 35 | if _, err := expfmt.MetricFamilyToText(&buf, mf); err != nil { 36 | t.Fatal(err) 37 | } 38 | } 39 | 40 | for _, re := range []*regexp.Regexp{ 41 | regexp.MustCompile("process_cpu_seconds_total [0-9]"), 42 | regexp.MustCompile("process_max_fds [1-9]"), 43 | regexp.MustCompile("process_open_fds [1-9]"), 44 | regexp.MustCompile("process_virtual_memory_bytes [1-9]"), 45 | regexp.MustCompile("process_resident_memory_bytes [1-9]"), 46 | regexp.MustCompile("process_start_time_seconds [0-9.]{10,}"), 47 | regexp.MustCompile("foobar_process_cpu_seconds_total [0-9]"), 48 | regexp.MustCompile("foobar_process_max_fds [1-9]"), 49 | regexp.MustCompile("foobar_process_open_fds [1-9]"), 50 | regexp.MustCompile("foobar_process_virtual_memory_bytes [1-9]"), 51 | regexp.MustCompile("foobar_process_resident_memory_bytes [1-9]"), 52 | regexp.MustCompile("foobar_process_start_time_seconds [0-9.]{10,}"), 53 | } { 54 | if !re.Match(buf.Bytes()) { 55 | t.Errorf("want body to match %s\n%s", re, buf.String()) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/promhttp/http_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Copyright (c) 2013, The Prometheus Authors 15 | // All rights reserved. 16 | // 17 | // Use of this source code is governed by a BSD-style license that can be found 18 | // in the LICENSE file. 19 | 20 | package promhttp 21 | 22 | import ( 23 | "bytes" 24 | "errors" 25 | "log" 26 | "net/http" 27 | "net/http/httptest" 28 | "testing" 29 | 30 | "github.com/prometheus/client_golang/prometheus" 31 | ) 32 | 33 | type errorCollector struct{} 34 | 35 | func (e errorCollector) Describe(ch chan<- *prometheus.Desc) { 36 | ch <- prometheus.NewDesc("invalid_metric", "not helpful", nil, nil) 37 | } 38 | 39 | func (e errorCollector) Collect(ch chan<- prometheus.Metric) { 40 | ch <- prometheus.NewInvalidMetric( 41 | prometheus.NewDesc("invalid_metric", "not helpful", nil, nil), 42 | errors.New("collect error"), 43 | ) 44 | } 45 | 46 | func TestHandlerErrorHandling(t *testing.T) { 47 | 48 | // Create a registry that collects a MetricFamily with two elements, 49 | // another with one, and reports an error. 50 | reg := prometheus.NewRegistry() 51 | 52 | cnt := prometheus.NewCounter(prometheus.CounterOpts{ 53 | Name: "the_count", 54 | Help: "Ah-ah-ah! Thunder and lightning!", 55 | }) 56 | reg.MustRegister(cnt) 57 | 58 | cntVec := prometheus.NewCounterVec( 59 | prometheus.CounterOpts{ 60 | Name: "name", 61 | Help: "docstring", 62 | ConstLabels: prometheus.Labels{"constname": "constvalue"}, 63 | }, 64 | []string{"labelname"}, 65 | ) 66 | cntVec.WithLabelValues("val1").Inc() 67 | cntVec.WithLabelValues("val2").Inc() 68 | reg.MustRegister(cntVec) 69 | 70 | reg.MustRegister(errorCollector{}) 71 | 72 | logBuf := &bytes.Buffer{} 73 | logger := log.New(logBuf, "", 0) 74 | 75 | writer := httptest.NewRecorder() 76 | request, _ := http.NewRequest("GET", "/", nil) 77 | request.Header.Add("Accept", "test/plain") 78 | 79 | errorHandler := HandlerFor(reg, HandlerOpts{ 80 | ErrorLog: logger, 81 | ErrorHandling: HTTPErrorOnError, 82 | }) 83 | continueHandler := HandlerFor(reg, HandlerOpts{ 84 | ErrorLog: logger, 85 | ErrorHandling: ContinueOnError, 86 | }) 87 | panicHandler := HandlerFor(reg, HandlerOpts{ 88 | ErrorLog: logger, 89 | ErrorHandling: PanicOnError, 90 | }) 91 | wantMsg := `error gathering metrics: error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", constLabels: {}, variableLabels: []}: collect error 92 | ` 93 | wantErrorBody := `An error has occurred during metrics gathering: 94 | 95 | error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", constLabels: {}, variableLabels: []}: collect error 96 | ` 97 | wantOKBody := `# HELP name docstring 98 | # TYPE name counter 99 | name{constname="constvalue",labelname="val1"} 1 100 | name{constname="constvalue",labelname="val2"} 1 101 | # HELP the_count Ah-ah-ah! Thunder and lightning! 102 | # TYPE the_count counter 103 | the_count 0 104 | ` 105 | 106 | errorHandler.ServeHTTP(writer, request) 107 | if got, want := writer.Code, http.StatusInternalServerError; got != want { 108 | t.Errorf("got HTTP status code %d, want %d", got, want) 109 | } 110 | if got := logBuf.String(); got != wantMsg { 111 | t.Errorf("got log message:\n%s\nwant log mesage:\n%s\n", got, wantMsg) 112 | } 113 | if got := writer.Body.String(); got != wantErrorBody { 114 | t.Errorf("got body:\n%s\nwant body:\n%s\n", got, wantErrorBody) 115 | } 116 | logBuf.Reset() 117 | writer.Body.Reset() 118 | writer.Code = http.StatusOK 119 | 120 | continueHandler.ServeHTTP(writer, request) 121 | if got, want := writer.Code, http.StatusOK; got != want { 122 | t.Errorf("got HTTP status code %d, want %d", got, want) 123 | } 124 | if got := logBuf.String(); got != wantMsg { 125 | t.Errorf("got log message %q, want %q", got, wantMsg) 126 | } 127 | if got := writer.Body.String(); got != wantOKBody { 128 | t.Errorf("got body %q, want %q", got, wantOKBody) 129 | } 130 | 131 | defer func() { 132 | if err := recover(); err == nil { 133 | t.Error("expected panic from panicHandler") 134 | } 135 | }() 136 | panicHandler.ServeHTTP(writer, request) 137 | } 138 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull request, 6 | addressing (with `@...`) the maintainer of this repository (see 7 | [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | * Björn Rabenstein 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2013 Prometheus Team 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | KEY_ID ?= _DEFINE_ME_ 15 | 16 | all: cpp go java python ruby 17 | 18 | SUFFIXES: 19 | 20 | cpp: cpp/metrics.pb.cc cpp/metrics.pb.h 21 | 22 | cpp/metrics.pb.cc: metrics.proto 23 | protoc $< --cpp_out=cpp/ 24 | 25 | cpp/metrics.pb.h: metrics.proto 26 | protoc $< --cpp_out=cpp/ 27 | 28 | go: go/metrics.pb.go 29 | 30 | go/metrics.pb.go: metrics.proto 31 | protoc $< --go_out=go/ 32 | 33 | java: src/main/java/io/prometheus/client/Metrics.java pom.xml 34 | mvn clean compile package 35 | 36 | src/main/java/io/prometheus/client/Metrics.java: metrics.proto 37 | protoc $< --java_out=src/main/java 38 | 39 | python: python/prometheus/client/model/metrics_pb2.py 40 | 41 | python/prometheus/client/model/metrics_pb2.py: metrics.proto 42 | mkdir -p python/prometheus/client/model 43 | protoc $< --python_out=python/prometheus/client/model 44 | 45 | ruby: 46 | $(MAKE) -C ruby build 47 | 48 | clean: 49 | -rm -rf cpp/* 50 | -rm -rf go/* 51 | -rm -rf java/* 52 | -rm -rf python/* 53 | -$(MAKE) -C ruby clean 54 | -mvn clean 55 | 56 | maven-deploy-snapshot: java 57 | mvn clean deploy -Dgpg.keyname=$(KEY_ID) -DperformRelease=true 58 | 59 | maven-deploy-release: java 60 | mvn clean release:clean release:prepare release:perform -Dgpg.keyname=$(KEY_ID) -DperformRelease=true 61 | 62 | .PHONY: all clean cpp go java maven-deploy-snapshot maven-deploy-release python ruby 63 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/NOTICE: -------------------------------------------------------------------------------- 1 | Data model artifacts for Prometheus. 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/README.md: -------------------------------------------------------------------------------- 1 | # Background 2 | Under most circumstances, manually downloading this repository should never 3 | be required. 4 | 5 | # Prerequisites 6 | # Base 7 | * [Google Protocol Buffers](https://developers.google.com/protocol-buffers) 8 | 9 | ## Java 10 | * [Apache Maven](http://maven.apache.org) 11 | * [Prometheus Maven Repository](https://github.com/prometheus/io.prometheus-maven-repository) checked out into ../io.prometheus-maven-repository 12 | 13 | ## Go 14 | * [Go](http://golang.org) 15 | * [goprotobuf](https://code.google.com/p/goprotobuf) 16 | 17 | ## Ruby 18 | * [Ruby](https://www.ruby-lang.org) 19 | * [bundler](https://rubygems.org/gems/bundler) 20 | 21 | # Building 22 | $ make 23 | 24 | # Getting Started 25 | * The Go source code is periodically indexed: [Go Protocol Buffer Model](http://godoc.org/github.com/prometheus/client_model/go). 26 | * All of the core developers are accessible via the [Prometheus Developers Mailinglist](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 27 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/metrics.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Prometheus Team 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | syntax = "proto2"; 15 | 16 | package io.prometheus.client; 17 | option java_package = "io.prometheus.client"; 18 | 19 | message LabelPair { 20 | optional string name = 1; 21 | optional string value = 2; 22 | } 23 | 24 | enum MetricType { 25 | COUNTER = 0; 26 | GAUGE = 1; 27 | SUMMARY = 2; 28 | UNTYPED = 3; 29 | HISTOGRAM = 4; 30 | } 31 | 32 | message Gauge { 33 | optional double value = 1; 34 | } 35 | 36 | message Counter { 37 | optional double value = 1; 38 | } 39 | 40 | message Quantile { 41 | optional double quantile = 1; 42 | optional double value = 2; 43 | } 44 | 45 | message Summary { 46 | optional uint64 sample_count = 1; 47 | optional double sample_sum = 2; 48 | repeated Quantile quantile = 3; 49 | } 50 | 51 | message Untyped { 52 | optional double value = 1; 53 | } 54 | 55 | message Histogram { 56 | optional uint64 sample_count = 1; 57 | optional double sample_sum = 2; 58 | repeated Bucket bucket = 3; // Ordered in increasing order of upper_bound, +Inf bucket is optional. 59 | } 60 | 61 | message Bucket { 62 | optional uint64 cumulative_count = 1; // Cumulative in increasing order. 63 | optional double upper_bound = 2; // Inclusive. 64 | } 65 | 66 | message Metric { 67 | repeated LabelPair label = 1; 68 | optional Gauge gauge = 2; 69 | optional Counter counter = 3; 70 | optional Summary summary = 4; 71 | optional Untyped untyped = 5; 72 | optional Histogram histogram = 7; 73 | optional int64 timestamp_ms = 6; 74 | } 75 | 76 | message MetricFamily { 77 | optional string name = 1; 78 | optional string help = 2; 79 | optional MetricType type = 3; 80 | repeated Metric metric = 4; 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from setuptools import setup 4 | 5 | setup( 6 | name = 'prometheus_client_model', 7 | version = '0.0.1', 8 | author = 'Matt T. Proud', 9 | author_email = 'matt.proud@gmail.com', 10 | description = 'Data model artifacts for the Prometheus client.', 11 | license = 'Apache License 2.0', 12 | url = 'http://github.com/prometheus/client_model', 13 | packages = ['prometheus', 'prometheus/client', 'prometheus/client/model'], 14 | package_dir = {'': 'python'}, 15 | requires = ['protobuf(==2.4.1)'], 16 | platforms = 'Platform Independent', 17 | classifiers = ['Development Status :: 3 - Alpha', 18 | 'Intended Audience :: Developers', 19 | 'Intended Audience :: System Administrators', 20 | 'License :: OSI Approved :: Apache Software License', 21 | 'Operating System :: OS Independent', 22 | 'Topic :: Software Development :: Testing', 23 | 'Topic :: System :: Monitoring']) 24 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | go: 5 | - 1.7.5 6 | - tip 7 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull request, 6 | addressing (with `@...`) the maintainer of this repository (see 7 | [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | * Fabian Reinartz 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/NOTICE: -------------------------------------------------------------------------------- 1 | Common libraries shared by Prometheus Go components. 2 | Copyright 2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/README.md: -------------------------------------------------------------------------------- 1 | # Common 2 | [![Build Status](https://travis-ci.org/prometheus/common.svg)](https://travis-ci.org/prometheus/common) 3 | 4 | This repository contains Go libraries that are shared across Prometheus 5 | components and libraries. 6 | 7 | * **config**: Common configuration structures 8 | * **expfmt**: Decoding and encoding for the exposition format 9 | * **log**: A logging wrapper around [logrus](https://github.com/sirupsen/logrus) 10 | * **model**: Shared data structures 11 | * **route**: A routing wrapper around [httprouter](https://github.com/julienschmidt/httprouter) using `context.Context` 12 | * **version**: Version informations and metric 13 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package expfmt 15 | 16 | import ( 17 | "fmt" 18 | "io" 19 | "net/http" 20 | 21 | "github.com/golang/protobuf/proto" 22 | "github.com/matttproud/golang_protobuf_extensions/pbutil" 23 | "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg" 24 | 25 | dto "github.com/prometheus/client_model/go" 26 | ) 27 | 28 | // Encoder types encode metric families into an underlying wire protocol. 29 | type Encoder interface { 30 | Encode(*dto.MetricFamily) error 31 | } 32 | 33 | type encoder func(*dto.MetricFamily) error 34 | 35 | func (e encoder) Encode(v *dto.MetricFamily) error { 36 | return e(v) 37 | } 38 | 39 | // Negotiate returns the Content-Type based on the given Accept header. 40 | // If no appropriate accepted type is found, FmtText is returned. 41 | func Negotiate(h http.Header) Format { 42 | for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) { 43 | // Check for protocol buffer 44 | if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol { 45 | switch ac.Params["encoding"] { 46 | case "delimited": 47 | return FmtProtoDelim 48 | case "text": 49 | return FmtProtoText 50 | case "compact-text": 51 | return FmtProtoCompact 52 | } 53 | } 54 | // Check for text format. 55 | ver := ac.Params["version"] 56 | if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") { 57 | return FmtText 58 | } 59 | } 60 | return FmtText 61 | } 62 | 63 | // NewEncoder returns a new encoder based on content type negotiation. 64 | func NewEncoder(w io.Writer, format Format) Encoder { 65 | switch format { 66 | case FmtProtoDelim: 67 | return encoder(func(v *dto.MetricFamily) error { 68 | _, err := pbutil.WriteDelimited(w, v) 69 | return err 70 | }) 71 | case FmtProtoCompact: 72 | return encoder(func(v *dto.MetricFamily) error { 73 | _, err := fmt.Fprintln(w, v.String()) 74 | return err 75 | }) 76 | case FmtProtoText: 77 | return encoder(func(v *dto.MetricFamily) error { 78 | _, err := fmt.Fprintln(w, proto.MarshalTextString(v)) 79 | return err 80 | }) 81 | case FmtText: 82 | return encoder(func(v *dto.MetricFamily) error { 83 | _, err := MetricFamilyToText(w, v) 84 | return err 85 | }) 86 | } 87 | panic("expfmt.NewEncoder: unknown format") 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/expfmt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package expfmt contains tools for reading and writing Prometheus metrics. 15 | package expfmt 16 | 17 | // Format specifies the HTTP content type of the different wire protocols. 18 | type Format string 19 | 20 | // Constants to assemble the Content-Type values for the different wire protocols. 21 | const ( 22 | TextVersion = "0.0.4" 23 | ProtoType = `application/vnd.google.protobuf` 24 | ProtoProtocol = `io.prometheus.client.MetricFamily` 25 | ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" 26 | 27 | // The Content-Type values for the different wire protocols. 28 | FmtUnknown Format = `` 29 | FmtText Format = `text/plain; version=` + TextVersion 30 | FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` 31 | FmtProtoText Format = ProtoFmt + ` encoding=text` 32 | FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` 33 | ) 34 | 35 | const ( 36 | hdrContentType = "Content-Type" 37 | hdrAccept = "Accept" 38 | ) 39 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/fuzz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Build only when actually fuzzing 15 | // +build gofuzz 16 | 17 | package expfmt 18 | 19 | import "bytes" 20 | 21 | // Fuzz text metric parser with with github.com/dvyukov/go-fuzz: 22 | // 23 | // go-fuzz-build github.com/prometheus/common/expfmt 24 | // go-fuzz -bin expfmt-fuzz.zip -workdir fuzz 25 | // 26 | // Further input samples should go in the folder fuzz/corpus. 27 | func Fuzz(in []byte) int { 28 | parser := TextParser{} 29 | _, err := parser.TextToMetricFamilies(bytes.NewReader(in)) 30 | 31 | if err != nil { 32 | return 0 33 | } 34 | 35 | return 1 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/README.txt: -------------------------------------------------------------------------------- 1 | PACKAGE 2 | 3 | package goautoneg 4 | import "bitbucket.org/ww/goautoneg" 5 | 6 | HTTP Content-Type Autonegotiation. 7 | 8 | The functions in this package implement the behaviour specified in 9 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 10 | 11 | Copyright (c) 2011, Open Knowledge Foundation Ltd. 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in 23 | the documentation and/or other materials provided with the 24 | distribution. 25 | 26 | Neither the name of the Open Knowledge Foundation Ltd. nor the 27 | names of its contributors may be used to endorse or promote 28 | products derived from this software without specific prior written 29 | permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | 43 | 44 | FUNCTIONS 45 | 46 | func Negotiate(header string, alternatives []string) (content_type string) 47 | Negotiate the most appropriate content_type given the accept header 48 | and a list of alternatives. 49 | 50 | func ParseAccept(header string) (accept []Accept) 51 | Parse an Accept Header string returning a sorted list 52 | of clauses 53 | 54 | 55 | TYPES 56 | 57 | type Accept struct { 58 | Type, SubType string 59 | Q float32 60 | Params map[string]string 61 | } 62 | Structure to represent a clause in an HTTP Accept Header 63 | 64 | 65 | SUBDIRECTORIES 66 | 67 | .hg 68 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg_test.go: -------------------------------------------------------------------------------- 1 | package goautoneg 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var chrome = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" 8 | 9 | func TestParseAccept(t *testing.T) { 10 | alternatives := []string{"text/html", "image/png"} 11 | content_type := Negotiate(chrome, alternatives) 12 | if content_type != "image/png" { 13 | t.Errorf("got %s expected image/png", content_type) 14 | } 15 | 16 | alternatives = []string{"text/html", "text/plain", "text/n3"} 17 | content_type = Negotiate(chrome, alternatives) 18 | if content_type != "text/html" { 19 | t.Errorf("got %s expected text/html", content_type) 20 | } 21 | 22 | alternatives = []string{"text/n3", "text/plain"} 23 | content_type = Negotiate(chrome, alternatives) 24 | if content_type != "text/plain" { 25 | t.Errorf("got %s expected text/plain", content_type) 26 | } 27 | 28 | alternatives = []string{"text/n3", "application/rdf+xml"} 29 | content_type = Negotiate(chrome, alternatives) 30 | if content_type != "text/n3" { 31 | t.Errorf("got %s expected text/n3", content_type) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/alert.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "time" 19 | ) 20 | 21 | type AlertStatus string 22 | 23 | const ( 24 | AlertFiring AlertStatus = "firing" 25 | AlertResolved AlertStatus = "resolved" 26 | ) 27 | 28 | // Alert is a generic representation of an alert in the Prometheus eco-system. 29 | type Alert struct { 30 | // Label value pairs for purpose of aggregation, matching, and disposition 31 | // dispatching. This must minimally include an "alertname" label. 32 | Labels LabelSet `json:"labels"` 33 | 34 | // Extra key/value information which does not define alert identity. 35 | Annotations LabelSet `json:"annotations"` 36 | 37 | // The known time range for this alert. Both ends are optional. 38 | StartsAt time.Time `json:"startsAt,omitempty"` 39 | EndsAt time.Time `json:"endsAt,omitempty"` 40 | GeneratorURL string `json:"generatorURL"` 41 | } 42 | 43 | // Name returns the name of the alert. It is equivalent to the "alertname" label. 44 | func (a *Alert) Name() string { 45 | return string(a.Labels[AlertNameLabel]) 46 | } 47 | 48 | // Fingerprint returns a unique hash for the alert. It is equivalent to 49 | // the fingerprint of the alert's label set. 50 | func (a *Alert) Fingerprint() Fingerprint { 51 | return a.Labels.Fingerprint() 52 | } 53 | 54 | func (a *Alert) String() string { 55 | s := fmt.Sprintf("%s[%s]", a.Name(), a.Fingerprint().String()[:7]) 56 | if a.Resolved() { 57 | return s + "[resolved]" 58 | } 59 | return s + "[active]" 60 | } 61 | 62 | // Resolved returns true iff the activity interval ended in the past. 63 | func (a *Alert) Resolved() bool { 64 | return a.ResolvedAt(time.Now()) 65 | } 66 | 67 | // ResolvedAt returns true off the activity interval ended before 68 | // the given timestamp. 69 | func (a *Alert) ResolvedAt(ts time.Time) bool { 70 | if a.EndsAt.IsZero() { 71 | return false 72 | } 73 | return !a.EndsAt.After(ts) 74 | } 75 | 76 | // Status returns the status of the alert. 77 | func (a *Alert) Status() AlertStatus { 78 | if a.Resolved() { 79 | return AlertResolved 80 | } 81 | return AlertFiring 82 | } 83 | 84 | // Validate checks whether the alert data is inconsistent. 85 | func (a *Alert) Validate() error { 86 | if a.StartsAt.IsZero() { 87 | return fmt.Errorf("start time missing") 88 | } 89 | if !a.EndsAt.IsZero() && a.EndsAt.Before(a.StartsAt) { 90 | return fmt.Errorf("start time must be before end time") 91 | } 92 | if err := a.Labels.Validate(); err != nil { 93 | return fmt.Errorf("invalid label set: %s", err) 94 | } 95 | if len(a.Labels) == 0 { 96 | return fmt.Errorf("at least one label pair required") 97 | } 98 | if err := a.Annotations.Validate(); err != nil { 99 | return fmt.Errorf("invalid annotations: %s", err) 100 | } 101 | return nil 102 | } 103 | 104 | // Alert is a list of alerts that can be sorted in chronological order. 105 | type Alerts []*Alert 106 | 107 | func (as Alerts) Len() int { return len(as) } 108 | func (as Alerts) Swap(i, j int) { as[i], as[j] = as[j], as[i] } 109 | 110 | func (as Alerts) Less(i, j int) bool { 111 | if as[i].StartsAt.Before(as[j].StartsAt) { 112 | return true 113 | } 114 | if as[i].EndsAt.Before(as[j].EndsAt) { 115 | return true 116 | } 117 | return as[i].Fingerprint() < as[j].Fingerprint() 118 | } 119 | 120 | // HasFiring returns true iff one of the alerts is not resolved. 121 | func (as Alerts) HasFiring() bool { 122 | for _, a := range as { 123 | if !a.Resolved() { 124 | return true 125 | } 126 | } 127 | return false 128 | } 129 | 130 | // Status returns StatusFiring iff at least one of the alerts is firing. 131 | func (as Alerts) Status() AlertStatus { 132 | if as.HasFiring() { 133 | return AlertFiring 134 | } 135 | return AlertResolved 136 | } 137 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/alert_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "strings" 18 | "testing" 19 | "time" 20 | ) 21 | 22 | func TestAlertValidate(t *testing.T) { 23 | ts := time.Now() 24 | 25 | var cases = []struct { 26 | alert *Alert 27 | err string 28 | }{ 29 | { 30 | alert: &Alert{ 31 | Labels: LabelSet{"a": "b"}, 32 | StartsAt: ts, 33 | }, 34 | }, 35 | { 36 | alert: &Alert{ 37 | Labels: LabelSet{"a": "b"}, 38 | }, 39 | err: "start time missing", 40 | }, 41 | { 42 | alert: &Alert{ 43 | Labels: LabelSet{"a": "b"}, 44 | StartsAt: ts, 45 | EndsAt: ts, 46 | }, 47 | }, 48 | { 49 | alert: &Alert{ 50 | Labels: LabelSet{"a": "b"}, 51 | StartsAt: ts, 52 | EndsAt: ts.Add(1 * time.Minute), 53 | }, 54 | }, 55 | { 56 | alert: &Alert{ 57 | Labels: LabelSet{"a": "b"}, 58 | StartsAt: ts, 59 | EndsAt: ts.Add(-1 * time.Minute), 60 | }, 61 | err: "start time must be before end time", 62 | }, 63 | { 64 | alert: &Alert{ 65 | StartsAt: ts, 66 | }, 67 | err: "at least one label pair required", 68 | }, 69 | { 70 | alert: &Alert{ 71 | Labels: LabelSet{"a": "b", "!bad": "label"}, 72 | StartsAt: ts, 73 | }, 74 | err: "invalid label set: invalid name", 75 | }, 76 | { 77 | alert: &Alert{ 78 | Labels: LabelSet{"a": "b", "bad": "\xfflabel"}, 79 | StartsAt: ts, 80 | }, 81 | err: "invalid label set: invalid value", 82 | }, 83 | { 84 | alert: &Alert{ 85 | Labels: LabelSet{"a": "b"}, 86 | Annotations: LabelSet{"!bad": "label"}, 87 | StartsAt: ts, 88 | }, 89 | err: "invalid annotations: invalid name", 90 | }, 91 | { 92 | alert: &Alert{ 93 | Labels: LabelSet{"a": "b"}, 94 | Annotations: LabelSet{"bad": "\xfflabel"}, 95 | StartsAt: ts, 96 | }, 97 | err: "invalid annotations: invalid value", 98 | }, 99 | } 100 | 101 | for i, c := range cases { 102 | err := c.alert.Validate() 103 | if err == nil { 104 | if c.err == "" { 105 | continue 106 | } 107 | t.Errorf("%d. Expected error %q but got none", i, c.err) 108 | continue 109 | } 110 | if c.err == "" && err != nil { 111 | t.Errorf("%d. Expected no error but got %q", i, err) 112 | continue 113 | } 114 | if !strings.Contains(err.Error(), c.err) { 115 | t.Errorf("%d. Expected error to contain %q but got %q", i, c.err, err) 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fingerprinting.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "strconv" 19 | ) 20 | 21 | // Fingerprint provides a hash-capable representation of a Metric. 22 | // For our purposes, FNV-1A 64-bit is used. 23 | type Fingerprint uint64 24 | 25 | // FingerprintFromString transforms a string representation into a Fingerprint. 26 | func FingerprintFromString(s string) (Fingerprint, error) { 27 | num, err := strconv.ParseUint(s, 16, 64) 28 | return Fingerprint(num), err 29 | } 30 | 31 | // ParseFingerprint parses the input string into a fingerprint. 32 | func ParseFingerprint(s string) (Fingerprint, error) { 33 | num, err := strconv.ParseUint(s, 16, 64) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return Fingerprint(num), nil 38 | } 39 | 40 | func (f Fingerprint) String() string { 41 | return fmt.Sprintf("%016x", uint64(f)) 42 | } 43 | 44 | // Fingerprints represents a collection of Fingerprint subject to a given 45 | // natural sorting scheme. It implements sort.Interface. 46 | type Fingerprints []Fingerprint 47 | 48 | // Len implements sort.Interface. 49 | func (f Fingerprints) Len() int { 50 | return len(f) 51 | } 52 | 53 | // Less implements sort.Interface. 54 | func (f Fingerprints) Less(i, j int) bool { 55 | return f[i] < f[j] 56 | } 57 | 58 | // Swap implements sort.Interface. 59 | func (f Fingerprints) Swap(i, j int) { 60 | f[i], f[j] = f[j], f[i] 61 | } 62 | 63 | // FingerprintSet is a set of Fingerprints. 64 | type FingerprintSet map[Fingerprint]struct{} 65 | 66 | // Equal returns true if both sets contain the same elements (and not more). 67 | func (s FingerprintSet) Equal(o FingerprintSet) bool { 68 | if len(s) != len(o) { 69 | return false 70 | } 71 | 72 | for k := range s { 73 | if _, ok := o[k]; !ok { 74 | return false 75 | } 76 | } 77 | 78 | return true 79 | } 80 | 81 | // Intersection returns the elements contained in both sets. 82 | func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet { 83 | myLength, otherLength := len(s), len(o) 84 | if myLength == 0 || otherLength == 0 { 85 | return FingerprintSet{} 86 | } 87 | 88 | subSet := s 89 | superSet := o 90 | 91 | if otherLength < myLength { 92 | subSet = o 93 | superSet = s 94 | } 95 | 96 | out := FingerprintSet{} 97 | 98 | for k := range subSet { 99 | if _, ok := superSet[k]; ok { 100 | out[k] = struct{}{} 101 | } 102 | } 103 | 104 | return out 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fnv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | // Inline and byte-free variant of hash/fnv's fnv64a. 17 | 18 | const ( 19 | offset64 = 14695981039346656037 20 | prime64 = 1099511628211 21 | ) 22 | 23 | // hashNew initializies a new fnv64a hash value. 24 | func hashNew() uint64 { 25 | return offset64 26 | } 27 | 28 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 29 | func hashAdd(h uint64, s string) uint64 { 30 | for i := 0; i < len(s); i++ { 31 | h ^= uint64(s[i]) 32 | h *= prime64 33 | } 34 | return h 35 | } 36 | 37 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 38 | func hashAddByte(h uint64, b byte) uint64 { 39 | h ^= uint64(b) 40 | h *= prime64 41 | return h 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/labels_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "sort" 18 | "testing" 19 | ) 20 | 21 | func testLabelNames(t testing.TB) { 22 | var scenarios = []struct { 23 | in LabelNames 24 | out LabelNames 25 | }{ 26 | { 27 | in: LabelNames{"ZZZ", "zzz"}, 28 | out: LabelNames{"ZZZ", "zzz"}, 29 | }, 30 | { 31 | in: LabelNames{"aaa", "AAA"}, 32 | out: LabelNames{"AAA", "aaa"}, 33 | }, 34 | } 35 | 36 | for i, scenario := range scenarios { 37 | sort.Sort(scenario.in) 38 | 39 | for j, expected := range scenario.out { 40 | if expected != scenario.in[j] { 41 | t.Errorf("%d.%d expected %s, got %s", i, j, expected, scenario.in[j]) 42 | } 43 | } 44 | } 45 | } 46 | 47 | func TestLabelNames(t *testing.T) { 48 | testLabelNames(t) 49 | } 50 | 51 | func BenchmarkLabelNames(b *testing.B) { 52 | for i := 0; i < b.N; i++ { 53 | testLabelNames(b) 54 | } 55 | } 56 | 57 | func testLabelValues(t testing.TB) { 58 | var scenarios = []struct { 59 | in LabelValues 60 | out LabelValues 61 | }{ 62 | { 63 | in: LabelValues{"ZZZ", "zzz"}, 64 | out: LabelValues{"ZZZ", "zzz"}, 65 | }, 66 | { 67 | in: LabelValues{"aaa", "AAA"}, 68 | out: LabelValues{"AAA", "aaa"}, 69 | }, 70 | } 71 | 72 | for i, scenario := range scenarios { 73 | sort.Sort(scenario.in) 74 | 75 | for j, expected := range scenario.out { 76 | if expected != scenario.in[j] { 77 | t.Errorf("%d.%d expected %s, got %s", i, j, expected, scenario.in[j]) 78 | } 79 | } 80 | } 81 | } 82 | 83 | func TestLabelValues(t *testing.T) { 84 | testLabelValues(t) 85 | } 86 | 87 | func BenchmarkLabelValues(b *testing.B) { 88 | for i := 0; i < b.N; i++ { 89 | testLabelValues(b) 90 | } 91 | } 92 | 93 | func TestLabelNameIsValid(t *testing.T) { 94 | var scenarios = []struct { 95 | ln LabelName 96 | valid bool 97 | }{ 98 | { 99 | ln: "Avalid_23name", 100 | valid: true, 101 | }, 102 | { 103 | ln: "_Avalid_23name", 104 | valid: true, 105 | }, 106 | { 107 | ln: "1valid_23name", 108 | valid: false, 109 | }, 110 | { 111 | ln: "avalid_23name", 112 | valid: true, 113 | }, 114 | { 115 | ln: "Ava:lid_23name", 116 | valid: false, 117 | }, 118 | { 119 | ln: "a lid_23name", 120 | valid: false, 121 | }, 122 | { 123 | ln: ":leading_colon", 124 | valid: false, 125 | }, 126 | { 127 | ln: "colon:in:the:middle", 128 | valid: false, 129 | }, 130 | } 131 | 132 | for _, s := range scenarios { 133 | if s.ln.IsValid() != s.valid { 134 | t.Errorf("Expected %v for %q using IsValid method", s.valid, s.ln) 135 | } 136 | if LabelNameRE.MatchString(string(s.ln)) != s.valid { 137 | t.Errorf("Expected %v for %q using regexp match", s.valid, s.ln) 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/metric.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "regexp" 19 | "sort" 20 | "strings" 21 | ) 22 | 23 | var ( 24 | separator = []byte{0} 25 | // MetricNameRE is a regular expression matching valid metric 26 | // names. Note that the IsValidMetricName function performs the same 27 | // check but faster than a match with this regular expression. 28 | MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`) 29 | ) 30 | 31 | // A Metric is similar to a LabelSet, but the key difference is that a Metric is 32 | // a singleton and refers to one and only one stream of samples. 33 | type Metric LabelSet 34 | 35 | // Equal compares the metrics. 36 | func (m Metric) Equal(o Metric) bool { 37 | return LabelSet(m).Equal(LabelSet(o)) 38 | } 39 | 40 | // Before compares the metrics' underlying label sets. 41 | func (m Metric) Before(o Metric) bool { 42 | return LabelSet(m).Before(LabelSet(o)) 43 | } 44 | 45 | // Clone returns a copy of the Metric. 46 | func (m Metric) Clone() Metric { 47 | clone := make(Metric, len(m)) 48 | for k, v := range m { 49 | clone[k] = v 50 | } 51 | return clone 52 | } 53 | 54 | func (m Metric) String() string { 55 | metricName, hasName := m[MetricNameLabel] 56 | numLabels := len(m) - 1 57 | if !hasName { 58 | numLabels = len(m) 59 | } 60 | labelStrings := make([]string, 0, numLabels) 61 | for label, value := range m { 62 | if label != MetricNameLabel { 63 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 64 | } 65 | } 66 | 67 | switch numLabels { 68 | case 0: 69 | if hasName { 70 | return string(metricName) 71 | } 72 | return "{}" 73 | default: 74 | sort.Strings(labelStrings) 75 | return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", ")) 76 | } 77 | } 78 | 79 | // Fingerprint returns a Metric's Fingerprint. 80 | func (m Metric) Fingerprint() Fingerprint { 81 | return LabelSet(m).Fingerprint() 82 | } 83 | 84 | // FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing 85 | // algorithm, which is, however, more susceptible to hash collisions. 86 | func (m Metric) FastFingerprint() Fingerprint { 87 | return LabelSet(m).FastFingerprint() 88 | } 89 | 90 | // IsValidMetricName returns true iff name matches the pattern of MetricNameRE. 91 | // This function, however, does not use MetricNameRE for the check but a much 92 | // faster hardcoded implementation. 93 | func IsValidMetricName(n LabelValue) bool { 94 | if len(n) == 0 { 95 | return false 96 | } 97 | for i, b := range n { 98 | if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) { 99 | return false 100 | } 101 | } 102 | return true 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/metric_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import "testing" 17 | 18 | func testMetric(t testing.TB) { 19 | var scenarios = []struct { 20 | input LabelSet 21 | fingerprint Fingerprint 22 | fastFingerprint Fingerprint 23 | }{ 24 | { 25 | input: LabelSet{}, 26 | fingerprint: 14695981039346656037, 27 | fastFingerprint: 14695981039346656037, 28 | }, 29 | { 30 | input: LabelSet{ 31 | "first_name": "electro", 32 | "occupation": "robot", 33 | "manufacturer": "westinghouse", 34 | }, 35 | fingerprint: 5911716720268894962, 36 | fastFingerprint: 11310079640881077873, 37 | }, 38 | { 39 | input: LabelSet{ 40 | "x": "y", 41 | }, 42 | fingerprint: 8241431561484471700, 43 | fastFingerprint: 13948396922932177635, 44 | }, 45 | { 46 | input: LabelSet{ 47 | "a": "bb", 48 | "b": "c", 49 | }, 50 | fingerprint: 3016285359649981711, 51 | fastFingerprint: 3198632812309449502, 52 | }, 53 | { 54 | input: LabelSet{ 55 | "a": "b", 56 | "bb": "c", 57 | }, 58 | fingerprint: 7122421792099404749, 59 | fastFingerprint: 5774953389407657638, 60 | }, 61 | } 62 | 63 | for i, scenario := range scenarios { 64 | input := Metric(scenario.input) 65 | 66 | if scenario.fingerprint != input.Fingerprint() { 67 | t.Errorf("%d. expected %d, got %d", i, scenario.fingerprint, input.Fingerprint()) 68 | } 69 | if scenario.fastFingerprint != input.FastFingerprint() { 70 | t.Errorf("%d. expected %d, got %d", i, scenario.fastFingerprint, input.FastFingerprint()) 71 | } 72 | } 73 | } 74 | 75 | func TestMetric(t *testing.T) { 76 | testMetric(t) 77 | } 78 | 79 | func BenchmarkMetric(b *testing.B) { 80 | for i := 0; i < b.N; i++ { 81 | testMetric(b) 82 | } 83 | } 84 | 85 | func TestMetricNameIsValid(t *testing.T) { 86 | var scenarios = []struct { 87 | mn LabelValue 88 | valid bool 89 | }{ 90 | { 91 | mn: "Avalid_23name", 92 | valid: true, 93 | }, 94 | { 95 | mn: "_Avalid_23name", 96 | valid: true, 97 | }, 98 | { 99 | mn: "1valid_23name", 100 | valid: false, 101 | }, 102 | { 103 | mn: "avalid_23name", 104 | valid: true, 105 | }, 106 | { 107 | mn: "Ava:lid_23name", 108 | valid: true, 109 | }, 110 | { 111 | mn: "a lid_23name", 112 | valid: false, 113 | }, 114 | { 115 | mn: ":leading_colon", 116 | valid: true, 117 | }, 118 | { 119 | mn: "colon:in:the:middle", 120 | valid: true, 121 | }, 122 | } 123 | 124 | for _, s := range scenarios { 125 | if IsValidMetricName(s.mn) != s.valid { 126 | t.Errorf("Expected %v for %q using IsValidMetricName function", s.valid, s.mn) 127 | } 128 | if MetricNameRE.MatchString(string(s.mn)) != s.valid { 129 | t.Errorf("Expected %v for %q using regexp matching", s.valid, s.mn) 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/model.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package model contains common data structures that are shared across 15 | // Prometheus components and libraries. 16 | package model 17 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/silence.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "encoding/json" 18 | "fmt" 19 | "regexp" 20 | "time" 21 | ) 22 | 23 | // Matcher describes a matches the value of a given label. 24 | type Matcher struct { 25 | Name LabelName `json:"name"` 26 | Value string `json:"value"` 27 | IsRegex bool `json:"isRegex"` 28 | } 29 | 30 | func (m *Matcher) UnmarshalJSON(b []byte) error { 31 | type plain Matcher 32 | if err := json.Unmarshal(b, (*plain)(m)); err != nil { 33 | return err 34 | } 35 | 36 | if len(m.Name) == 0 { 37 | return fmt.Errorf("label name in matcher must not be empty") 38 | } 39 | if m.IsRegex { 40 | if _, err := regexp.Compile(m.Value); err != nil { 41 | return err 42 | } 43 | } 44 | return nil 45 | } 46 | 47 | // Validate returns true iff all fields of the matcher have valid values. 48 | func (m *Matcher) Validate() error { 49 | if !m.Name.IsValid() { 50 | return fmt.Errorf("invalid name %q", m.Name) 51 | } 52 | if m.IsRegex { 53 | if _, err := regexp.Compile(m.Value); err != nil { 54 | return fmt.Errorf("invalid regular expression %q", m.Value) 55 | } 56 | } else if !LabelValue(m.Value).IsValid() || len(m.Value) == 0 { 57 | return fmt.Errorf("invalid value %q", m.Value) 58 | } 59 | return nil 60 | } 61 | 62 | // Silence defines the representation of a silence definiton 63 | // in the Prometheus eco-system. 64 | type Silence struct { 65 | ID uint64 `json:"id,omitempty"` 66 | 67 | Matchers []*Matcher `json:"matchers"` 68 | 69 | StartsAt time.Time `json:"startsAt"` 70 | EndsAt time.Time `json:"endsAt"` 71 | 72 | CreatedAt time.Time `json:"createdAt,omitempty"` 73 | CreatedBy string `json:"createdBy"` 74 | Comment string `json:"comment,omitempty"` 75 | } 76 | 77 | // Validate returns true iff all fields of the silence have valid values. 78 | func (s *Silence) Validate() error { 79 | if len(s.Matchers) == 0 { 80 | return fmt.Errorf("at least one matcher required") 81 | } 82 | for _, m := range s.Matchers { 83 | if err := m.Validate(); err != nil { 84 | return fmt.Errorf("invalid matcher: %s", err) 85 | } 86 | } 87 | if s.StartsAt.IsZero() { 88 | return fmt.Errorf("start time missing") 89 | } 90 | if s.EndsAt.IsZero() { 91 | return fmt.Errorf("end time missing") 92 | } 93 | if s.EndsAt.Before(s.StartsAt) { 94 | return fmt.Errorf("start time must be before end time") 95 | } 96 | if s.CreatedBy == "" { 97 | return fmt.Errorf("creator information missing") 98 | } 99 | if s.Comment == "" { 100 | return fmt.Errorf("comment missing") 101 | } 102 | if s.CreatedAt.IsZero() { 103 | return fmt.Errorf("creation timestamp missing") 104 | } 105 | return nil 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/time_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "testing" 18 | "time" 19 | ) 20 | 21 | func TestComparators(t *testing.T) { 22 | t1a := TimeFromUnix(0) 23 | t1b := TimeFromUnix(0) 24 | t2 := TimeFromUnix(2*second - 1) 25 | 26 | if !t1a.Equal(t1b) { 27 | t.Fatalf("Expected %s to be equal to %s", t1a, t1b) 28 | } 29 | if t1a.Equal(t2) { 30 | t.Fatalf("Expected %s to not be equal to %s", t1a, t2) 31 | } 32 | 33 | if !t1a.Before(t2) { 34 | t.Fatalf("Expected %s to be before %s", t1a, t2) 35 | } 36 | if t1a.Before(t1b) { 37 | t.Fatalf("Expected %s to not be before %s", t1a, t1b) 38 | } 39 | 40 | if !t2.After(t1a) { 41 | t.Fatalf("Expected %s to be after %s", t2, t1a) 42 | } 43 | if t1b.After(t1a) { 44 | t.Fatalf("Expected %s to not be after %s", t1b, t1a) 45 | } 46 | } 47 | 48 | func TestTimeConversions(t *testing.T) { 49 | unixSecs := int64(1136239445) 50 | unixNsecs := int64(123456789) 51 | unixNano := unixSecs*1e9 + unixNsecs 52 | 53 | t1 := time.Unix(unixSecs, unixNsecs-unixNsecs%nanosPerTick) 54 | t2 := time.Unix(unixSecs, unixNsecs) 55 | 56 | ts := TimeFromUnixNano(unixNano) 57 | if !ts.Time().Equal(t1) { 58 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 59 | } 60 | 61 | // Test available precision. 62 | ts = TimeFromUnixNano(t2.UnixNano()) 63 | if !ts.Time().Equal(t1) { 64 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 65 | } 66 | 67 | if ts.UnixNano() != unixNano-unixNano%nanosPerTick { 68 | t.Fatalf("Expected %d, got %d", unixNano, ts.UnixNano()) 69 | } 70 | } 71 | 72 | func TestDuration(t *testing.T) { 73 | duration := time.Second + time.Minute + time.Hour 74 | goTime := time.Unix(1136239445, 0) 75 | 76 | ts := TimeFromUnix(goTime.Unix()) 77 | if !goTime.Add(duration).Equal(ts.Add(duration).Time()) { 78 | t.Fatalf("Expected %s to be equal to %s", goTime.Add(duration), ts.Add(duration)) 79 | } 80 | 81 | earlier := ts.Add(-duration) 82 | delta := ts.Sub(earlier) 83 | if delta != duration { 84 | t.Fatalf("Expected %s to be equal to %s", delta, duration) 85 | } 86 | } 87 | 88 | func TestParseDuration(t *testing.T) { 89 | var cases = []struct { 90 | in string 91 | out time.Duration 92 | }{ 93 | { 94 | in: "0s", 95 | out: 0, 96 | }, { 97 | in: "324ms", 98 | out: 324 * time.Millisecond, 99 | }, { 100 | in: "3s", 101 | out: 3 * time.Second, 102 | }, { 103 | in: "5m", 104 | out: 5 * time.Minute, 105 | }, { 106 | in: "1h", 107 | out: time.Hour, 108 | }, { 109 | in: "4d", 110 | out: 4 * 24 * time.Hour, 111 | }, { 112 | in: "3w", 113 | out: 3 * 7 * 24 * time.Hour, 114 | }, { 115 | in: "10y", 116 | out: 10 * 365 * 24 * time.Hour, 117 | }, 118 | } 119 | 120 | for _, c := range cases { 121 | d, err := ParseDuration(c.in) 122 | if err != nil { 123 | t.Errorf("Unexpected error on input %q", c.in) 124 | } 125 | if time.Duration(d) != c.out { 126 | t.Errorf("Expected %v but got %v", c.out, d) 127 | } 128 | if d.String() != c.in { 129 | t.Errorf("Expected duration string %q but got %q", c.in, d.String()) 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.9.x 7 | - 1.x 8 | 9 | go_import_path: github.com/prometheus/procfs 10 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull request, 6 | addressing (with `@...`) the maintainer of this repository (see 7 | [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | * Tobias Schmidt 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/Makefile: -------------------------------------------------------------------------------- 1 | ci: fmt lint test 2 | 3 | fmt: 4 | ! gofmt -l *.go | read nothing 5 | go vet 6 | 7 | lint: 8 | go get github.com/golang/lint/golint 9 | golint *.go 10 | 11 | test: sysfs/fixtures/.unpacked 12 | go test -v ./... 13 | 14 | sysfs/fixtures/.unpacked: sysfs/fixtures.ttar 15 | ./ttar -C sysfs -x -f sysfs/fixtures.ttar 16 | touch $@ 17 | 18 | .PHONY: fmt lint test ci 19 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/NOTICE: -------------------------------------------------------------------------------- 1 | procfs provides functions to retrieve system, kernel and process 2 | metrics from the pseudo-filesystem proc. 3 | 4 | Copyright 2014-2015 The Prometheus Authors 5 | 6 | This product includes software developed at 7 | SoundCloud Ltd. (http://soundcloud.com/). 8 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/README.md: -------------------------------------------------------------------------------- 1 | # procfs 2 | 3 | This procfs package provides functions to retrieve system, kernel and process 4 | metrics from the pseudo-filesystem proc. 5 | 6 | *WARNING*: This package is a work in progress. Its API may still break in 7 | backwards-incompatible ways without warnings. Use it at your own risk. 8 | 9 | [![GoDoc](https://godoc.org/github.com/prometheus/procfs?status.png)](https://godoc.org/github.com/prometheus/procfs) 10 | [![Build Status](https://travis-ci.org/prometheus/procfs.svg?branch=master)](https://travis-ci.org/prometheus/procfs) 11 | [![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/procfs)](https://goreportcard.com/report/github.com/prometheus/procfs) 12 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/buddyinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "os" 21 | "strconv" 22 | "strings" 23 | ) 24 | 25 | // A BuddyInfo is the details parsed from /proc/buddyinfo. 26 | // The data is comprised of an array of free fragments of each size. 27 | // The sizes are 2^n*PAGE_SIZE, where n is the array index. 28 | type BuddyInfo struct { 29 | Node string 30 | Zone string 31 | Sizes []float64 32 | } 33 | 34 | // NewBuddyInfo reads the buddyinfo statistics. 35 | func NewBuddyInfo() ([]BuddyInfo, error) { 36 | fs, err := NewFS(DefaultMountPoint) 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | return fs.NewBuddyInfo() 42 | } 43 | 44 | // NewBuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem. 45 | func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { 46 | file, err := os.Open(fs.Path("buddyinfo")) 47 | if err != nil { 48 | return nil, err 49 | } 50 | defer file.Close() 51 | 52 | return parseBuddyInfo(file) 53 | } 54 | 55 | func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) { 56 | var ( 57 | buddyInfo = []BuddyInfo{} 58 | scanner = bufio.NewScanner(r) 59 | bucketCount = -1 60 | ) 61 | 62 | for scanner.Scan() { 63 | var err error 64 | line := scanner.Text() 65 | parts := strings.Fields(line) 66 | 67 | if len(parts) < 4 { 68 | return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo") 69 | } 70 | 71 | node := strings.TrimRight(parts[1], ",") 72 | zone := strings.TrimRight(parts[3], ",") 73 | arraySize := len(parts[4:]) 74 | 75 | if bucketCount == -1 { 76 | bucketCount = arraySize 77 | } else { 78 | if bucketCount != arraySize { 79 | return nil, fmt.Errorf("mismatch in number of buddyinfo buckets, previous count %d, new count %d", bucketCount, arraySize) 80 | } 81 | } 82 | 83 | sizes := make([]float64, arraySize) 84 | for i := 0; i < arraySize; i++ { 85 | sizes[i], err = strconv.ParseFloat(parts[i+4], 64) 86 | if err != nil { 87 | return nil, fmt.Errorf("invalid value in buddyinfo: %s", err) 88 | } 89 | } 90 | 91 | buddyInfo = append(buddyInfo, BuddyInfo{node, zone, sizes}) 92 | } 93 | 94 | return buddyInfo, scanner.Err() 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/buddyinfo_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "strings" 18 | "testing" 19 | ) 20 | 21 | func TestBuddyInfo(t *testing.T) { 22 | buddyInfo, err := FS("fixtures/buddyinfo/valid").NewBuddyInfo() 23 | if err != nil { 24 | t.Fatal(err) 25 | } 26 | 27 | if want, got := "DMA", buddyInfo[0].Zone; want != got { 28 | t.Errorf("want Node 0, Zone %s, got %s", want, got) 29 | } 30 | 31 | if want, got := "Normal", buddyInfo[2].Zone; want != got { 32 | t.Errorf("want Node 0, Zone %s, got %s", want, got) 33 | } 34 | 35 | if want, got := 4381.0, buddyInfo[2].Sizes[0]; want != got { 36 | t.Errorf("want Node 0, Zone Normal %f, got %f", want, got) 37 | } 38 | 39 | if want, got := 572.0, buddyInfo[1].Sizes[1]; want != got { 40 | t.Errorf("want Node 0, Zone DMA32 %f, got %f", want, got) 41 | } 42 | } 43 | 44 | func TestBuddyInfoShort(t *testing.T) { 45 | _, err := FS("fixtures/buddyinfo/short").NewBuddyInfo() 46 | if err == nil { 47 | t.Errorf("expected error, but none occurred") 48 | } 49 | 50 | if want, got := "invalid number of fields when parsing buddyinfo", err.Error(); want != got { 51 | t.Errorf("wrong error returned, wanted %q, got %q", want, got) 52 | } 53 | } 54 | 55 | func TestBuddyInfoSizeMismatch(t *testing.T) { 56 | _, err := FS("fixtures/buddyinfo/sizemismatch").NewBuddyInfo() 57 | if err == nil { 58 | t.Errorf("expected error, but none occurred") 59 | } 60 | 61 | if want, got := "mismatch in number of buddyinfo buckets", err.Error(); !strings.HasPrefix(got, want) { 62 | t.Errorf("wrong error returned, wanted prefix %q, got %q", want, got) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Prometheus Team 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package procfs provides functions to retrieve system, kernel and process 15 | // metrics from the pseudo-filesystem proc. 16 | // 17 | // Example: 18 | // 19 | // package main 20 | // 21 | // import ( 22 | // "fmt" 23 | // "log" 24 | // 25 | // "github.com/prometheus/procfs" 26 | // ) 27 | // 28 | // func main() { 29 | // p, err := procfs.Self() 30 | // if err != nil { 31 | // log.Fatalf("could not get process: %s", err) 32 | // } 33 | // 34 | // stat, err := p.NewStat() 35 | // if err != nil { 36 | // log.Fatalf("could not get process stat: %s", err) 37 | // } 38 | // 39 | // fmt.Printf("command: %s\n", stat.Comm) 40 | // fmt.Printf("cpu time: %fs\n", stat.CPUTime()) 41 | // fmt.Printf("vsize: %dB\n", stat.VirtualMemory()) 42 | // fmt.Printf("rss: %dB\n", stat.ResidentMemory()) 43 | // } 44 | // 45 | package procfs 46 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/fs.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | 8 | "github.com/prometheus/procfs/nfs" 9 | "github.com/prometheus/procfs/xfs" 10 | ) 11 | 12 | // FS represents the pseudo-filesystem proc, which provides an interface to 13 | // kernel data structures. 14 | type FS string 15 | 16 | // DefaultMountPoint is the common mount point of the proc filesystem. 17 | const DefaultMountPoint = "/proc" 18 | 19 | // NewFS returns a new FS mounted under the given mountPoint. It will error 20 | // if the mount point can't be read. 21 | func NewFS(mountPoint string) (FS, error) { 22 | info, err := os.Stat(mountPoint) 23 | if err != nil { 24 | return "", fmt.Errorf("could not read %s: %s", mountPoint, err) 25 | } 26 | if !info.IsDir() { 27 | return "", fmt.Errorf("mount point %s is not a directory", mountPoint) 28 | } 29 | 30 | return FS(mountPoint), nil 31 | } 32 | 33 | // Path returns the path of the given subsystem relative to the procfs root. 34 | func (fs FS) Path(p ...string) string { 35 | return path.Join(append([]string{string(fs)}, p...)...) 36 | } 37 | 38 | // XFSStats retrieves XFS filesystem runtime statistics. 39 | func (fs FS) XFSStats() (*xfs.Stats, error) { 40 | f, err := os.Open(fs.Path("fs/xfs/stat")) 41 | if err != nil { 42 | return nil, err 43 | } 44 | defer f.Close() 45 | 46 | return xfs.ParseStats(f) 47 | } 48 | 49 | // NFSdClientRPCStats retrieves NFS daemon RPC statistics. 50 | func (fs FS) NFSdClientRPCStats() (*nfs.ClientRPCStats, error) { 51 | f, err := os.Open(fs.Path("net/rpc/nfs")) 52 | if err != nil { 53 | return nil, err 54 | } 55 | defer f.Close() 56 | 57 | return nfs.ParseClientRPCStats(f) 58 | } 59 | 60 | // NFSdServerRPCStats retrieves NFS daemon RPC statistics. 61 | func (fs FS) NFSdServerRPCStats() (*nfs.ServerRPCStats, error) { 62 | f, err := os.Open(fs.Path("net/rpc/nfsd")) 63 | if err != nil { 64 | return nil, err 65 | } 66 | defer f.Close() 67 | 68 | return nfs.ParseServerRPCStats(f) 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/fs_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestNewFS(t *testing.T) { 6 | if _, err := NewFS("foobar"); err == nil { 7 | t.Error("want NewFS to fail for non-existing mount point") 8 | } 9 | 10 | if _, err := NewFS("procfs.go"); err == nil { 11 | t.Error("want NewFS to fail if mount point is not a directory") 12 | } 13 | } 14 | 15 | func TestFSXFSStats(t *testing.T) { 16 | stats, err := FS("fixtures").XFSStats() 17 | if err != nil { 18 | t.Fatalf("failed to parse XFS stats: %v", err) 19 | } 20 | 21 | // Very lightweight test just to sanity check the path used 22 | // to open XFS stats. Heavier tests in package xfs. 23 | if want, got := uint32(92447), stats.ExtentAllocation.ExtentsAllocated; want != got { 24 | t.Errorf("unexpected extents allocated:\nwant: %d\nhave: %d", want, got) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/internal/util/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package util 15 | 16 | import "strconv" 17 | 18 | // ParseUint32s parses a slice of strings into a slice of uint32s. 19 | func ParseUint32s(ss []string) ([]uint32, error) { 20 | us := make([]uint32, 0, len(ss)) 21 | for _, s := range ss { 22 | u, err := strconv.ParseUint(s, 10, 32) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | us = append(us, uint32(u)) 28 | } 29 | 30 | return us, nil 31 | } 32 | 33 | // ParseUint64s parses a slice of strings into a slice of uint64s. 34 | func ParseUint64s(ss []string) ([]uint64, error) { 35 | us := make([]uint64, 0, len(ss)) 36 | for _, s := range ss { 37 | u, err := strconv.ParseUint(s, 10, 64) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | us = append(us, u) 43 | } 44 | 45 | return us, nil 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/mdstat.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "regexp" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | var ( 12 | statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`) 13 | buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`) 14 | ) 15 | 16 | // MDStat holds info parsed from /proc/mdstat. 17 | type MDStat struct { 18 | // Name of the device. 19 | Name string 20 | // activity-state of the device. 21 | ActivityState string 22 | // Number of active disks. 23 | DisksActive int64 24 | // Total number of disks the device consists of. 25 | DisksTotal int64 26 | // Number of blocks the device holds. 27 | BlocksTotal int64 28 | // Number of blocks on the device that are in sync. 29 | BlocksSynced int64 30 | } 31 | 32 | // ParseMDStat parses an mdstat-file and returns a struct with the relevant infos. 33 | func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { 34 | mdStatusFilePath := fs.Path("mdstat") 35 | content, err := ioutil.ReadFile(mdStatusFilePath) 36 | if err != nil { 37 | return []MDStat{}, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) 38 | } 39 | 40 | mdStates := []MDStat{} 41 | lines := strings.Split(string(content), "\n") 42 | for i, l := range lines { 43 | if l == "" { 44 | continue 45 | } 46 | if l[0] == ' ' { 47 | continue 48 | } 49 | if strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { 50 | continue 51 | } 52 | 53 | mainLine := strings.Split(l, " ") 54 | if len(mainLine) < 3 { 55 | return mdStates, fmt.Errorf("error parsing mdline: %s", l) 56 | } 57 | mdName := mainLine[0] 58 | activityState := mainLine[2] 59 | 60 | if len(lines) <= i+3 { 61 | return mdStates, fmt.Errorf( 62 | "error parsing %s: too few lines for md device %s", 63 | mdStatusFilePath, 64 | mdName, 65 | ) 66 | } 67 | 68 | active, total, size, err := evalStatusline(lines[i+1]) 69 | if err != nil { 70 | return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) 71 | } 72 | 73 | // j is the line number of the syncing-line. 74 | j := i + 2 75 | if strings.Contains(lines[i+2], "bitmap") { // skip bitmap line 76 | j = i + 3 77 | } 78 | 79 | // If device is syncing at the moment, get the number of currently 80 | // synced bytes, otherwise that number equals the size of the device. 81 | syncedBlocks := size 82 | if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") { 83 | syncedBlocks, err = evalBuildline(lines[j]) 84 | if err != nil { 85 | return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) 86 | } 87 | } 88 | 89 | mdStates = append(mdStates, MDStat{ 90 | Name: mdName, 91 | ActivityState: activityState, 92 | DisksActive: active, 93 | DisksTotal: total, 94 | BlocksTotal: size, 95 | BlocksSynced: syncedBlocks, 96 | }) 97 | } 98 | 99 | return mdStates, nil 100 | } 101 | 102 | func evalStatusline(statusline string) (active, total, size int64, err error) { 103 | matches := statuslineRE.FindStringSubmatch(statusline) 104 | if len(matches) != 4 { 105 | return 0, 0, 0, fmt.Errorf("unexpected statusline: %s", statusline) 106 | } 107 | 108 | size, err = strconv.ParseInt(matches[1], 10, 64) 109 | if err != nil { 110 | return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) 111 | } 112 | 113 | total, err = strconv.ParseInt(matches[2], 10, 64) 114 | if err != nil { 115 | return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) 116 | } 117 | 118 | active, err = strconv.ParseInt(matches[3], 10, 64) 119 | if err != nil { 120 | return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) 121 | } 122 | 123 | return active, total, size, nil 124 | } 125 | 126 | func evalBuildline(buildline string) (syncedBlocks int64, err error) { 127 | matches := buildlineRE.FindStringSubmatch(buildline) 128 | if len(matches) != 2 { 129 | return 0, fmt.Errorf("unexpected buildline: %s", buildline) 130 | } 131 | 132 | syncedBlocks, err = strconv.ParseInt(matches[1], 10, 64) 133 | if err != nil { 134 | return 0, fmt.Errorf("%s in buildline: %s", err, buildline) 135 | } 136 | 137 | return syncedBlocks, nil 138 | } 139 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/mdstat_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMDStat(t *testing.T) { 8 | mdStates, err := FS("fixtures").ParseMDStat() 9 | if err != nil { 10 | t.Fatalf("parsing of reference-file failed entirely: %s", err) 11 | } 12 | 13 | refs := map[string]MDStat{ 14 | "md3": {"md3", "active", 8, 8, 5853468288, 5853468288}, 15 | "md127": {"md127", "active", 2, 2, 312319552, 312319552}, 16 | "md0": {"md0", "active", 2, 2, 248896, 248896}, 17 | "md4": {"md4", "inactive", 2, 2, 4883648, 4883648}, 18 | "md6": {"md6", "active", 1, 2, 195310144, 16775552}, 19 | "md8": {"md8", "active", 2, 2, 195310144, 16775552}, 20 | "md7": {"md7", "active", 3, 4, 7813735424, 7813735424}, 21 | } 22 | 23 | if want, have := len(refs), len(mdStates); want != have { 24 | t.Errorf("want %d parsed md-devices, have %d", want, have) 25 | } 26 | for _, md := range mdStates { 27 | if want, have := refs[md.Name], md; want != have { 28 | t.Errorf("%s: want %v, have %v", md.Name, want, have) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/net_dev_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNetDevParseLine(t *testing.T) { 8 | const rawLine = ` eth0: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16` 9 | 10 | have, err := NetDev{}.parseLine(rawLine) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | 15 | want := NetDevLine{"eth0", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 16 | if want != *have { 17 | t.Errorf("want %v, have %v", want, have) 18 | } 19 | } 20 | 21 | func TestNewNetDev(t *testing.T) { 22 | fs, err := NewFS("fixtures") 23 | if err != nil { 24 | t.Fatal(err) 25 | } 26 | 27 | nd, err := fs.NewNetDev() 28 | if err != nil { 29 | t.Fatal(err) 30 | } 31 | 32 | lines := map[string]NetDevLine{ 33 | "vethf345468": {Name: "vethf345468", RxBytes: 648, RxPackets: 8, TxBytes: 438, TxPackets: 5}, 34 | "lo": {Name: "lo", RxBytes: 1664039048, RxPackets: 1566805, TxBytes: 1664039048, TxPackets: 1566805}, 35 | "docker0": {Name: "docker0", RxBytes: 2568, RxPackets: 38, TxBytes: 438, TxPackets: 5}, 36 | "eth0": {Name: "eth0", RxBytes: 874354587, RxPackets: 1036395, TxBytes: 563352563, TxPackets: 732147}, 37 | } 38 | 39 | if want, have := len(lines), len(nd); want != have { 40 | t.Errorf("want %d parsed net/dev lines, have %d", want, have) 41 | } 42 | for _, line := range nd { 43 | if want, have := lines[line.Name], line; want != have { 44 | t.Errorf("%s: want %v, have %v", line.Name, want, have) 45 | } 46 | } 47 | } 48 | 49 | func TestProcNewNetDev(t *testing.T) { 50 | p, err := FS("fixtures").NewProc(26231) 51 | if err != nil { 52 | t.Fatal(err) 53 | } 54 | 55 | nd, err := p.NewNetDev() 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | 60 | lines := map[string]NetDevLine{ 61 | "lo": {Name: "lo"}, 62 | "eth0": {Name: "eth0", RxBytes: 438, RxPackets: 5, TxBytes: 648, TxPackets: 8}, 63 | } 64 | 65 | if want, have := len(lines), len(nd); want != have { 66 | t.Errorf("want %d parsed net/dev lines, have %d", want, have) 67 | } 68 | for _, line := range nd { 69 | if want, have := lines[line.Name], line; want != have { 70 | t.Errorf("%s: want %v, have %v", line.Name, want, have) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/nfs/parse_nfs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package nfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "strings" 21 | 22 | "github.com/prometheus/procfs/internal/util" 23 | ) 24 | 25 | // ParseClientRPCStats returns stats read from /proc/net/rpc/nfs 26 | func ParseClientRPCStats(r io.Reader) (*ClientRPCStats, error) { 27 | stats := &ClientRPCStats{} 28 | 29 | scanner := bufio.NewScanner(r) 30 | for scanner.Scan() { 31 | line := scanner.Text() 32 | parts := strings.Fields(scanner.Text()) 33 | // require at least 34 | if len(parts) < 2 { 35 | return nil, fmt.Errorf("invalid NFSd metric line %q", line) 36 | } 37 | 38 | values, err := util.ParseUint64s(parts[1:]) 39 | if err != nil { 40 | return nil, fmt.Errorf("error parsing NFSd metric line: %s", err) 41 | } 42 | 43 | switch metricLine := parts[0]; metricLine { 44 | case "net": 45 | stats.Network, err = parseNetwork(values) 46 | case "rpc": 47 | stats.ClientRPC, err = parseClientRPC(values) 48 | case "proc2": 49 | stats.V2Stats, err = parseV2Stats(values) 50 | case "proc3": 51 | stats.V3Stats, err = parseV3Stats(values) 52 | case "proc4": 53 | stats.ClientV4Stats, err = parseClientV4Stats(values) 54 | default: 55 | return nil, fmt.Errorf("unknown NFSd metric line %q", metricLine) 56 | } 57 | if err != nil { 58 | return nil, fmt.Errorf("errors parsing NFSd metric line: %s", err) 59 | } 60 | } 61 | 62 | if err := scanner.Err(); err != nil { 63 | return nil, fmt.Errorf("error scanning NFSd file: %s", err) 64 | } 65 | 66 | return stats, nil 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/nfs/parse_nfsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package nfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "strings" 21 | 22 | "github.com/prometheus/procfs/internal/util" 23 | ) 24 | 25 | // ParseServerRPCStats returns stats read from /proc/net/rpc/nfsd 26 | func ParseServerRPCStats(r io.Reader) (*ServerRPCStats, error) { 27 | stats := &ServerRPCStats{} 28 | 29 | scanner := bufio.NewScanner(r) 30 | for scanner.Scan() { 31 | line := scanner.Text() 32 | parts := strings.Fields(scanner.Text()) 33 | // require at least 34 | if len(parts) < 2 { 35 | return nil, fmt.Errorf("invalid NFSd metric line %q", line) 36 | } 37 | label := parts[0] 38 | 39 | var values []uint64 40 | var err error 41 | if label == "th" { 42 | if len(parts) < 3 { 43 | return nil, fmt.Errorf("invalid NFSd th metric line %q", line) 44 | } 45 | values, err = util.ParseUint64s(parts[1:3]) 46 | } else { 47 | values, err = util.ParseUint64s(parts[1:]) 48 | } 49 | if err != nil { 50 | return nil, fmt.Errorf("error parsing NFSd metric line: %s", err) 51 | } 52 | 53 | switch metricLine := parts[0]; metricLine { 54 | case "rc": 55 | stats.ReplyCache, err = parseReplyCache(values) 56 | case "fh": 57 | stats.FileHandles, err = parseFileHandles(values) 58 | case "io": 59 | stats.InputOutput, err = parseInputOutput(values) 60 | case "th": 61 | stats.Threads, err = parseThreads(values) 62 | case "ra": 63 | stats.ReadAheadCache, err = parseReadAheadCache(values) 64 | case "net": 65 | stats.Network, err = parseNetwork(values) 66 | case "rpc": 67 | stats.ServerRPC, err = parseServerRPC(values) 68 | case "proc2": 69 | stats.V2Stats, err = parseV2Stats(values) 70 | case "proc3": 71 | stats.V3Stats, err = parseV3Stats(values) 72 | case "proc4": 73 | stats.ServerV4Stats, err = parseServerV4Stats(values) 74 | case "proc4ops": 75 | stats.V4Ops, err = parseV4Ops(values) 76 | default: 77 | return nil, fmt.Errorf("unknown NFSd metric line %q", metricLine) 78 | } 79 | if err != nil { 80 | return nil, fmt.Errorf("errors parsing NFSd metric line: %s", err) 81 | } 82 | } 83 | 84 | if err := scanner.Err(); err != nil { 85 | return nil, fmt.Errorf("error scanning NFSd file: %s", err) 86 | } 87 | 88 | return stats, nil 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_io.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | // ProcIO models the content of /proc//io. 10 | type ProcIO struct { 11 | // Chars read. 12 | RChar uint64 13 | // Chars written. 14 | WChar uint64 15 | // Read syscalls. 16 | SyscR uint64 17 | // Write syscalls. 18 | SyscW uint64 19 | // Bytes read. 20 | ReadBytes uint64 21 | // Bytes written. 22 | WriteBytes uint64 23 | // Bytes written, but taking into account truncation. See 24 | // Documentation/filesystems/proc.txt in the kernel sources for 25 | // detailed explanation. 26 | CancelledWriteBytes int64 27 | } 28 | 29 | // NewIO creates a new ProcIO instance from a given Proc instance. 30 | func (p Proc) NewIO() (ProcIO, error) { 31 | pio := ProcIO{} 32 | 33 | f, err := os.Open(p.path("io")) 34 | if err != nil { 35 | return pio, err 36 | } 37 | defer f.Close() 38 | 39 | data, err := ioutil.ReadAll(f) 40 | if err != nil { 41 | return pio, err 42 | } 43 | 44 | ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" + 45 | "read_bytes: %d\nwrite_bytes: %d\n" + 46 | "cancelled_write_bytes: %d\n" 47 | 48 | _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR, 49 | &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes) 50 | 51 | return pio, err 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_io_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestProcIO(t *testing.T) { 6 | p, err := FS("fixtures").NewProc(26231) 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | s, err := p.NewIO() 12 | if err != nil { 13 | t.Fatal(err) 14 | } 15 | 16 | for _, test := range []struct { 17 | name string 18 | want int64 19 | have int64 20 | }{ 21 | {name: "RChar", want: 750339, have: int64(s.RChar)}, 22 | {name: "WChar", want: 818609, have: int64(s.WChar)}, 23 | {name: "SyscR", want: 7405, have: int64(s.SyscR)}, 24 | {name: "SyscW", want: 5245, have: int64(s.SyscW)}, 25 | {name: "ReadBytes", want: 1024, have: int64(s.ReadBytes)}, 26 | {name: "WriteBytes", want: 2048, have: int64(s.WriteBytes)}, 27 | {name: "CancelledWriteBytes", want: -1024, have: s.CancelledWriteBytes}, 28 | } { 29 | if test.want != test.have { 30 | t.Errorf("want %s %d, have %d", test.name, test.want, test.have) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_limits.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "regexp" 8 | "strconv" 9 | ) 10 | 11 | // ProcLimits represents the soft limits for each of the process's resource 12 | // limits. For more information see getrlimit(2): 13 | // http://man7.org/linux/man-pages/man2/getrlimit.2.html. 14 | type ProcLimits struct { 15 | // CPU time limit in seconds. 16 | CPUTime int64 17 | // Maximum size of files that the process may create. 18 | FileSize int64 19 | // Maximum size of the process's data segment (initialized data, 20 | // uninitialized data, and heap). 21 | DataSize int64 22 | // Maximum size of the process stack in bytes. 23 | StackSize int64 24 | // Maximum size of a core file. 25 | CoreFileSize int64 26 | // Limit of the process's resident set in pages. 27 | ResidentSet int64 28 | // Maximum number of processes that can be created for the real user ID of 29 | // the calling process. 30 | Processes int64 31 | // Value one greater than the maximum file descriptor number that can be 32 | // opened by this process. 33 | OpenFiles int64 34 | // Maximum number of bytes of memory that may be locked into RAM. 35 | LockedMemory int64 36 | // Maximum size of the process's virtual memory address space in bytes. 37 | AddressSpace int64 38 | // Limit on the combined number of flock(2) locks and fcntl(2) leases that 39 | // this process may establish. 40 | FileLocks int64 41 | // Limit of signals that may be queued for the real user ID of the calling 42 | // process. 43 | PendingSignals int64 44 | // Limit on the number of bytes that can be allocated for POSIX message 45 | // queues for the real user ID of the calling process. 46 | MsqqueueSize int64 47 | // Limit of the nice priority set using setpriority(2) or nice(2). 48 | NicePriority int64 49 | // Limit of the real-time priority set using sched_setscheduler(2) or 50 | // sched_setparam(2). 51 | RealtimePriority int64 52 | // Limit (in microseconds) on the amount of CPU time that a process 53 | // scheduled under a real-time scheduling policy may consume without making 54 | // a blocking system call. 55 | RealtimeTimeout int64 56 | } 57 | 58 | const ( 59 | limitsFields = 3 60 | limitsUnlimited = "unlimited" 61 | ) 62 | 63 | var ( 64 | limitsDelimiter = regexp.MustCompile(" +") 65 | ) 66 | 67 | // NewLimits returns the current soft limits of the process. 68 | func (p Proc) NewLimits() (ProcLimits, error) { 69 | f, err := os.Open(p.path("limits")) 70 | if err != nil { 71 | return ProcLimits{}, err 72 | } 73 | defer f.Close() 74 | 75 | var ( 76 | l = ProcLimits{} 77 | s = bufio.NewScanner(f) 78 | ) 79 | for s.Scan() { 80 | fields := limitsDelimiter.Split(s.Text(), limitsFields) 81 | if len(fields) != limitsFields { 82 | return ProcLimits{}, fmt.Errorf( 83 | "couldn't parse %s line %s", f.Name(), s.Text()) 84 | } 85 | 86 | switch fields[0] { 87 | case "Max cpu time": 88 | l.CPUTime, err = parseInt(fields[1]) 89 | case "Max file size": 90 | l.FileSize, err = parseInt(fields[1]) 91 | case "Max data size": 92 | l.DataSize, err = parseInt(fields[1]) 93 | case "Max stack size": 94 | l.StackSize, err = parseInt(fields[1]) 95 | case "Max core file size": 96 | l.CoreFileSize, err = parseInt(fields[1]) 97 | case "Max resident set": 98 | l.ResidentSet, err = parseInt(fields[1]) 99 | case "Max processes": 100 | l.Processes, err = parseInt(fields[1]) 101 | case "Max open files": 102 | l.OpenFiles, err = parseInt(fields[1]) 103 | case "Max locked memory": 104 | l.LockedMemory, err = parseInt(fields[1]) 105 | case "Max address space": 106 | l.AddressSpace, err = parseInt(fields[1]) 107 | case "Max file locks": 108 | l.FileLocks, err = parseInt(fields[1]) 109 | case "Max pending signals": 110 | l.PendingSignals, err = parseInt(fields[1]) 111 | case "Max msgqueue size": 112 | l.MsqqueueSize, err = parseInt(fields[1]) 113 | case "Max nice priority": 114 | l.NicePriority, err = parseInt(fields[1]) 115 | case "Max realtime priority": 116 | l.RealtimePriority, err = parseInt(fields[1]) 117 | case "Max realtime timeout": 118 | l.RealtimeTimeout, err = parseInt(fields[1]) 119 | } 120 | if err != nil { 121 | return ProcLimits{}, err 122 | } 123 | } 124 | 125 | return l, s.Err() 126 | } 127 | 128 | func parseInt(s string) (int64, error) { 129 | if s == limitsUnlimited { 130 | return -1, nil 131 | } 132 | i, err := strconv.ParseInt(s, 10, 64) 133 | if err != nil { 134 | return 0, fmt.Errorf("couldn't parse value %s: %s", s, err) 135 | } 136 | return i, nil 137 | } 138 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_limits_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestNewLimits(t *testing.T) { 6 | p, err := FS("fixtures").NewProc(26231) 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | l, err := p.NewLimits() 12 | if err != nil { 13 | t.Fatal(err) 14 | } 15 | 16 | for _, test := range []struct { 17 | name string 18 | want int64 19 | have int64 20 | }{ 21 | {name: "cpu time", want: -1, have: l.CPUTime}, 22 | {name: "open files", want: 2048, have: l.OpenFiles}, 23 | {name: "msgqueue size", want: 819200, have: l.MsqqueueSize}, 24 | {name: "nice priority", want: 0, have: l.NicePriority}, 25 | {name: "address space", want: 8589934592, have: l.AddressSpace}, 26 | } { 27 | if test.want != test.have { 28 | t.Errorf("want %s %d, have %d", test.name, test.want, test.have) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_ns.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // Namespace represents a single namespace of a process. 11 | type Namespace struct { 12 | Type string // Namespace type. 13 | Inode uint32 // Inode number of the namespace. If two processes are in the same namespace their inodes will match. 14 | } 15 | 16 | // Namespaces contains all of the namespaces that the process is contained in. 17 | type Namespaces map[string]Namespace 18 | 19 | // NewNamespaces reads from /proc/[pid/ns/* to get the namespaces of which the 20 | // process is a member. 21 | func (p Proc) NewNamespaces() (Namespaces, error) { 22 | d, err := os.Open(p.path("ns")) 23 | if err != nil { 24 | return nil, err 25 | } 26 | defer d.Close() 27 | 28 | names, err := d.Readdirnames(-1) 29 | if err != nil { 30 | return nil, fmt.Errorf("failed to read contents of ns dir: %v", err) 31 | } 32 | 33 | ns := make(Namespaces, len(names)) 34 | for _, name := range names { 35 | target, err := os.Readlink(p.path("ns", name)) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | fields := strings.SplitN(target, ":", 2) 41 | if len(fields) != 2 { 42 | return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", target) 43 | } 44 | 45 | typ := fields[0] 46 | inode, err := strconv.ParseUint(strings.Trim(fields[1], "[]"), 10, 32) 47 | if err != nil { 48 | return nil, fmt.Errorf("failed to parse inode from '%v': %v", fields[1], err) 49 | } 50 | 51 | ns[name] = Namespace{typ, uint32(inode)} 52 | } 53 | 54 | return ns, nil 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_ns_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNewNamespaces(t *testing.T) { 8 | p, err := FS("fixtures").NewProc(26231) 9 | if err != nil { 10 | t.Fatal(err) 11 | } 12 | 13 | namespaces, err := p.NewNamespaces() 14 | if err != nil { 15 | t.Fatal(err) 16 | } 17 | 18 | expectedNamespaces := map[string]Namespace{ 19 | "mnt": {"mnt", 4026531840}, 20 | "net": {"net", 4026531993}, 21 | } 22 | 23 | if want, have := len(expectedNamespaces), len(namespaces); want != have { 24 | t.Errorf("want %d parsed namespaces, have %d", want, have) 25 | } 26 | for _, ns := range namespaces { 27 | if want, have := expectedNamespaces[ns.Type], ns; want != have { 28 | t.Errorf("%s: want %v, have %v", ns.Type, want, have) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_stat_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestProcStat(t *testing.T) { 9 | p, err := FS("fixtures").NewProc(26231) 10 | if err != nil { 11 | t.Fatal(err) 12 | } 13 | 14 | s, err := p.NewStat() 15 | if err != nil { 16 | t.Fatal(err) 17 | } 18 | 19 | for _, test := range []struct { 20 | name string 21 | want int 22 | have int 23 | }{ 24 | {name: "pid", want: 26231, have: s.PID}, 25 | {name: "user time", want: 1677, have: int(s.UTime)}, 26 | {name: "system time", want: 44, have: int(s.STime)}, 27 | {name: "start time", want: 82375, have: int(s.Starttime)}, 28 | {name: "virtual memory size", want: 56274944, have: s.VSize}, 29 | {name: "resident set size", want: 1981, have: s.RSS}, 30 | } { 31 | if test.want != test.have { 32 | t.Errorf("want %s %d, have %d", test.name, test.want, test.have) 33 | } 34 | } 35 | } 36 | 37 | func TestProcStatComm(t *testing.T) { 38 | s1, err := testProcStat(26231) 39 | if err != nil { 40 | t.Fatal(err) 41 | } 42 | if want, have := "vim", s1.Comm; want != have { 43 | t.Errorf("want comm %s, have %s", want, have) 44 | } 45 | 46 | s2, err := testProcStat(584) 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | if want, have := "(a b ) ( c d) ", s2.Comm; want != have { 51 | t.Errorf("want comm %s, have %s", want, have) 52 | } 53 | } 54 | 55 | func TestProcStatVirtualMemory(t *testing.T) { 56 | s, err := testProcStat(26231) 57 | if err != nil { 58 | t.Fatal(err) 59 | } 60 | 61 | if want, have := 56274944, s.VirtualMemory(); want != have { 62 | t.Errorf("want virtual memory %d, have %d", want, have) 63 | } 64 | } 65 | 66 | func TestProcStatResidentMemory(t *testing.T) { 67 | s, err := testProcStat(26231) 68 | if err != nil { 69 | t.Fatal(err) 70 | } 71 | 72 | if want, have := 1981*os.Getpagesize(), s.ResidentMemory(); want != have { 73 | t.Errorf("want resident memory %d, have %d", want, have) 74 | } 75 | } 76 | 77 | func TestProcStatStartTime(t *testing.T) { 78 | s, err := testProcStat(26231) 79 | if err != nil { 80 | t.Fatal(err) 81 | } 82 | 83 | time, err := s.StartTime() 84 | if err != nil { 85 | t.Fatal(err) 86 | } 87 | if want, have := 1418184099.75, time; want != have { 88 | t.Errorf("want start time %f, have %f", want, have) 89 | } 90 | } 91 | 92 | func TestProcStatCPUTime(t *testing.T) { 93 | s, err := testProcStat(26231) 94 | if err != nil { 95 | t.Fatal(err) 96 | } 97 | 98 | if want, have := 17.21, s.CPUTime(); want != have { 99 | t.Errorf("want cpu time %f, have %f", want, have) 100 | } 101 | } 102 | 103 | func testProcStat(pid int) (ProcStat, error) { 104 | p, err := FS("fixtures").NewProc(pid) 105 | if err != nil { 106 | return ProcStat{}, err 107 | } 108 | 109 | return p.NewStat() 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | "testing" 7 | ) 8 | 9 | func TestSelf(t *testing.T) { 10 | fs := FS("fixtures") 11 | 12 | p1, err := fs.NewProc(26231) 13 | if err != nil { 14 | t.Fatal(err) 15 | } 16 | p2, err := fs.Self() 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | 21 | if !reflect.DeepEqual(p1, p2) { 22 | t.Errorf("want process %v, have %v", p1, p2) 23 | } 24 | } 25 | 26 | func TestAllProcs(t *testing.T) { 27 | procs, err := FS("fixtures").AllProcs() 28 | if err != nil { 29 | t.Fatal(err) 30 | } 31 | sort.Sort(procs) 32 | for i, p := range []*Proc{{PID: 584}, {PID: 26231}} { 33 | if want, have := p.PID, procs[i].PID; want != have { 34 | t.Errorf("want processes %d, have %d", want, have) 35 | } 36 | } 37 | } 38 | 39 | func TestCmdLine(t *testing.T) { 40 | for _, tt := range []struct { 41 | process int 42 | want []string 43 | }{ 44 | {process: 26231, want: []string{"vim", "test.go", "+10"}}, 45 | {process: 26232, want: []string{}}, 46 | } { 47 | p1, err := FS("fixtures").NewProc(tt.process) 48 | if err != nil { 49 | t.Fatal(err) 50 | } 51 | c1, err := p1.CmdLine() 52 | if err != nil { 53 | t.Fatal(err) 54 | } 55 | if !reflect.DeepEqual(tt.want, c1) { 56 | t.Errorf("want cmdline %v, have %v", tt.want, c1) 57 | } 58 | } 59 | } 60 | 61 | func TestComm(t *testing.T) { 62 | for _, tt := range []struct { 63 | process int 64 | want string 65 | }{ 66 | {process: 26231, want: "vim"}, 67 | {process: 26232, want: "ata_sff"}, 68 | } { 69 | p1, err := FS("fixtures").NewProc(tt.process) 70 | if err != nil { 71 | t.Fatal(err) 72 | } 73 | c1, err := p1.Comm() 74 | if err != nil { 75 | t.Fatal(err) 76 | } 77 | if !reflect.DeepEqual(tt.want, c1) { 78 | t.Errorf("want comm %v, have %v", tt.want, c1) 79 | } 80 | } 81 | } 82 | 83 | func TestExecutable(t *testing.T) { 84 | for _, tt := range []struct { 85 | process int 86 | want string 87 | }{ 88 | {process: 26231, want: "/usr/bin/vim"}, 89 | {process: 26232, want: ""}, 90 | } { 91 | p, err := FS("fixtures").NewProc(tt.process) 92 | if err != nil { 93 | t.Fatal(err) 94 | } 95 | exe, err := p.Executable() 96 | if err != nil { 97 | t.Fatal(err) 98 | } 99 | if !reflect.DeepEqual(tt.want, exe) { 100 | t.Errorf("want absolute path to cmdline %v, have %v", tt.want, exe) 101 | } 102 | } 103 | } 104 | 105 | func TestFileDescriptors(t *testing.T) { 106 | p1, err := FS("fixtures").NewProc(26231) 107 | if err != nil { 108 | t.Fatal(err) 109 | } 110 | fds, err := p1.FileDescriptors() 111 | if err != nil { 112 | t.Fatal(err) 113 | } 114 | sort.Sort(byUintptr(fds)) 115 | if want := []uintptr{0, 1, 2, 3, 10}; !reflect.DeepEqual(want, fds) { 116 | t.Errorf("want fds %v, have %v", want, fds) 117 | } 118 | } 119 | 120 | func TestFileDescriptorTargets(t *testing.T) { 121 | p1, err := FS("fixtures").NewProc(26231) 122 | if err != nil { 123 | t.Fatal(err) 124 | } 125 | fds, err := p1.FileDescriptorTargets() 126 | if err != nil { 127 | t.Fatal(err) 128 | } 129 | sort.Strings(fds) 130 | var want = []string{ 131 | "../../symlinktargets/abc", 132 | "../../symlinktargets/def", 133 | "../../symlinktargets/ghi", 134 | "../../symlinktargets/uvw", 135 | "../../symlinktargets/xyz", 136 | } 137 | if !reflect.DeepEqual(want, fds) { 138 | t.Errorf("want fds %v, have %v", want, fds) 139 | } 140 | } 141 | 142 | func TestFileDescriptorsLen(t *testing.T) { 143 | p1, err := FS("fixtures").NewProc(26231) 144 | if err != nil { 145 | t.Fatal(err) 146 | } 147 | l, err := p1.FileDescriptorsLen() 148 | if err != nil { 149 | t.Fatal(err) 150 | } 151 | if want, have := 5, l; want != have { 152 | t.Errorf("want fds %d, have %d", want, have) 153 | } 154 | } 155 | 156 | type byUintptr []uintptr 157 | 158 | func (a byUintptr) Len() int { return len(a) } 159 | func (a byUintptr) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 160 | func (a byUintptr) Less(i, j int) bool { return a[i] < a[j] } 161 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/stat_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestStat(t *testing.T) { 6 | s, err := FS("fixtures").NewStat() 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | // cpu 12 | if want, have := float64(301854)/userHZ, s.CPUTotal.User; want != have { 13 | t.Errorf("want cpu/user %v, have %v", want, have) 14 | } 15 | if want, have := float64(31)/userHZ, s.CPU[7].SoftIRQ; want != have { 16 | t.Errorf("want cpu7/softirq %v, have %v", want, have) 17 | } 18 | 19 | // intr 20 | if want, have := uint64(8885917), s.IRQTotal; want != have { 21 | t.Errorf("want irq/total %d, have %d", want, have) 22 | } 23 | if want, have := uint64(1), s.IRQ[8]; want != have { 24 | t.Errorf("want irq8 %d, have %d", want, have) 25 | } 26 | 27 | // ctxt 28 | if want, have := uint64(38014093), s.ContextSwitches; want != have { 29 | t.Errorf("want context switches (ctxt) %d, have %d", want, have) 30 | } 31 | 32 | // btime 33 | if want, have := uint64(1418183276), s.BootTime; want != have { 34 | t.Errorf("want boot time (btime) %d, have %d", want, have) 35 | } 36 | 37 | // processes 38 | if want, have := uint64(26442), s.ProcessCreated; want != have { 39 | t.Errorf("want process created (processes) %d, have %d", want, have) 40 | } 41 | 42 | // procs_running 43 | if want, have := uint64(2), s.ProcessesRunning; want != have { 44 | t.Errorf("want processes running (procs_running) %d, have %d", want, have) 45 | } 46 | 47 | // procs_blocked 48 | if want, have := uint64(1), s.ProcessesBlocked; want != have { 49 | t.Errorf("want processes blocked (procs_blocked) %d, have %d", want, have) 50 | } 51 | 52 | // softirq 53 | if want, have := uint64(5057579), s.SoftIRQTotal; want != have { 54 | t.Errorf("want softirq total %d, have %d", want, have) 55 | } 56 | 57 | if want, have := uint64(508444), s.SoftIRQ.Rcu; want != have { 58 | t.Errorf("want softirq RCU %d, have %d", want, have) 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/xfrm_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Prometheus Team 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "testing" 18 | ) 19 | 20 | func TestXfrmStats(t *testing.T) { 21 | xfrmStats, err := FS("fixtures").NewXfrmStat() 22 | if err != nil { 23 | t.Fatal(err) 24 | } 25 | 26 | for _, test := range []struct { 27 | name string 28 | want int 29 | got int 30 | }{ 31 | {name: "XfrmInError", want: 1, got: xfrmStats.XfrmInError}, 32 | {name: "XfrmInBufferError", want: 2, got: xfrmStats.XfrmInBufferError}, 33 | {name: "XfrmInHdrError", want: 4, got: xfrmStats.XfrmInHdrError}, 34 | {name: "XfrmInNoStates", want: 3, got: xfrmStats.XfrmInNoStates}, 35 | {name: "XfrmInStateProtoError", want: 40, got: xfrmStats.XfrmInStateProtoError}, 36 | {name: "XfrmInStateModeError", want: 100, got: xfrmStats.XfrmInStateModeError}, 37 | {name: "XfrmInStateSeqError", want: 6000, got: xfrmStats.XfrmInStateSeqError}, 38 | {name: "XfrmInStateExpired", want: 4, got: xfrmStats.XfrmInStateExpired}, 39 | {name: "XfrmInStateMismatch", want: 23451, got: xfrmStats.XfrmInStateMismatch}, 40 | {name: "XfrmInStateInvalid", want: 55555, got: xfrmStats.XfrmInStateInvalid}, 41 | {name: "XfrmInTmplMismatch", want: 51, got: xfrmStats.XfrmInTmplMismatch}, 42 | {name: "XfrmInNoPols", want: 65432, got: xfrmStats.XfrmInNoPols}, 43 | {name: "XfrmInPolBlock", want: 100, got: xfrmStats.XfrmInPolBlock}, 44 | {name: "XfrmInPolError", want: 10000, got: xfrmStats.XfrmInPolError}, 45 | {name: "XfrmOutError", want: 1000000, got: xfrmStats.XfrmOutError}, 46 | {name: "XfrmOutBundleGenError", want: 43321, got: xfrmStats.XfrmOutBundleGenError}, 47 | {name: "XfrmOutBundleCheckError", want: 555, got: xfrmStats.XfrmOutBundleCheckError}, 48 | {name: "XfrmOutNoStates", want: 869, got: xfrmStats.XfrmOutNoStates}, 49 | {name: "XfrmOutStateProtoError", want: 4542, got: xfrmStats.XfrmOutStateProtoError}, 50 | {name: "XfrmOutStateModeError", want: 4, got: xfrmStats.XfrmOutStateModeError}, 51 | {name: "XfrmOutStateSeqError", want: 543, got: xfrmStats.XfrmOutStateSeqError}, 52 | {name: "XfrmOutStateExpired", want: 565, got: xfrmStats.XfrmOutStateExpired}, 53 | {name: "XfrmOutPolBlock", want: 43456, got: xfrmStats.XfrmOutPolBlock}, 54 | {name: "XfrmOutPolDead", want: 7656, got: xfrmStats.XfrmOutPolDead}, 55 | {name: "XfrmOutPolError", want: 1454, got: xfrmStats.XfrmOutPolError}, 56 | {name: "XfrmFwdHdrError", want: 6654, got: xfrmStats.XfrmFwdHdrError}, 57 | {name: "XfrmOutStateInvaliad", want: 28765, got: xfrmStats.XfrmOutStateInvalid}, 58 | {name: "XfrmAcquireError", want: 24532, got: xfrmStats.XfrmAcquireError}, 59 | {name: "XfrmInStateInvalid", want: 55555, got: xfrmStats.XfrmInStateInvalid}, 60 | {name: "XfrmOutError", want: 1000000, got: xfrmStats.XfrmOutError}, 61 | } { 62 | if test.want != test.got { 63 | t.Errorf("Want %s %d, have %d", test.name, test.want, test.got) 64 | } 65 | } 66 | } 67 | --------------------------------------------------------------------------------