diff --git a/.circleci/config.yml b/.circleci/config.yml index 1960bbafba..f9922b4e02 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,22 +35,14 @@ jobs: - run: make format - run: name: "Run all tests" - # TODO(bplotka): Setup some S3 tests for CI. + # TODO(bwplotka): Setup some S3 tests for CI. + # taskset sets CPU affinity to 2 (current CPU limit). command: | if [ -z ${GCP_PROJECT} ]; then - export THANOS_SKIP_GCS_TESTS="true" - echo "Skipping GCS tests." + taskset 2 make test-local + exit fi - export THANOS_SKIP_S3_AWS_TESTS="true" - echo "Skipping AWS tests." - export THANOS_SKIP_AZURE_TESTS="true" - echo "Skipping Azure tests." - export THANOS_SKIP_SWIFT_TESTS="true" - echo "Skipping SWIFT tests." - export THANOS_SKIP_TENCENT_COS_TESTS="true" - echo "Skipping TENCENT COS tests." - - make test + taskset 2 make test-only-gcs # Cross build is needed for publish_release but needs to be done outside of docker. cross_build: diff --git a/Makefile b/Makefile index af44bef969..851f3a5af5 100644 --- a/Makefile +++ b/Makefile @@ -177,9 +177,12 @@ tarballs-release: $(PROMU) # test runs all Thanos golang tests against each supported version of Prometheus. .PHONY: test +test: export GOCACHE= $(TMP_GOPATH)/gocache test: check-git test-deps + # Be careful on GOCACHE. Those tests are sometimes using built Thanos/Prometheus binaries directly. Don't cache those. + @rm -rf ${GOCACHE} @echo ">> running all tests. Do export THANOS_SKIP_GCS_TESTS='true' or/and THANOS_SKIP_S3_AWS_TESTS='true' or/and THANOS_SKIP_AZURE_TESTS='true' and/or THANOS_SKIP_SWIFT_TESTS='true' and/or THANOS_SKIP_TENCENT_COS_TESTS='true' if you want to skip e2e tests against real store buckets" - THANOS_TEST_PROMETHEUS_VERSIONS="$(PROM_VERSIONS)" THANOS_TEST_ALERTMANAGER_PATH="alertmanager-$(ALERTMANAGER_VERSION)" go test $(shell go list ./... | grep -v /vendor/ | grep -v /benchmark/); + THANOS_TEST_PROMETHEUS_VERSIONS="$(PROM_VERSIONS)" THANOS_TEST_ALERTMANAGER_PATH="alertmanager-$(ALERTMANAGER_VERSION)" go test $(shell go list ./... | grep -v /vendor/); .PHONY: test-only-gcs test-only-gcs: export THANOS_SKIP_S3_AWS_TESTS = true @@ -203,6 +206,7 @@ test-local: # It installs current Thanos, supported versions of Prometheus and alertmanager to test against in e2e. .PHONY: test-deps test-deps: + @echo ">> install thanos GOOPTS=${GOOPTS}" @go install github.com/thanos-io/thanos/cmd/thanos $(foreach ver,$(PROM_VERSIONS),$(call fetch_go_bin_version,github.com/prometheus/prometheus/cmd/prometheus,$(ver))) $(call fetch_go_bin_version,github.com/prometheus/alertmanager/cmd/alertmanager,$(ALERTMANAGER_VERSION)) @@ -217,7 +221,6 @@ else @echo >&2 "No git binary found."; exit 1 endif - .PHONY: web-pre-process web-pre-process: @echo ">> running documentation website pre processing" @@ -237,8 +240,8 @@ web: web-pre-process $(HUGO) # # to debug big allocations during linting. lint: check-git $(GOLANGCILINT) $(MISSPELL) - @echo ">> linting all of the Go files" - @$(GOLANGCILINT) run -v --enable goimports --enable goconst --skip-dirs vendor + @echo ">> linting all of the Go files GOGC=${GOGC}" + @$(GOLANGCILINT) run --enable goimports --enable goconst --skip-dirs vendor @echo ">> detecting misspells" @find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index a4e01e0e63..1717bbd67e 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -399,8 +399,7 @@ func runQuery( } ins := extpromhttp.NewInstrumentationMiddleware(reg) - - ui.NewQueryUI(logger, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) + ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling, enablePartialResponse) diff --git a/cmd/thanos/rule.go b/cmd/thanos/rule.go index b6ac6d1b76..6226ca4479 100644 --- a/cmd/thanos/rule.go +++ b/cmd/thanos/rule.go @@ -529,9 +529,9 @@ func runRule( ins := extpromhttp.NewInstrumentationMiddleware(reg) - ui.NewRuleUI(logger, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) + ui.NewRuleUI(logger, reg, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) - api := v1.NewAPI(logger, ruleMgrs) + api := v1.NewAPI(logger, reg, ruleMgrs) api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins) mux := http.NewServeMux() diff --git a/go.mod b/go.mod index e4409028ff..3f8453cd82 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.1.0 github.com/prometheus/common v0.6.0 - github.com/prometheus/prometheus v0.0.0-20190814090039-b5c833ca2194 + github.com/prometheus/prometheus v1.8.2-0.20190819201610-48b2c9c8eae2 // v1.8.2 is misleading as Prometheus does not have v2 module. This is pointing to one commit after 2.12.0. github.com/uber-go/atomic v1.4.0 // indirect github.com/uber/jaeger-client-go v2.16.0+incompatible github.com/uber/jaeger-lib v2.0.0+incompatible diff --git a/go.sum b/go.sum index 66a71e6670..d06f5f1464 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,7 @@ github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQh github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/aws/aws-sdk-go v1.22.4 h1:Mcq67g9mZEBvBuj/x7mF9KCyw5M8/4I/cjQPkdCsq0I= github.com/aws/aws-sdk-go v1.22.4/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -76,6 +77,7 @@ github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M= github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structtag v1.0.0 h1:pTHj65+u3RKWYPSGaU290FpI/dXxTaHdVwVwbcPKmEc= @@ -150,6 +152,7 @@ github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -164,6 +167,7 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/btree v0.0.0-20160524151835-7d79101e329e/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -172,7 +176,9 @@ github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -188,6 +194,7 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0= github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/gophercloud/gophercloud v0.0.0-20190126172459-c818fa66e4c8/go.mod h1:3WdhXV3rUYy9p6AUW8d94kr+HS62Y4VL9mBnFxsD8q4= github.com/gophercloud/gophercloud v0.3.0 h1:6sjpKIpVwRIIwmcEGp+WwNovNsem+c+2vm6oxshRpL8= @@ -202,8 +209,11 @@ github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117/ github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0 h1:BNQPM9ytxj6jbjjdRPioQ94T6YXriSopn0i8COv6SRA= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1 h1:LnuDWGNsoajlhGyHJvuWW6FVqRl8JOTPqS6CPTsYjhY= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= @@ -213,12 +223,17 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh github.com/hashicorp/go-immutable-radix v1.1.0 h1:vN9wG1D6KG6YHRTWr8512cxGOVgTMEfgEdSj/hr8MPc= github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-rootcerts v1.0.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8= github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc= github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -232,20 +247,27 @@ github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8 github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3 h1:EmmoJme1matNzb+hMpDuR/0sbJSUisxyqBGG676r31M= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/memberlist v0.1.4 h1:gkyML/r71w3FL8gUi74Vk76avkj/9lYAY9lvg0OcoGs= github.com/hashicorp/memberlist v0.1.4/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2 h1:YZ7UKsJv+hKjqGVUUbtE3HNj79Eln2oQ75tniF6iPt0= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hashicorp/serf v0.8.3 h1:MWYcmct5EtKz0efYooPcL0yNkem+7kWxqXDi/UIh+8k= github.com/hashicorp/serf v0.8.3/go.mod h1:UpNcs7fFbpKIyZaUuSW6EPiH+eZC7OuyFD+wc1oal+k= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/influxdata/influxdb v1.7.7/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7 h1:K//n/AqR5HjG3qxbrBCL4vJPW0MVFSs9CPK1OOJdRME= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -291,6 +313,7 @@ github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceT github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -302,6 +325,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mozillazg/go-cos v0.12.0 h1:b9hUd5HjrDe10BUfkyiLYI1+z4M2kAgKasktszx9pO4= github.com/mozillazg/go-cos v0.12.0/go.mod h1:Zp6DvvXn0RUOXGJ2chmWt2bLEqRAnJnS3DnAZsJsoaE= @@ -319,7 +343,9 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3 h1:EooPXg51Tn+xmWPXJUGCnJhJSpeuMlBmfJVcqIRmmv8= github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9 h1:QsgXACQhd9QJhEmRumbsMQQvBtmdS0mafoVEBplWXEg= github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w= @@ -352,6 +378,7 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= @@ -362,14 +389,16 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/prometheus v0.0.0-20180315085919-58e2a31db8de/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= -github.com/prometheus/prometheus v0.0.0-20190814090039-b5c833ca2194 h1:LrsaiNAHOgGoqZESBAxbK33LlBVlSku6AZPOhaU6/GI= -github.com/prometheus/prometheus v0.0.0-20190814090039-b5c833ca2194/go.mod h1:rMTlmxGCvukf2KMu3fClMDKLLoJ5hl61MhcJ7xKakf0= +github.com/prometheus/prometheus v1.8.2-0.20190819201610-48b2c9c8eae2 h1:yZAWzfQYJN+vduRHL5jcTrVw+XwYU52ZrAhprmwoknI= +github.com/prometheus/prometheus v1.8.2-0.20190819201610-48b2c9c8eae2/go.mod h1:rMTlmxGCvukf2KMu3fClMDKLLoJ5hl61MhcJ7xKakf0= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75 h1:cA+Ubq9qEVIQhIWvP2kNuSZ2CmnfBJFSRq+kO1pu2cc= github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/satori/go.uuid v0.0.0-20160603004225-b111a074d5ef/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= @@ -387,6 +416,7 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -452,7 +482,6 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -497,12 +526,14 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180805044716-cb6730876b98/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20161028155119-f51c12702a4d/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -563,6 +594,7 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= @@ -573,10 +605,15 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/api v0.0.0-20190620084959-7cf5895f2711 h1:BblVYz/wE5WtBsD/Gvu54KyBUTJMflolzc5I2DTvh50= k8s.io/api v0.0.0-20190620084959-7cf5895f2711/go.mod h1:TBhBqb1AWbBQbW3XRusr7n7E4v2+5ZY8r8sAMnyFC5A= +k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719 h1:uV4S5IB5g4Nvi+TBVNf3e9L4wrirlwYJ6w88jUQxTUw= k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719/go.mod h1:I4A+glKBHiTgiEjQiCCQfCAIcIMFGt291SmsvcrFzJA= +k8s.io/client-go v0.0.0-20190620085101-78d2af792bab h1:E8Fecph0qbNsAbijJJQryKu4Oi9QTp5cVpjTE+nqg6g= k8s.io/client-go v0.0.0-20190620085101-78d2af792bab/go.mod h1:E95RaSlHr79aHaX0aGSwcPNfygDiPKOVXdmivCIZT0k= +k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68= k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30 h1:TRb4wNWoBVrH9plmkp2q86FIDppkbrEXdXlxU3a3BMI= k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc= k8s.io/utils v0.0.0-20190221042446-c2654d5206da/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= k8s.io/utils v0.0.0-20190809000727-6c36bc71fc4a h1:uy5HAgt4Ha5rEMbhZA+aM1j2cq5LmR6LQ71EYC2sVH4= diff --git a/pkg/promclient/promclient_e2e_test.go b/pkg/promclient/promclient_e2e_test.go index a88a134e7c..a92d76ca53 100644 --- a/pkg/promclient/promclient_e2e_test.go +++ b/pkg/promclient/promclient_e2e_test.go @@ -22,7 +22,6 @@ import ( func TestIsWALFileAccesible_e2e(t *testing.T) { testutil.ForeachPrometheus(t, func(t testing.TB, p *testutil.Prometheus) { testutil.Ok(t, p.Start()) - defer func() { testutil.Ok(t, p.Stop()) }() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() @@ -43,7 +42,6 @@ global: `)) testutil.Ok(t, p.Start()) - defer func() { testutil.Ok(t, p.Stop()) }() u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr())) testutil.Ok(t, err) @@ -60,7 +58,6 @@ global: func TestConfiguredFlags_e2e(t *testing.T) { testutil.ForeachPrometheus(t, func(t testing.TB, p *testutil.Prometheus) { testutil.Ok(t, p.Start()) - defer func() { testutil.Ok(t, p.Stop()) }() u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr())) testutil.Ok(t, err) @@ -96,7 +93,6 @@ func TestSnapshot_e2e(t *testing.T) { testutil.Ok(t, err) testutil.Ok(t, p.Start()) - defer func() { testutil.Ok(t, p.Stop()) }() u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr())) testutil.Ok(t, err) diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index ad897a7333..f51706b501 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -104,7 +104,9 @@ type API struct { rangeQueryDuration prometheus.Histogram enableAutodownsampling bool enablePartialResponse bool - now func() time.Time + reg prometheus.Registerer + + now func() time.Time } // NewAPI returns an initialized API type. @@ -143,6 +145,7 @@ func NewAPI( rangeQueryDuration: rangeQueryDuration, enableAutodownsampling: enableAutodownsampling, enablePartialResponse: enablePartialResponse, + reg: reg, now: time.Now, } diff --git a/pkg/receive/config.go b/pkg/receive/config.go index 2a6c6d2686..60733f6107 100644 --- a/pkg/receive/config.go +++ b/pkg/receive/config.go @@ -21,8 +21,8 @@ import ( // HashringConfig represents the configuration for a hashring // a receive node knows about. type HashringConfig struct { - Hashring string `json:"hashring"` - Tenants []string `json:"tenants"` + Hashring string `json:"hashring,omitempty"` + Tenants []string `json:"tenants,omitempty"` Endpoints []string `json:"endpoints"` } @@ -231,6 +231,7 @@ func (cw *ConfigWatcher) refresh(ctx context.Context) { cw.hashringTenantsGauge.WithLabelValues(c.Hashring).Set(float64(len(c.Tenants))) } + level.Debug(cw.logger).Log("msg", "refreshed hashring config") select { case <-ctx.Done(): return diff --git a/pkg/receive/handler.go b/pkg/receive/handler.go index 82385f8855..50e7499b46 100644 --- a/pkg/receive/handler.go +++ b/pkg/receive/handler.go @@ -23,10 +23,10 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/route" + "github.com/prometheus/prometheus/prompb" promtsdb "github.com/prometheus/prometheus/storage/tsdb" terrors "github.com/prometheus/prometheus/tsdb/errors" "github.com/thanos-io/thanos/pkg/runutil" - "github.com/thanos-io/thanos/pkg/store/prompb" ) // Options for the web Handler. diff --git a/pkg/receive/hashring.go b/pkg/receive/hashring.go index a2b4781330..1998bad08b 100644 --- a/pkg/receive/hashring.go +++ b/pkg/receive/hashring.go @@ -7,7 +7,7 @@ import ( "sort" "sync" - "github.com/thanos-io/thanos/pkg/store/prompb" + "github.com/prometheus/prometheus/prompb" "github.com/cespare/xxhash" ) diff --git a/pkg/receive/hashring_test.go b/pkg/receive/hashring_test.go index 44fd621c3b..c16334a24e 100644 --- a/pkg/receive/hashring_test.go +++ b/pkg/receive/hashring_test.go @@ -3,7 +3,7 @@ package receive import ( "testing" - "github.com/thanos-io/thanos/pkg/store/prompb" + "github.com/prometheus/prometheus/prompb" ) func TestHash(t *testing.T) { diff --git a/pkg/receive/writer.go b/pkg/receive/writer.go index d3f14216cf..a545d712bd 100644 --- a/pkg/receive/writer.go +++ b/pkg/receive/writer.go @@ -3,7 +3,7 @@ package receive import ( "github.com/go-kit/kit/log" "github.com/pkg/errors" - "github.com/thanos-io/thanos/pkg/store/prompb" + "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/storage" diff --git a/pkg/reloader/reloader_test.go b/pkg/reloader/reloader_test.go index 95975ad73a..fb6ede8cee 100644 --- a/pkg/reloader/reloader_test.go +++ b/pkg/reloader/reloader_test.go @@ -211,7 +211,7 @@ func TestReloader_RuleApply(t *testing.T) { testutil.Ok(t, ioutil.WriteFile(path.Join(dir2, "rule3-source.yaml"), []byte("rule3"), os.ModePerm)) testutil.Ok(t, ioutil.WriteFile(path.Join(dir2, "rule-dir", "rule4.yaml"), []byte("rule4"), os.ModePerm)) - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) g := sync.WaitGroup{} g.Add(1) go func() { diff --git a/pkg/rule/api/v1.go b/pkg/rule/api/v1.go index b9eb84ddc0..9b6d41a030 100644 --- a/pkg/rule/api/v1.go +++ b/pkg/rule/api/v1.go @@ -6,6 +6,8 @@ import ( "time" "github.com/NYTimes/gziphandler" + "github.com/prometheus/client_golang/prometheus" + "github.com/go-kit/kit/log" opentracing "github.com/opentracing/opentracing-go" "github.com/prometheus/common/route" @@ -22,16 +24,19 @@ type API struct { logger log.Logger now func() time.Time ruleRetriever RulesRetriever + reg prometheus.Registerer } func NewAPI( logger log.Logger, + reg prometheus.Registerer, ruleRetriever RulesRetriever, ) *API { return &API{ logger: logger, now: time.Now, ruleRetriever: ruleRetriever, + reg: reg, } } diff --git a/pkg/rule/api/v1_test.go b/pkg/rule/api/v1_test.go index 3417e61157..5c281a1efa 100644 --- a/pkg/rule/api/v1_test.go +++ b/pkg/rule/api/v1_test.go @@ -12,15 +12,15 @@ import ( "testing" "time" - "github.com/prometheus/common/model" - "github.com/prometheus/prometheus/storage" - "github.com/prometheus/prometheus/storage/tsdb" - "github.com/go-kit/kit/log" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/model" "github.com/prometheus/common/route" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/rules" + "github.com/prometheus/prometheus/storage" + "github.com/prometheus/prometheus/storage/tsdb" qapi "github.com/thanos-io/thanos/pkg/query/api" thanosrule "github.com/thanos-io/thanos/pkg/rule" ) @@ -164,6 +164,7 @@ func TestEndpoints(t *testing.T) { algr.RuleGroups() api := NewAPI( nil, + prometheus.DefaultRegisterer, algr, ) testEndpoints(t, api) diff --git a/pkg/rule/rule.go b/pkg/rule/rule.go index 966b2fa456..5156d24d91 100644 --- a/pkg/rule/rule.go +++ b/pkg/rule/rule.go @@ -175,6 +175,7 @@ func (m *Managers) Update(dataDir string, evalInterval time.Duration, files []st continue } // We add external labels in `pkg/alert.Queue`. + // TODO(bwplotka): Investigate if we should put ext labels here or not. if err := updater.Update(evalInterval, fs, nil); err != nil { errs = append(errs, err) continue diff --git a/pkg/store/bucket_test.go b/pkg/store/bucket_test.go index a57b7d01d8..894a3c5594 100644 --- a/pkg/store/bucket_test.go +++ b/pkg/store/bucket_test.go @@ -413,7 +413,7 @@ func TestBucketStore_Info(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - dir, err := ioutil.TempDir("", "prometheus-test") + dir, err := ioutil.TempDir("", "bucketstore-test") testutil.Ok(t, err) bucketStore, err := NewBucketStore(nil, nil, nil, dir, noopCache{}, 2e5, 0, 0, false, 20) diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index 201417e9c0..58313033ba 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -19,11 +19,11 @@ import ( "github.com/gogo/protobuf/proto" "github.com/golang/snappy" "github.com/pkg/errors" + "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/tsdb/chunkenc" "github.com/prometheus/prometheus/tsdb/labels" "github.com/thanos-io/thanos/pkg/component" "github.com/thanos-io/thanos/pkg/runutil" - "github.com/thanos-io/thanos/pkg/store/prompb" "github.com/thanos-io/thanos/pkg/store/storepb" "github.com/thanos-io/thanos/pkg/tracing" "google.golang.org/grpc/codes" @@ -140,12 +140,12 @@ func (p *PrometheusStore) Series(r *storepb.SeriesRequest, s storepb.Store_Serie return status.Error(codes.InvalidArgument, errors.New("no matchers specified (excluding external labels)").Error()) } - q := prompb.Query{StartTimestampMs: r.MinTime, EndTimestampMs: r.MaxTime} + q := &prompb.Query{StartTimestampMs: r.MinTime, EndTimestampMs: r.MaxTime} // TODO(fabxc): import common definitions from prompb once we have a stable gRPC // query API there. for _, m := range newMatchers { - pm := prompb.LabelMatcher{Name: m.Name, Value: m.Value} + pm := &prompb.LabelMatcher{Name: m.Name, Value: m.Value} switch m.Type { case storepb.LabelMatcher_EQ: @@ -206,7 +206,7 @@ func (p *PrometheusStore) Series(r *storepb.SeriesRequest, s storepb.Store_Serie return nil } -func (p *PrometheusStore) chunkSamples(series prompb.TimeSeries, maxSamplesPerChunk int) (chks []storepb.AggrChunk, err error) { +func (p *PrometheusStore) chunkSamples(series *prompb.TimeSeries, maxSamplesPerChunk int) (chks []storepb.AggrChunk, err error) { samples := series.Samples for len(samples) > 0 { @@ -232,11 +232,11 @@ func (p *PrometheusStore) chunkSamples(series prompb.TimeSeries, maxSamplesPerCh return chks, nil } -func (p *PrometheusStore) promSeries(ctx context.Context, q prompb.Query) (*prompb.ReadResponse, error) { +func (p *PrometheusStore) promSeries(ctx context.Context, q *prompb.Query) (*prompb.ReadResponse, error) { span, ctx := tracing.StartSpan(ctx, "query_prometheus") defer span.Finish() - reqb, err := proto.Marshal(&prompb.ReadRequest{Queries: []prompb.Query{q}}) + reqb, err := proto.Marshal(&prompb.ReadRequest{Queries: []*prompb.Query{q}}) if err != nil { return nil, errors.Wrap(err, "marshal read request") } diff --git a/pkg/store/prompb/remote.pb.go b/pkg/store/prompb/remote.pb.go deleted file mode 100644 index 26b2b8061b..0000000000 --- a/pkg/store/prompb/remote.pb.go +++ /dev/null @@ -1,2436 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: remote.proto - -package prompb - -import ( - encoding_binary "encoding/binary" - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -type LabelMatcher_Type int32 - -const ( - LabelMatcher_EQ LabelMatcher_Type = 0 - LabelMatcher_NEQ LabelMatcher_Type = 1 - LabelMatcher_RE LabelMatcher_Type = 2 - LabelMatcher_NRE LabelMatcher_Type = 3 -) - -var LabelMatcher_Type_name = map[int32]string{ - 0: "EQ", - 1: "NEQ", - 2: "RE", - 3: "NRE", -} - -var LabelMatcher_Type_value = map[string]int32{ - "EQ": 0, - "NEQ": 1, - "RE": 2, - "NRE": 3, -} - -func (x LabelMatcher_Type) String() string { - return proto.EnumName(LabelMatcher_Type_name, int32(x)) -} - -func (LabelMatcher_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{8, 0} -} - -type WriteRequest struct { - Timeseries []TimeSeries `protobuf:"bytes,1,rep,name=timeseries,proto3" json:"timeseries"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *WriteRequest) Reset() { *m = WriteRequest{} } -func (m *WriteRequest) String() string { return proto.CompactTextString(m) } -func (*WriteRequest) ProtoMessage() {} -func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{0} -} -func (m *WriteRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *WriteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_WriteRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *WriteRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_WriteRequest.Merge(m, src) -} -func (m *WriteRequest) XXX_Size() int { - return m.Size() -} -func (m *WriteRequest) XXX_DiscardUnknown() { - xxx_messageInfo_WriteRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_WriteRequest proto.InternalMessageInfo - -type ReadRequest struct { - Queries []Query `protobuf:"bytes,1,rep,name=queries,proto3" json:"queries"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ReadRequest) Reset() { *m = ReadRequest{} } -func (m *ReadRequest) String() string { return proto.CompactTextString(m) } -func (*ReadRequest) ProtoMessage() {} -func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{1} -} -func (m *ReadRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ReadRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReadRequest.Merge(m, src) -} -func (m *ReadRequest) XXX_Size() int { - return m.Size() -} -func (m *ReadRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ReadRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ReadRequest proto.InternalMessageInfo - -type ReadResponse struct { - // In same order as the request's queries. - Results []QueryResult `protobuf:"bytes,1,rep,name=results,proto3" json:"results"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ReadResponse) Reset() { *m = ReadResponse{} } -func (m *ReadResponse) String() string { return proto.CompactTextString(m) } -func (*ReadResponse) ProtoMessage() {} -func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{2} -} -func (m *ReadResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ReadResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReadResponse.Merge(m, src) -} -func (m *ReadResponse) XXX_Size() int { - return m.Size() -} -func (m *ReadResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ReadResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ReadResponse proto.InternalMessageInfo - -type Query struct { - StartTimestampMs int64 `protobuf:"varint,1,opt,name=start_timestamp_ms,json=startTimestampMs,proto3" json:"start_timestamp_ms,omitempty"` - EndTimestampMs int64 `protobuf:"varint,2,opt,name=end_timestamp_ms,json=endTimestampMs,proto3" json:"end_timestamp_ms,omitempty"` - Matchers []LabelMatcher `protobuf:"bytes,3,rep,name=matchers,proto3" json:"matchers"` - Hints *ReadHints `protobuf:"bytes,4,opt,name=hints,proto3" json:"hints,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Query) Reset() { *m = Query{} } -func (m *Query) String() string { return proto.CompactTextString(m) } -func (*Query) ProtoMessage() {} -func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{3} -} -func (m *Query) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Query) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Query.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Query) XXX_Merge(src proto.Message) { - xxx_messageInfo_Query.Merge(m, src) -} -func (m *Query) XXX_Size() int { - return m.Size() -} -func (m *Query) XXX_DiscardUnknown() { - xxx_messageInfo_Query.DiscardUnknown(m) -} - -var xxx_messageInfo_Query proto.InternalMessageInfo - -type QueryResult struct { - Timeseries []TimeSeries `protobuf:"bytes,1,rep,name=timeseries,proto3" json:"timeseries"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *QueryResult) Reset() { *m = QueryResult{} } -func (m *QueryResult) String() string { return proto.CompactTextString(m) } -func (*QueryResult) ProtoMessage() {} -func (*QueryResult) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{4} -} -func (m *QueryResult) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryResult.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryResult) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryResult.Merge(m, src) -} -func (m *QueryResult) XXX_Size() int { - return m.Size() -} -func (m *QueryResult) XXX_DiscardUnknown() { - xxx_messageInfo_QueryResult.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryResult proto.InternalMessageInfo - -type Sample struct { - Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"` - Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Sample) Reset() { *m = Sample{} } -func (m *Sample) String() string { return proto.CompactTextString(m) } -func (*Sample) ProtoMessage() {} -func (*Sample) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{5} -} -func (m *Sample) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Sample) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Sample.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Sample) XXX_Merge(src proto.Message) { - xxx_messageInfo_Sample.Merge(m, src) -} -func (m *Sample) XXX_Size() int { - return m.Size() -} -func (m *Sample) XXX_DiscardUnknown() { - xxx_messageInfo_Sample.DiscardUnknown(m) -} - -var xxx_messageInfo_Sample proto.InternalMessageInfo - -type TimeSeries struct { - Labels []Label `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels"` - Samples []Sample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *TimeSeries) Reset() { *m = TimeSeries{} } -func (m *TimeSeries) String() string { return proto.CompactTextString(m) } -func (*TimeSeries) ProtoMessage() {} -func (*TimeSeries) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{6} -} -func (m *TimeSeries) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *TimeSeries) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_TimeSeries.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *TimeSeries) XXX_Merge(src proto.Message) { - xxx_messageInfo_TimeSeries.Merge(m, src) -} -func (m *TimeSeries) XXX_Size() int { - return m.Size() -} -func (m *TimeSeries) XXX_DiscardUnknown() { - xxx_messageInfo_TimeSeries.DiscardUnknown(m) -} - -var xxx_messageInfo_TimeSeries proto.InternalMessageInfo - -type Label struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Label) Reset() { *m = Label{} } -func (m *Label) String() string { return proto.CompactTextString(m) } -func (*Label) ProtoMessage() {} -func (*Label) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{7} -} -func (m *Label) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Label) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Label.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Label) XXX_Merge(src proto.Message) { - xxx_messageInfo_Label.Merge(m, src) -} -func (m *Label) XXX_Size() int { - return m.Size() -} -func (m *Label) XXX_DiscardUnknown() { - xxx_messageInfo_Label.DiscardUnknown(m) -} - -var xxx_messageInfo_Label proto.InternalMessageInfo - -// Matcher specifies a rule, which can match or set of labels or not. -type LabelMatcher struct { - Type LabelMatcher_Type `protobuf:"varint,1,opt,name=type,proto3,enum=prometheus.LabelMatcher_Type" json:"type,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LabelMatcher) Reset() { *m = LabelMatcher{} } -func (m *LabelMatcher) String() string { return proto.CompactTextString(m) } -func (*LabelMatcher) ProtoMessage() {} -func (*LabelMatcher) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{8} -} -func (m *LabelMatcher) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LabelMatcher) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LabelMatcher.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LabelMatcher) XXX_Merge(src proto.Message) { - xxx_messageInfo_LabelMatcher.Merge(m, src) -} -func (m *LabelMatcher) XXX_Size() int { - return m.Size() -} -func (m *LabelMatcher) XXX_DiscardUnknown() { - xxx_messageInfo_LabelMatcher.DiscardUnknown(m) -} - -var xxx_messageInfo_LabelMatcher proto.InternalMessageInfo - -type ReadHints struct { - StepMs int64 `protobuf:"varint,1,opt,name=step_ms,json=stepMs,proto3" json:"step_ms,omitempty"` - Func string `protobuf:"bytes,2,opt,name=func,proto3" json:"func,omitempty"` - StartMs int64 `protobuf:"varint,3,opt,name=start_ms,json=startMs,proto3" json:"start_ms,omitempty"` - EndMs int64 `protobuf:"varint,4,opt,name=end_ms,json=endMs,proto3" json:"end_ms,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ReadHints) Reset() { *m = ReadHints{} } -func (m *ReadHints) String() string { return proto.CompactTextString(m) } -func (*ReadHints) ProtoMessage() {} -func (*ReadHints) Descriptor() ([]byte, []int) { - return fileDescriptor_eefc82927d57d89b, []int{9} -} -func (m *ReadHints) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ReadHints) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ReadHints.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ReadHints) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReadHints.Merge(m, src) -} -func (m *ReadHints) XXX_Size() int { - return m.Size() -} -func (m *ReadHints) XXX_DiscardUnknown() { - xxx_messageInfo_ReadHints.DiscardUnknown(m) -} - -var xxx_messageInfo_ReadHints proto.InternalMessageInfo - -func init() { - proto.RegisterEnum("prometheus.LabelMatcher_Type", LabelMatcher_Type_name, LabelMatcher_Type_value) - proto.RegisterType((*WriteRequest)(nil), "prometheus.WriteRequest") - proto.RegisterType((*ReadRequest)(nil), "prometheus.ReadRequest") - proto.RegisterType((*ReadResponse)(nil), "prometheus.ReadResponse") - proto.RegisterType((*Query)(nil), "prometheus.Query") - proto.RegisterType((*QueryResult)(nil), "prometheus.QueryResult") - proto.RegisterType((*Sample)(nil), "prometheus.Sample") - proto.RegisterType((*TimeSeries)(nil), "prometheus.TimeSeries") - proto.RegisterType((*Label)(nil), "prometheus.Label") - proto.RegisterType((*LabelMatcher)(nil), "prometheus.LabelMatcher") - proto.RegisterType((*ReadHints)(nil), "prometheus.ReadHints") -} - -func init() { proto.RegisterFile("remote.proto", fileDescriptor_eefc82927d57d89b) } - -var fileDescriptor_eefc82927d57d89b = []byte{ - // 535 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0x51, 0x8b, 0xd3, 0x40, - 0x10, 0xbe, 0x34, 0x6d, 0x72, 0x9d, 0x96, 0x23, 0x0e, 0x77, 0x5e, 0x15, 0xad, 0x47, 0x9e, 0x0a, - 0x4a, 0x8f, 0xd6, 0x07, 0x41, 0xee, 0x41, 0x0e, 0x8a, 0x82, 0x57, 0xa1, 0x7b, 0x05, 0xc1, 0x97, - 0x23, 0xbd, 0x8e, 0xd7, 0x4a, 0x36, 0x49, 0xb3, 0x1b, 0xa1, 0x3f, 0xc4, 0xff, 0xd4, 0x47, 0x7f, - 0x81, 0x68, 0x7f, 0x89, 0xec, 0x6e, 0xd2, 0xae, 0x78, 0x3e, 0xf9, 0x96, 0x99, 0xf9, 0xe6, 0x9b, - 0xef, 0xdb, 0x99, 0x40, 0x3b, 0x27, 0x9e, 0x4a, 0xea, 0x67, 0x79, 0x2a, 0x53, 0x84, 0x2c, 0x4f, - 0x39, 0xc9, 0x05, 0x15, 0xe2, 0xf1, 0xf1, 0x5d, 0x7a, 0x97, 0xea, 0xf4, 0xb9, 0xfa, 0x32, 0x88, - 0xf0, 0x0a, 0xda, 0x1f, 0xf3, 0xa5, 0x24, 0x46, 0xab, 0x82, 0x84, 0xc4, 0x0b, 0x00, 0xb9, 0xe4, - 0x24, 0x28, 0x5f, 0x92, 0xe8, 0x38, 0x67, 0x6e, 0xaf, 0x35, 0x7c, 0xd8, 0xdf, 0xd3, 0xf4, 0xa7, - 0x4b, 0x4e, 0xd7, 0xba, 0x7a, 0x59, 0xdf, 0xfc, 0x78, 0x76, 0xc0, 0x2c, 0x7c, 0xf8, 0x06, 0x5a, - 0x8c, 0xa2, 0x79, 0x45, 0x36, 0x00, 0x7f, 0x55, 0xd8, 0x4c, 0x0f, 0x6c, 0xa6, 0x49, 0x41, 0xf9, - 0xba, 0x24, 0xa9, 0x70, 0xe1, 0x5b, 0x68, 0x1b, 0x06, 0x91, 0xa5, 0x89, 0x20, 0x7c, 0x05, 0x7e, - 0x4e, 0xa2, 0x88, 0x65, 0x45, 0x71, 0xfa, 0x17, 0x05, 0xd3, 0xf5, 0x8a, 0xa8, 0x44, 0x87, 0x1b, - 0x07, 0x1a, 0xba, 0x8c, 0x2f, 0x00, 0x85, 0x8c, 0x72, 0x79, 0xa3, 0x85, 0xca, 0x88, 0x67, 0x37, - 0x5c, 0xb1, 0x39, 0x3d, 0x97, 0x05, 0xba, 0x32, 0xad, 0x0a, 0x63, 0x81, 0x3d, 0x08, 0x28, 0x99, - 0xff, 0x89, 0xad, 0x69, 0xec, 0x11, 0x25, 0x73, 0x1b, 0xf9, 0x1a, 0x0e, 0x79, 0x24, 0x6f, 0x17, - 0x94, 0x8b, 0x8e, 0xab, 0xb5, 0x75, 0x6c, 0x6d, 0x57, 0xd1, 0x8c, 0xe2, 0xb1, 0x01, 0x94, 0xe2, - 0x76, 0x78, 0x7c, 0x0e, 0x8d, 0xc5, 0x32, 0x91, 0xa2, 0x53, 0x3f, 0x73, 0x7a, 0xad, 0xe1, 0x89, - 0xdd, 0xa8, 0xfc, 0xbf, 0x53, 0x45, 0x66, 0x30, 0xe1, 0x7b, 0x68, 0x59, 0x46, 0xff, 0x73, 0x45, - 0x17, 0xe0, 0x5d, 0x47, 0x3c, 0x8b, 0x09, 0x8f, 0xa1, 0xf1, 0x35, 0x8a, 0x0b, 0xd2, 0x4f, 0xe1, - 0x30, 0x13, 0xe0, 0x13, 0x68, 0xee, 0xbc, 0x97, 0xc6, 0xf7, 0x89, 0x70, 0x05, 0xb0, 0x67, 0xc7, - 0x73, 0xf0, 0x62, 0xe5, 0xf2, 0xde, 0xf5, 0x6a, 0xff, 0xa5, 0x80, 0x12, 0x86, 0x43, 0xf0, 0x85, - 0x1e, 0xae, 0xde, 0x54, 0x75, 0xa0, 0xdd, 0x61, 0x74, 0x55, 0x8b, 0x2c, 0x81, 0xe1, 0x00, 0x1a, - 0x9a, 0x0a, 0x11, 0xea, 0x49, 0xc4, 0x8d, 0xdc, 0x26, 0xd3, 0xdf, 0x7b, 0x0f, 0x35, 0x9d, 0x34, - 0x41, 0xf8, 0xcd, 0x81, 0xb6, 0xfd, 0xfc, 0x38, 0x80, 0xba, 0x5c, 0x67, 0xa6, 0xf5, 0x68, 0xf8, - 0xf4, 0x5f, 0x6b, 0xea, 0x4f, 0xd7, 0x19, 0x31, 0x0d, 0xdd, 0x4d, 0xab, 0xdd, 0x37, 0xcd, 0xb5, - 0xa7, 0xf5, 0xa0, 0xae, 0xfa, 0xd0, 0x83, 0xda, 0x68, 0x12, 0x1c, 0xa0, 0x0f, 0xee, 0x87, 0xd1, - 0x24, 0x70, 0x54, 0x82, 0x8d, 0x82, 0x9a, 0x4e, 0xb0, 0x51, 0xe0, 0x86, 0x5f, 0xa0, 0xb9, 0x5b, - 0x2e, 0x9e, 0x82, 0x2f, 0x24, 0x59, 0xb7, 0xe8, 0xa9, 0x70, 0x2c, 0xd4, 0xe4, 0xcf, 0x45, 0x72, - 0x5b, 0x4d, 0x56, 0xdf, 0xf8, 0x08, 0x0e, 0xcd, 0x0d, 0x73, 0xa1, 0x87, 0xbb, 0xcc, 0xd7, 0xf1, - 0x58, 0xe0, 0x09, 0x78, 0xea, 0x60, 0xb9, 0xb9, 0x25, 0x97, 0x35, 0x28, 0x99, 0x8f, 0xc5, 0x65, - 0x67, 0xf3, 0xab, 0x7b, 0xb0, 0xd9, 0x76, 0x9d, 0xef, 0xdb, 0xae, 0xf3, 0x73, 0xdb, 0x75, 0x3e, - 0x79, 0xca, 0x75, 0x36, 0x9b, 0x79, 0xfa, 0xcf, 0x7f, 0xf9, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xe5, - 0xcf, 0xa9, 0xcb, 0x2b, 0x04, 0x00, 0x00, -} - -func (m *WriteRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WriteRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *WriteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Timeseries) > 0 { - for iNdEx := len(m.Timeseries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Timeseries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *ReadRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ReadRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ReadRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Queries) > 0 { - for iNdEx := len(m.Queries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Queries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *ReadResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ReadResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ReadResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Results) > 0 { - for iNdEx := len(m.Results) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Results[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *Query) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Query) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Query) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Hints != nil { - { - size, err := m.Hints.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - if len(m.Matchers) > 0 { - for iNdEx := len(m.Matchers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Matchers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if m.EndTimestampMs != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.EndTimestampMs)) - i-- - dAtA[i] = 0x10 - } - if m.StartTimestampMs != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.StartTimestampMs)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryResult) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryResult) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryResult) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Timeseries) > 0 { - for iNdEx := len(m.Timeseries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Timeseries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *Sample) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Sample) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Sample) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Timestamp != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.Timestamp)) - i-- - dAtA[i] = 0x10 - } - if m.Value != 0 { - i -= 8 - encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.Value)))) - i-- - dAtA[i] = 0x9 - } - return len(dAtA) - i, nil -} - -func (m *TimeSeries) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TimeSeries) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *TimeSeries) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Samples) > 0 { - for iNdEx := len(m.Samples) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Samples[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if len(m.Labels) > 0 { - for iNdEx := len(m.Labels) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Labels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRemote(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *Label) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Label) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Label) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Value) > 0 { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintRemote(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0x12 - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintRemote(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LabelMatcher) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LabelMatcher) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LabelMatcher) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Value) > 0 { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintRemote(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0x1a - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintRemote(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0x12 - } - if m.Type != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ReadHints) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ReadHints) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ReadHints) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.EndMs != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.EndMs)) - i-- - dAtA[i] = 0x20 - } - if m.StartMs != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.StartMs)) - i-- - dAtA[i] = 0x18 - } - if len(m.Func) > 0 { - i -= len(m.Func) - copy(dAtA[i:], m.Func) - i = encodeVarintRemote(dAtA, i, uint64(len(m.Func))) - i-- - dAtA[i] = 0x12 - } - if m.StepMs != 0 { - i = encodeVarintRemote(dAtA, i, uint64(m.StepMs)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintRemote(dAtA []byte, offset int, v uint64) int { - offset -= sovRemote(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *WriteRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Timeseries) > 0 { - for _, e := range m.Timeseries { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ReadRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Queries) > 0 { - for _, e := range m.Queries { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ReadResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Results) > 0 { - for _, e := range m.Results { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Query) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.StartTimestampMs != 0 { - n += 1 + sovRemote(uint64(m.StartTimestampMs)) - } - if m.EndTimestampMs != 0 { - n += 1 + sovRemote(uint64(m.EndTimestampMs)) - } - if len(m.Matchers) > 0 { - for _, e := range m.Matchers { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.Hints != nil { - l = m.Hints.Size() - n += 1 + l + sovRemote(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *QueryResult) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Timeseries) > 0 { - for _, e := range m.Timeseries { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Sample) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Value != 0 { - n += 9 - } - if m.Timestamp != 0 { - n += 1 + sovRemote(uint64(m.Timestamp)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *TimeSeries) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Labels) > 0 { - for _, e := range m.Labels { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if len(m.Samples) > 0 { - for _, e := range m.Samples { - l = e.Size() - n += 1 + l + sovRemote(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Label) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRemote(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovRemote(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LabelMatcher) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != 0 { - n += 1 + sovRemote(uint64(m.Type)) - } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovRemote(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovRemote(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ReadHints) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.StepMs != 0 { - n += 1 + sovRemote(uint64(m.StepMs)) - } - l = len(m.Func) - if l > 0 { - n += 1 + l + sovRemote(uint64(l)) - } - if m.StartMs != 0 { - n += 1 + sovRemote(uint64(m.StartMs)) - } - if m.EndMs != 0 { - n += 1 + sovRemote(uint64(m.EndMs)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRemote(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozRemote(x uint64) (n int) { - return sovRemote(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *WriteRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WriteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WriteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Timeseries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Timeseries = append(m.Timeseries, TimeSeries{}) - if err := m.Timeseries[len(m.Timeseries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ReadRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ReadRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ReadRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Queries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Queries = append(m.Queries, Query{}) - if err := m.Queries[len(m.Queries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ReadResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ReadResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ReadResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Results", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Results = append(m.Results, QueryResult{}) - if err := m.Results[len(m.Results)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Query) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Query: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Query: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StartTimestampMs", wireType) - } - m.StartTimestampMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StartTimestampMs |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EndTimestampMs", wireType) - } - m.EndTimestampMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.EndTimestampMs |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Matchers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Matchers = append(m.Matchers, LabelMatcher{}) - if err := m.Matchers[len(m.Matchers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Hints", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Hints == nil { - m.Hints = &ReadHints{} - } - if err := m.Hints.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryResult) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryResult: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryResult: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Timeseries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Timeseries = append(m.Timeseries, TimeSeries{}) - if err := m.Timeseries[len(m.Timeseries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Sample) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Sample: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Sample: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 1 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var v uint64 - if (iNdEx + 8) > l { - return io.ErrUnexpectedEOF - } - v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - m.Value = float64(math.Float64frombits(v)) - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) - } - m.Timestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Timestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TimeSeries) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TimeSeries: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TimeSeries: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Labels = append(m.Labels, Label{}) - if err := m.Labels[len(m.Labels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Samples", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Samples = append(m.Samples, Sample{}) - if err := m.Samples[len(m.Samples)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Label) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Label: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Label: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LabelMatcher) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LabelMatcher: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LabelMatcher: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= LabelMatcher_Type(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ReadHints) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ReadHints: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ReadHints: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StepMs", wireType) - } - m.StepMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StepMs |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Func", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRemote - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRemote - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Func = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StartMs", wireType) - } - m.StartMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StartMs |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EndMs", wireType) - } - m.EndMs = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRemote - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.EndMs |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRemote(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthRemote - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRemote(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRemote - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRemote - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRemote - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthRemote - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthRemote - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRemote - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRemote(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthRemote - } - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthRemote = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRemote = fmt.Errorf("proto: integer overflow") -) diff --git a/pkg/store/prompb/remote.proto b/pkg/store/prompb/remote.proto deleted file mode 100644 index 2f7cf3fc0e..0000000000 --- a/pkg/store/prompb/remote.proto +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2016 Prometheus Team -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// NOTE(fabxc): this is just hard-copied from prometheus/prometheus/prompb -// since depending on the generated package just added dependency complexities. -// It is also generated in a way that makes heavy use of pointers, e.g. for each sample -// which we want to avoid for ourselves. - -syntax = "proto3"; -package prometheus; - -import "gogoproto/gogo.proto"; - -option (gogoproto.sizer_all) = true; -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.goproto_getters_all) = false; - -option go_package = "prompb"; - -message WriteRequest { - repeated prometheus.TimeSeries timeseries = 1 [(gogoproto.nullable) = false]; -} - -message ReadRequest { - repeated Query queries = 1 [(gogoproto.nullable) = false]; -} - -message ReadResponse { - // In same order as the request's queries. - repeated QueryResult results = 1 [(gogoproto.nullable) = false]; -} - -message Query { - int64 start_timestamp_ms = 1; - int64 end_timestamp_ms = 2; - repeated LabelMatcher matchers = 3 [(gogoproto.nullable) = false]; - prometheus.ReadHints hints = 4; -} - -message QueryResult { - repeated TimeSeries timeseries = 1 [(gogoproto.nullable) = false]; -} - -message Sample { - double value = 1; - int64 timestamp = 2; -} - -message TimeSeries { - repeated Label labels = 1 [(gogoproto.nullable) = false]; - repeated Sample samples = 2 [(gogoproto.nullable) = false]; -} - -message Label { - string name = 1; - string value = 2; -} - -// Matcher specifies a rule, which can match or set of labels or not. -message LabelMatcher { - enum Type { - EQ = 0; - NEQ = 1; - RE = 2; - NRE = 3; - } - Type type = 1; - string name = 2; - string value = 3; -} - -message ReadHints { - int64 step_ms = 1; // Query step size in milliseconds. - string func = 2; // String representation of surrounding function or aggregation. - int64 start_ms = 3; // Start time in milliseconds. - int64 end_ms = 4; // End time in milliseconds. -} \ No newline at end of file diff --git a/pkg/testutil/prometheus.go b/pkg/testutil/prometheus.go index 30fede179e..f1271f0970 100644 --- a/pkg/testutil/prometheus.go +++ b/pkg/testutil/prometheus.go @@ -21,7 +21,6 @@ import ( "github.com/pkg/errors" "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb/labels" - "github.com/prometheus/prometheus/tsdb/testutil" "github.com/thanos-io/thanos/pkg/block/metadata" "github.com/thanos-io/thanos/pkg/runutil" "golang.org/x/sync/errgroup" @@ -96,9 +95,10 @@ func ForeachPrometheus(t *testing.T, testFn func(t testing.TB, p *Prometheus)) { for _, ver := range strings.Split(vers, " ") { if ok := t.Run(ver, func(t *testing.T) { p, err := newPrometheus(ver, "") - testutil.Ok(t, err) + Ok(t, err) testFn(t, p) + Ok(t, p.Stop()) }); !ok { return } @@ -106,7 +106,7 @@ func ForeachPrometheus(t *testing.T, testFn func(t testing.TB, p *Prometheus)) { } // NewPrometheus creates a new test Prometheus instance that will listen on local address. -// DEPRECARED: Use ForeachPrometheus instead. +// DEPRECATED: Use ForeachPrometheus instead. func NewPrometheus() (*Prometheus, error) { return newPrometheus("", "") } @@ -143,11 +143,17 @@ func newPrometheus(version string, prefix string) (*Prometheus, error) { // Start running the Prometheus instance and return. func (p *Prometheus) Start() error { - if !p.running { - if err := p.db.Close(); err != nil { - return err - } + if p.running { + return errors.New("Already started") } + + if err := p.db.Close(); err != nil { + return err + } + return p.start() +} + +func (p *Prometheus) start() error { p.running = true port, err := FreePort() @@ -173,6 +179,10 @@ func (p *Prometheus) Start() error { }, extra...) p.cmd = exec.Command(prometheusBin(p.version), args...) + p.cmd.SysProcAttr = &syscall.SysProcAttr{ + // For linux only, kill this if the go test process dies before the cleanup. + Pdeathsig: syscall.SIGKILL, + } go func() { if b, err := p.cmd.CombinedOutput(); err != nil { fmt.Fprintln(os.Stderr, "running Prometheus failed", err) @@ -205,10 +215,8 @@ func (p *Prometheus) Restart() error { if err := p.cmd.Process.Signal(syscall.SIGTERM); err != nil { return errors.Wrap(err, "failed to kill Prometheus. Kill it manually") } - _ = p.cmd.Wait() - - return p.Start() + return p.start() } // Dir returns TSDB dir. @@ -239,15 +247,19 @@ func (p *Prometheus) SetConfig(s string) (err error) { // Stop terminates Prometheus and clean up its data directory. func (p *Prometheus) Stop() error { + if !p.running { + return nil + } + if err := p.cmd.Process.Signal(syscall.SIGTERM); err != nil { return errors.Wrapf(err, "failed to Prometheus. Kill it manually and clean %s dir", p.db.Dir()) } - time.Sleep(time.Second / 2) return p.cleanup() } func (p *Prometheus) cleanup() error { + p.running = false return os.RemoveAll(p.db.Dir()) } diff --git a/pkg/tracing/stackdriver/tracer.go b/pkg/tracing/stackdriver/tracer.go index 291f46d516..d8d80b0f95 100644 --- a/pkg/tracing/stackdriver/tracer.go +++ b/pkg/tracing/stackdriver/tracer.go @@ -107,10 +107,11 @@ func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectI return nil, nil, err } + // TODO(bwplotka): gcloudtracer is archived. Find replacement. For now wrap traceClient for compatibility. r, err := gcloudtracer.NewRecorder( ctx, gcloudTraceProjectID, - &compTraceWrapper{traceClient}, + &compTraceWrapper{cl: traceClient}, gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) if err != nil { return nil, traceClient, err diff --git a/pkg/ui/query.go b/pkg/ui/query.go index e318cc55e5..d3a159e6e1 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -10,6 +10,7 @@ import ( "time" "github.com/go-kit/kit/log" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/common/route" "github.com/prometheus/common/version" @@ -26,6 +27,7 @@ type Query struct { cwd string birth time.Time + reg prometheus.Registerer now func() model.Time } @@ -38,7 +40,7 @@ type thanosVersion struct { GoVersion string `json:"goVersion"` } -func NewQueryUI(logger log.Logger, storeSet *query.StoreSet, flagsMap map[string]string) *Query { +func NewQueryUI(logger log.Logger, reg prometheus.Registerer, storeSet *query.StoreSet, flagsMap map[string]string) *Query { cwd, err := os.Getwd() if err != nil { cwd = "" @@ -49,6 +51,7 @@ func NewQueryUI(logger log.Logger, storeSet *query.StoreSet, flagsMap map[string flagsMap: flagsMap, cwd: cwd, birth: time.Now(), + reg: reg, now: model.Now, } } diff --git a/pkg/ui/rule.go b/pkg/ui/rule.go index 3d52c205a5..f35e26f4c4 100644 --- a/pkg/ui/rule.go +++ b/pkg/ui/rule.go @@ -11,6 +11,7 @@ import ( "time" "github.com/go-kit/kit/log" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/route" "github.com/prometheus/prometheus/rules" extpromhttp "github.com/thanos-io/thanos/pkg/extprom/http" @@ -25,14 +26,16 @@ type Rule struct { ruleManagers thanosrule.Managers queryURL string + reg prometheus.Registerer } -func NewRuleUI(logger log.Logger, ruleManagers map[storepb.PartialResponseStrategy]*rules.Manager, queryURL string, flagsMap map[string]string) *Rule { +func NewRuleUI(logger log.Logger, reg prometheus.Registerer, ruleManagers map[storepb.PartialResponseStrategy]*rules.Manager, queryURL string, flagsMap map[string]string) *Rule { return &Rule{ BaseUI: NewBaseUI(logger, "rule_menu.html", ruleTmplFuncs(queryURL)), flagsMap: flagsMap, ruleManagers: ruleManagers, queryURL: queryURL, + reg: reg, } } diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 753da8d3f4..f0e029f766 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -21,18 +21,16 @@ fi echo "installing gogofast" GO111MODULE=on go install "github.com/gogo/protobuf/protoc-gen-gogofast" -PROM_PATH="$(pwd)/pkg/store/prompb" GOGOPROTO_ROOT="$(GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)" GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf" -DIRS="pkg/store/storepb pkg/store/prompb" +DIRS="pkg/store/storepb" echo "generating code" for dir in ${DIRS}; do pushd ${dir} ${PROTOC_BIN} --gogofast_out=plugins=grpc:. -I=. \ -I="${GOGOPROTO_PATH}" \ - -I="${PROM_PATH}" \ *.proto sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go diff --git a/test/e2e/query_test.go b/test/e2e/query_test.go index 8afd8e6ccd..720423b458 100644 --- a/test/e2e/query_test.go +++ b/test/e2e/query_test.go @@ -5,6 +5,7 @@ import ( "fmt" "net/url" "os" + "sort" "testing" "time" @@ -16,54 +17,65 @@ import ( "github.com/thanos-io/thanos/pkg/testutil" ) -type testConfig struct { - name string - suite *spinupSuite -} +// NOTE: by using aggregation all results are now unsorted. +const queryUpWithoutInstance = "sum(up) without (instance)" -var ( - firstPromPort = promHTTPPort(1) - - queryStaticFlagsSuite = newSpinupSuite(). - Add(scraper(1, defaultPromConfig("prom-"+firstPromPort, 0))). - Add(scraper(2, defaultPromConfig("prom-ha", 0))). - Add(scraper(3, defaultPromConfig("prom-ha", 1))). - Add(querierWithStoreFlags(1, "replica", sidecarGRPC(1), sidecarGRPC(2), sidecarGRPC(3), remoteWriteReceiveGRPC(1))). - Add(querierWithStoreFlags(2, "replica", sidecarGRPC(1), sidecarGRPC(2), sidecarGRPC(3), remoteWriteReceiveGRPC(1))). - Add(receiver(1, defaultPromRemoteWriteConfig(nodeExporterHTTP(1), remoteWriteEndpoint(1)), 1)) - - queryFileSDSuite = newSpinupSuite(). - Add(scraper(1, defaultPromConfig("prom-"+firstPromPort, 0))). - Add(scraper(2, defaultPromConfig("prom-ha", 0))). - Add(scraper(3, defaultPromConfig("prom-ha", 1))). - Add(querierWithFileSD(1, "replica", sidecarGRPC(1), sidecarGRPC(2), sidecarGRPC(3), remoteWriteReceiveGRPC(1))). - Add(querierWithFileSD(2, "replica", sidecarGRPC(1), sidecarGRPC(2), sidecarGRPC(3), remoteWriteReceiveGRPC(1))). - Add(receiver(1, defaultPromRemoteWriteConfig(nodeExporterHTTP(1), remoteWriteEndpoint(1)), 1)) -) +// defaultPromConfig returns Prometheus config that sets Prometheus to: +// * expose 2 external labels, source and replica. +// * scrape fake target. This will produce up == 0 metric which we can assert on. +// * optionally remote write endpoint to write into. +func defaultPromConfig(name string, replica int, remoteWriteEndpoint string) string { + config := fmt.Sprintf(` +global: + external_labels: + prometheus: %v + replica: %v +scrape_configs: +- job_name: 'test' + static_configs: + - targets: ['fake'] +`, name, replica) -func TestQuery(t *testing.T) { - for _, tt := range []testConfig{ - { - "staticFlag", - queryStaticFlagsSuite, - }, - { - "fileSD", - queryFileSDSuite, - }, - } { - t.Run(tt.name, func(t *testing.T) { - testQuerySimple(t, tt) - }) + if remoteWriteEndpoint != "" { + config = fmt.Sprintf(` +%s +remote_write: +- url: "%s" +`, config, remoteWriteEndpoint) } + return config } -// testQuerySimple runs a setup of Prometheus servers, sidecars, and query nodes and verifies that -// queries return data merged from all Prometheus servers. Additionally it verifies if deduplication works for query. -func testQuerySimple(t *testing.T, conf testConfig) { +func sortResults(res model.Vector) { + sort.Slice(res, func(i, j int) bool { + return res[i].String() < res[j].String() + }) +} + +func TestQuery(t *testing.T) { + a := newLocalAddresser() + + // Thanos Receive. + r := receiver(a.New(), a.New(), a.New(), 1) + + // Prometheus-es. + prom1 := prometheus(a.New(), defaultPromConfig("prom-alone", 0, "")) + prom2 := prometheus(a.New(), defaultPromConfig("prom-both-remote-write-and-sidecar", 1234, remoteWriteEndpoint(r.HTTP))) + prom3 := prometheus(a.New(), defaultPromConfig("prom-ha", 0, "")) + prom4 := prometheus(a.New(), defaultPromConfig("prom-ha", 1, "")) + + // Sidecars per each Prometheus. + s1 := sidecar(a.New(), a.New(), prom1) + s2 := sidecar(a.New(), a.New(), prom2) + s3 := sidecar(a.New(), a.New(), prom3) + s4 := sidecar(a.New(), a.New(), prom4) + + // Querier. Both fileSD and directly by flags. + q := querier(a.New(), a.New(), []address{s1.GRPC, s2.GRPC, r.GRPC}, []address{s3.GRPC, s4.GRPC}) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) - exit, err := conf.suite.Exec(t, ctx, conf.name) + exit, err := e2eSpinup(t, ctx, r, prom1, prom2, prom3, prom4, s1, s2, s3, s4, q) if err != nil { t.Errorf("spinup failed: %v", err) cancel() @@ -79,14 +91,13 @@ func testQuerySimple(t *testing.T, conf testConfig) { w := log.NewSyncWriter(os.Stderr) l := log.NewLogfmtLogger(w) - l = log.With(l, "conf-name", conf.name) // Try query without deduplication. testutil.Ok(t, runutil.RetryWithLog(l, time.Second, ctx.Done(), func() error { select { case <-exit: cancel() - return errors.Errorf("exiting test, possibly due to timeout") + return nil default: } @@ -94,7 +105,7 @@ func testQuerySimple(t *testing.T, conf testConfig) { err error warnings []string ) - res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "up", time.Now(), promclient.QueryOptions{ + res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), queryUpWithoutInstance, time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -106,45 +117,48 @@ func testQuerySimple(t *testing.T, conf testConfig) { return errors.Errorf("unexpected warnings %s", warnings) } - expectedRes := 4 + expectedRes := 5 if len(res) != expectedRes { - return errors.Errorf("unexpected result size %d, expected %d", len(res), expectedRes) + return errors.Errorf("unexpected result size, expected %d; result: %v", expectedRes, res) } return nil })) - // In our model result are always sorted. + select { + case <-exit: + return + default: + } + + sortResults(res) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(promHTTP(1)), - "job": "prometheus", - "prometheus": model.LabelValue("prom-" + promHTTPPort(1)), - "replica": model.LabelValue("0"), + "job": "test", + "prometheus": "prom-alone", + "replica": "0", }, res[0].Metric) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(promHTTP(1)), - "job": "prometheus", - "prometheus": "prom-ha", - "replica": model.LabelValue("0"), + "job": "test", + "prometheus": "prom-both-remote-write-and-sidecar", + "receive": model.LabelValue(r.HTTP.Port), + "replica": model.LabelValue("1234"), }, res[1].Metric) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(promHTTP(1)), - "job": "prometheus", - "prometheus": "prom-ha", - "replica": model.LabelValue("1"), + "job": "test", + "prometheus": "prom-both-remote-write-and-sidecar", + "replica": model.LabelValue("1234"), }, res[2].Metric) - testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("1"), + "job": "test", + "prometheus": "prom-ha", + "replica": model.LabelValue("0"), }, res[3].Metric) + testutil.Equals(t, model.Metric{ + "job": "test", + "prometheus": "prom-ha", + "replica": model.LabelValue("1"), + }, res[4].Metric) - // Try query with deduplication. + // With deduplication. testutil.Ok(t, runutil.Retry(time.Second, ctx.Done(), func() error { select { case <-exit: @@ -157,7 +171,7 @@ func testQuerySimple(t *testing.T, conf testConfig) { err error warnings []string ) - res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "up", time.Now(), promclient.QueryOptions{ + res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), queryUpWithoutInstance, time.Now(), promclient.QueryOptions{ Deduplicate: true, }) if err != nil { @@ -169,32 +183,38 @@ func testQuerySimple(t *testing.T, conf testConfig) { return errors.Errorf("unexpected warnings %s", warnings) } - expectedRes := 3 + expectedRes := 4 if len(res) != expectedRes { - return errors.Errorf("unexpected result size %d, expected %d", len(res), expectedRes) + return errors.Errorf("unexpected result size, expected %d; result: %v", expectedRes, res) } return nil })) + select { + case <-exit: + return + default: + } + + sortResults(res) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(promHTTP(1)), - "job": "prometheus", - "prometheus": model.LabelValue("prom-" + promHTTPPort(1)), + "job": "test", + "prometheus": "prom-alone", }, res[0].Metric) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(promHTTP(1)), - "job": "prometheus", - "prometheus": "prom-ha", + "job": "test", + "prometheus": "prom-both-remote-write-and-sidecar", + "receive": model.LabelValue(r.HTTP.Port), }, res[1].Metric) testutil.Equals(t, model.Metric{ - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", + "job": "test", + "prometheus": "prom-both-remote-write-and-sidecar", }, res[2].Metric) + testutil.Equals(t, model.Metric{ + "job": "test", + "prometheus": "prom-ha", + }, res[3].Metric) } func urlParse(t *testing.T, addr string) *url.URL { @@ -203,29 +223,3 @@ func urlParse(t *testing.T, addr string) *url.URL { return u } - -func defaultPromConfig(name string, replicas int) string { - return fmt.Sprintf(` -global: - external_labels: - prometheus: %s - replica: %v -scrape_configs: -- job_name: prometheus - scrape_interval: 1s - static_configs: - - targets: - - "localhost:%s" -`, name, replicas, firstPromPort) -} - -func defaultPromRemoteWriteConfig(nodeExporterHTTP, remoteWriteEndpoint string) string { - return fmt.Sprintf(` -scrape_configs: -- job_name: 'node' - static_configs: - - targets: ['%s'] -remote_write: -- url: "%s" -`, nodeExporterHTTP, remoteWriteEndpoint) -} diff --git a/test/e2e/receive_test.go b/test/e2e/receive_test.go index a513649e5c..be20ba170b 100644 --- a/test/e2e/receive_test.go +++ b/test/e2e/receive_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/thanos-io/thanos/pkg/receive" + "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/thanos-io/thanos/pkg/promclient" @@ -12,97 +14,111 @@ import ( "github.com/thanos-io/thanos/pkg/testutil" ) -var ( - // The hashring suite creates three receivers, each with a Prometheus - // remote-writing data to it. However, due to the hashing of the labels, - // the time series from the Prometheus is forwarded to a different - // receiver in the hashring than the one handling the request. - // The querier queries all the receivers and the test verifies - // the time series are forwarded to the correct receive node. - receiveHashringSuite = newSpinupSuite(). - Add(querierWithStoreFlags(1, "replica", remoteWriteReceiveGRPC(1), remoteWriteReceiveGRPC(2), remoteWriteReceiveGRPC(3))). - Add(receiver(1, defaultPromRemoteWriteConfig(nodeExporterHTTP(1), remoteWriteEndpoint(1)), 1, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))). - Add(receiver(2, defaultPromRemoteWriteConfig(nodeExporterHTTP(2), remoteWriteEndpoint(2)), 1, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))). - Add(receiver(3, defaultPromRemoteWriteConfig(nodeExporterHTTP(3), remoteWriteEndpoint(3)), 1, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))) - receiveHashringMetrics = []model.Metric{ - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("2"), - }, - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(2)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("3"), - }, - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(3)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("1"), - }, - } - // The replication suite creates three receivers but only one - // Prometheus that remote-writes data. The querier queries all - // receivers and the test verifies that the time series are - // replicated to all of the nodes. - receiveReplicationSuite = newSpinupSuite(). - Add(querierWithStoreFlags(1, "replica", remoteWriteReceiveGRPC(1), remoteWriteReceiveGRPC(2), remoteWriteReceiveGRPC(3))). - Add(receiver(1, defaultPromRemoteWriteConfig(nodeExporterHTTP(1), remoteWriteEndpoint(1)), 3, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))). - Add(receiver(2, defaultPromConfig("no-remote-write", 2), 3, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))). - Add(receiver(3, defaultPromConfig("no-remote-write", 3), 3, remoteWriteEndpoint(1), remoteWriteEndpoint(2), remoteWriteEndpoint(3))) - receiveReplicationMetrics = []model.Metric{ - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("1"), - }, - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("2"), - }, - { - "__name__": "up", - "instance": model.LabelValue(nodeExporterHTTP(1)), - "job": "node", - "receive": "true", - "replica": model.LabelValue("3"), - }, - } -) - type receiveTestConfig struct { - testConfig + name string + cmds []scheduler metrics []model.Metric + + queryAddress address } func TestReceive(t *testing.T) { - for _, tt := range []receiveTestConfig{ - { - testConfig{ - "hashring", - receiveHashringSuite, - }, - receiveHashringMetrics, - }, - { - testConfig{ - "replication", - receiveReplicationSuite, - }, - receiveReplicationMetrics, - }, - } { + var testCases []receiveTestConfig + + a := newLocalAddresser() + { + // The hashring suite creates three receivers, each with a Prometheus + // remote-writing data to it. However, due to the hashing of the labels, + // the time series from the Prometheus is forwarded to a different + // receiver in the hashring than the one handling the request. + // The querier queries all the receivers and the test verifies + // the time series are forwarded to the correct receive node. + receiveHTTP1, receiveHTTP2, receiveHTTP3 := a.New(), a.New(), a.New() + + h := receive.HashringConfig{ + Endpoints: []string{remoteWriteEndpoint(receiveHTTP1), remoteWriteEndpoint(receiveHTTP2), remoteWriteEndpoint(receiveHTTP3)}, + } + + r1 := receiver(receiveHTTP1, a.New(), a.New(), 1, h) + r2 := receiver(receiveHTTP2, a.New(), a.New(), 1, h) + r3 := receiver(receiveHTTP3, a.New(), a.New(), 1, h) + + prom1 := prometheus(a.New(), defaultPromConfig("prom1", 1, remoteWriteEndpoint(r1.HTTP))) + prom2 := prometheus(a.New(), defaultPromConfig("prom2", 1, remoteWriteEndpoint(r2.HTTP))) + prom3 := prometheus(a.New(), defaultPromConfig("prom3", 1, remoteWriteEndpoint(r3.HTTP))) + + q1 := querier(a.New(), a.New(), []address{r1.GRPC, r2.GRPC, r3.GRPC}, nil) + + testCases = append(testCases, receiveTestConfig{ + name: "hashring", + cmds: []scheduler{q1, prom1, prom2, prom3, r1, r2, r3}, + queryAddress: q1.HTTP, + metrics: []model.Metric{ + { + "job": "test", + "prometheus": "prom1", + "receive": model.LabelValue(r1.HTTP.Port), + "replica": "1", + }, + { + "job": "test", + "prometheus": "prom2", + "receive": model.LabelValue(r2.HTTP.Port), + "replica": "1", + }, + { + "job": "test", + "prometheus": "prom3", + "receive": model.LabelValue(r2.HTTP.Port), + "replica": "1", + }, + }}) + } + { + // The replication suite creates three receivers but only one + // receives Prometheus remote-written data. The querier queries all + // receivers and the test verifies that the time series are + // replicated to all of the nodes. + receiveHTTP1, receiveHTTP2, receiveHTTP3 := a.New(), a.New(), a.New() + + h := receive.HashringConfig{ + Endpoints: []string{remoteWriteEndpoint(receiveHTTP1), remoteWriteEndpoint(receiveHTTP2), remoteWriteEndpoint(receiveHTTP3)}, + } + + r1 := receiver(receiveHTTP1, a.New(), a.New(), 3, h) + r2 := receiver(receiveHTTP2, a.New(), a.New(), 3, h) + r3 := receiver(receiveHTTP3, a.New(), a.New(), 3, h) + + prom1 := prometheus(a.New(), defaultPromConfig("prom1", 1, remoteWriteEndpoint(r1.HTTP))) + + q1 := querier(a.New(), a.New(), []address{r1.GRPC, r2.GRPC, r3.GRPC}, nil) + + testCases = append(testCases, receiveTestConfig{ + name: "replication", + cmds: []scheduler{q1, prom1, r1, r2, r3}, + queryAddress: q1.HTTP, + metrics: []model.Metric{ + { + "job": "test", + "prometheus": "prom1", + "receive": model.LabelValue(r1.HTTP.Port), + "replica": "1", + }, + { + "job": "test", + "prometheus": "prom1", + "receive": model.LabelValue(r2.HTTP.Port), + "replica": "1", + }, + { + "job": "test", + "prometheus": "prom1", + "receive": model.LabelValue(r3.HTTP.Port), + "replica": "1", + }, + }}) + } + for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { testReceive(t, tt) }) @@ -114,7 +130,7 @@ func TestReceive(t *testing.T) { func testReceive(t *testing.T, conf receiveTestConfig) { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) - exit, err := conf.suite.Exec(t, ctx, conf.name) + exit, err := e2eSpinup(t, ctx, conf.cmds...) if err != nil { t.Errorf("spinup failed: %v", err) cancel() @@ -142,7 +158,7 @@ func testReceive(t *testing.T, conf receiveTestConfig) { err error warnings []string ) - res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "up", time.Now(), promclient.QueryOptions{ + res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, conf.queryAddress.URL()), queryUpWithoutInstance, time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -154,14 +170,20 @@ func testReceive(t *testing.T, conf receiveTestConfig) { return errors.Errorf("unexpected warnings %s", warnings) } - expectedRes := len(conf.metrics) - if len(res) != expectedRes { - return errors.Errorf("unexpected result size %d, expected %d", len(res), expectedRes) + if len(res) != len(conf.metrics) { + return errors.Errorf("unexpected result size, expected %d; result: %v", len(conf.metrics), res) } return nil })) + select { + case <-exit: + return + default: + } + + sortResults(res) for i, metric := range conf.metrics { testutil.Equals(t, metric, res[i].Metric) } diff --git a/test/e2e/rule_test.go b/test/e2e/rule_test.go index 01294b071c..d8c840c82c 100644 --- a/test/e2e/rule_test.go +++ b/test/e2e/rule_test.go @@ -54,45 +54,22 @@ groups: var ( alertsToTest = []string{testAlertRuleAbortOnPartialResponse, testAlertRuleWarnOnPartialResponse} - - ruleStaticFlagsSuite = newSpinupSuite(). - Add(querierWithStoreFlags(1, "", rulerGRPC(1), rulerGRPC(2))). - Add(rulerWithQueryFlags(1, alertsToTest, queryHTTP(1))). - Add(rulerWithQueryFlags(2, alertsToTest, queryHTTP(1))). - Add(alertManager(1)) - - ruleFileSDSuite = newSpinupSuite(). - Add(querierWithFileSD(1, "", rulerGRPC(1), rulerGRPC(2))). - Add(rulerWithFileSD(1, alertsToTest, queryHTTP(1))). - Add(rulerWithFileSD(2, alertsToTest, queryHTTP(1))). - Add(alertManager(1)) ) func TestRule(t *testing.T) { - for _, tt := range []testConfig{ - { - "staticFlag", - ruleStaticFlagsSuite, - }, - { - "fileSD", - ruleFileSDSuite, - }, - } { - t.Run(tt.name, func(t *testing.T) { - testRuleComponent(t, tt) - }) - } -} + a := newLocalAddresser() + + am := alertManager(a.New()) + qAddr := a.New() + + r1 := rule(a.New(), a.New(), alertsToTest, am.HTTP, []address{qAddr}, nil) + r2 := rule(a.New(), a.New(), alertsToTest, am.HTTP, nil, []address{qAddr}) + + q := querier(qAddr, a.New(), []address{r1.GRPC, r2.GRPC}, nil) -// testRuleComponent tests the basic interaction between the rule component -// and the querying layer. -// Rules are evaluated against the query layer and the query layer in return -// can access data written by the rules. -func testRuleComponent(t *testing.T, conf testConfig) { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) - exit, err := conf.suite.Exec(t, ctx, "test_rule_component") + exit, err := e2eSpinup(t, ctx, q, r1, r2, am) if err != nil { t.Errorf("spinup failed: %v", err) cancel() @@ -110,50 +87,50 @@ func testRuleComponent(t *testing.T, conf testConfig) { "severity": "page", "alertname": "TestAlert_AbortOnPartialResponse", "alertstate": "firing", - "replica": "1", + "replica": model.LabelValue(r1.HTTP.Port), }, { "__name__": "ALERTS", "severity": "page", "alertname": "TestAlert_AbortOnPartialResponse", "alertstate": "firing", - "replica": "2", + "replica": model.LabelValue(r2.HTTP.Port), }, { "__name__": "ALERTS", "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", "alertstate": "firing", - "replica": "1", + "replica": model.LabelValue(r1.HTTP.Port), }, { "__name__": "ALERTS", "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", "alertstate": "firing", - "replica": "2", + "replica": model.LabelValue(r2.HTTP.Port), }, } expAlertLabels := []model.LabelSet{ { "severity": "page", "alertname": "TestAlert_AbortOnPartialResponse", - "replica": "1", + "replica": model.LabelValue(r1.HTTP.Port), }, { "severity": "page", "alertname": "TestAlert_AbortOnPartialResponse", - "replica": "2", + "replica": model.LabelValue(r2.HTTP.Port), }, { "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", - "replica": "1", + "replica": model.LabelValue(r1.HTTP.Port), }, { "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", - "replica": "2", + "replica": model.LabelValue(r2.HTTP.Port), }, } @@ -168,7 +145,7 @@ func testRuleComponent(t *testing.T, conf testConfig) { qtime := time.Now() // The time series written for the firing alerting rule must be queryable. - res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "ALERTS", time.Now(), promclient.QueryOptions{ + res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), "ALERTS", time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -181,7 +158,7 @@ func testRuleComponent(t *testing.T, conf testConfig) { } if len(res) != len(expMetrics) { - return errors.Errorf("unexpected result length %d", len(res)) + return errors.Errorf("unexpected result %v, expected %d", res, len(expMetrics)) } for i, r := range res { @@ -197,7 +174,7 @@ func testRuleComponent(t *testing.T, conf testConfig) { } // A notification must be sent to Alertmanager. - alrts, err := queryAlertmanagerAlerts(ctx, "http://localhost:29093") + alrts, err := queryAlertmanagerAlerts(ctx, am.HTTP.URL()) if err != nil { return err } @@ -215,7 +192,7 @@ func testRuleComponent(t *testing.T, conf testConfig) { // checks counter ensures we are not missing metrics. checks := 0 // Check metrics to make sure we report correct ones that allow handling the AlwaysFiring not being triggered because of query issue. - testutil.Ok(t, promclient.MetricValues(ctx, nil, urlParse(t, "http://"+rulerHTTP(1)), func(lset labels.Labels, val float64) error { + testutil.Ok(t, promclient.MetricValues(ctx, nil, urlParse(t, r1.HTTP.URL()), func(lset labels.Labels, val float64) error { switch lset.Get("__name__") { case "prometheus_rule_group_rules": checks++ @@ -276,21 +253,20 @@ func (a *failingStoreAPI) LabelValues(context.Context, *storepb.LabelValuesReque // Test Ruler behaviour on different storepb.PartialResponseStrategy when having partial response from single `failingStoreAPI`. func TestRulePartialResponse(t *testing.T) { - const expectedWarning = "receive series from Addr: 127.0.0.1:21091 LabelSets: [name:\"magic\" value:\"store_api\" ][name:\"magicmarker\" value:\"store_api\" ] Mint: -9223372036854775808 Maxt: 9223372036854775807: rpc error: code = Unknown desc = I always fail. No reason. I am just offended StoreAPI. Don't touch me" - - dir, err := ioutil.TempDir("", "test_rulepartial_respn") + dir, err := ioutil.TempDir("", "test_rulepartial_response") testutil.Ok(t, err) defer func() { testutil.Ok(t, os.RemoveAll(dir)) }() - suite := newSpinupSuite(). - Add(querierWithStoreFlags(1, "", rulerGRPC(1), fakeStoreAPIGRPC(1))). - Add(rulerWithDir(1, dir, queryHTTP(1))). - Add(fakeStoreAPI(1, &failingStoreAPI{})). - Add(alertManager(1)) + a := newLocalAddresser() + qAddr := a.New() - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + f := fakeStoreAPI(a.New(), &failingStoreAPI{}) + am := alertManager(a.New()) + r := ruleWithDir(a.New(), a.New(), dir, nil, am.HTTP, []address{qAddr}, nil) + q := querier(qAddr, a.New(), []address{r.GRPC, f.GRPC}, nil) - exit, err := suite.Exec(t, ctx, "test_rule_partial_response_component") + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + exit, err := e2eSpinup(t, ctx, am, f, q, r) if err != nil { t.Errorf("spinup failed: %v", err) cancel() @@ -311,7 +287,7 @@ func TestRulePartialResponse(t *testing.T) { } // The time series written for the firing alerting rule must be queryable. - res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "ALERTS", time.Now(), promclient.QueryOptions{ + res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), "ALERTS", time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -335,7 +311,7 @@ func TestRulePartialResponse(t *testing.T) { testutil.Ok(t, ioutil.WriteFile(path.Join(dir, fmt.Sprintf("rules-%d.yaml", i)), []byte(rule), 0666)) } - resp, err := http.Post("http://"+rulerHTTP(1)+"/-/reload", "", nil) + resp, err := http.Post(r.HTTP.URL()+"/-/reload", "", nil) testutil.Ok(t, err) defer func() { _, _ = ioutil.ReadAll(resp.Body); _ = resp.Body.Close() }() testutil.Equals(t, http.StatusOK, resp.StatusCode) @@ -347,17 +323,19 @@ func TestRulePartialResponse(t *testing.T) { "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", "alertstate": "firing", - "replica": "1", + "replica": model.LabelValue(r.HTTP.Port), }, } expAlertLabels := []model.LabelSet{ { "severity": "page", "alertname": "TestAlert_WarnOnPartialResponse", - "replica": "1", + "replica": model.LabelValue(r.HTTP.Port), }, } + expectedWarning := "receive series from Addr: " + f.GRPC.HostPort() + " LabelSets: [name:\"magic\" value:\"store_api\" ][name:\"magicmarker\" value:\"store_api\" ] Mint: -9223372036854775808 Maxt: 9223372036854775807: rpc error: code = Unknown desc = I always fail. No reason. I am just offended StoreAPI. Don't touch me" + testutil.Ok(t, runutil.Retry(5*time.Second, ctx.Done(), func() (err error) { select { case <-exit: @@ -369,7 +347,7 @@ func TestRulePartialResponse(t *testing.T) { qtime := time.Now() // The time series written for the firing alerting rule must be queryable. - res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "ALERTS", time.Now(), promclient.QueryOptions{ + res, warnings, err := promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), "ALERTS", time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -403,7 +381,7 @@ func TestRulePartialResponse(t *testing.T) { } // A notification must be sent to Alertmanager. - alrts, err := queryAlertmanagerAlerts(ctx, "http://localhost:29093") + alrts, err := queryAlertmanagerAlerts(ctx, am.HTTP.URL()) if err != nil { return err } @@ -421,7 +399,7 @@ func TestRulePartialResponse(t *testing.T) { // checks counter ensures we are not missing metrics. checks := 0 // Check metrics to make sure we report correct ones that allow handling the AlwaysFiring not being triggered because of query issue. - testutil.Ok(t, promclient.MetricValues(ctx, nil, urlParse(t, "http://"+rulerHTTP(1)), func(lset labels.Labels, val float64) error { + testutil.Ok(t, promclient.MetricValues(ctx, nil, urlParse(t, r.HTTP.URL()), func(lset labels.Labels, val float64) error { switch lset.Get("__name__") { case "prometheus_rule_group_rules": checks++ diff --git a/test/e2e/spinup_test.go b/test/e2e/spinup_test.go index 41fe0665b4..f47729b1af 100644 --- a/test/e2e/spinup_test.go +++ b/test/e2e/spinup_test.go @@ -1,8 +1,9 @@ package e2e_test import ( - "bytes" + "bufio" "context" + "encoding/json" "fmt" "io" "io/ioutil" @@ -18,42 +19,58 @@ import ( "github.com/oklog/run" "github.com/pkg/errors" "github.com/thanos-io/thanos/pkg/objstore/s3" + "github.com/thanos-io/thanos/pkg/receive" "github.com/thanos-io/thanos/pkg/runutil" "github.com/thanos-io/thanos/pkg/store/storepb" "github.com/thanos-io/thanos/pkg/testutil" "google.golang.org/grpc" ) -var ( - promHTTPPort = func(i int) string { return fmt.Sprintf("%d", 9090+i) } +const portMin = 10000 - // We keep this one with localhost, to have perfect match with what Prometheus will expose in up metric. - promHTTP = func(i int) string { return fmt.Sprintf("localhost:%s", promHTTPPort(i)) } - promRemoteWriteHTTP = func(i int) string { return fmt.Sprintf("localhost:%s", promHTTPPort(100+i)) } +func remoteWriteEndpoint(addr address) string { return fmt.Sprintf("%s/api/v1/receive", addr.URL()) } - nodeExporterHTTP = func(i int) string { return fmt.Sprintf("localhost:%d", 9100+i) } +type address struct { + host string + Port string +} - sidecarGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19090+i) } - sidecarHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19190+i) } +func (a address) HostPort() string { + return net.JoinHostPort(a.host, a.Port) +} - queryGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19490+i) } - queryHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19590+i) } +func (a address) URL() string { + return fmt.Sprintf("http://%s", net.JoinHostPort(a.host, a.Port)) +} - rulerGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19790+i) } - rulerHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 19890+i) } +// portPool allows to reserve ports within unit test. This naive implementation assumes that all ports from portMin-X are free outside. +// No top boundary, no thread safety. +// TODO(bwplotka): Make it more resilient. +type portPool struct { + lastPort int +} - remoteWriteEndpoint = func(i int) string { return fmt.Sprintf("http://%s/api/v1/receive", remoteWriteReceiveHTTP(i)) } - remoteWriteReceiveHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 18690+i) } - remoteWriteReceiveGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 18790+i) } - remoteWriteReceiveMetricHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 18890+i) } +func (pp *portPool) New() int { + if pp.lastPort < portMin { + pp.lastPort = portMin - 1 + } + pp.lastPort++ + return pp.lastPort +} - storeGatewayGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 20090+i) } - storeGatewayHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 20190+i) } +type addresser struct { + host string + pp *portPool +} - minioHTTP = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 20290+i) } +func (a *addresser) New() address { + return address{host: a.host, Port: fmt.Sprintf("%d", a.pp.New())} +} - fakeStoreAPIGRPC = func(i int) string { return fmt.Sprintf("127.0.0.1:%d", 21090+i) } -) +func newLocalAddresser() *addresser { + // We keep this one with localhost, not 127.0.0.1 to have perfect match with what Prometheus will expose in up metric. + return &addresser{host: "localhost", pp: &portPool{}} +} type Exec interface { Start(stdout io.Writer, stderr io.Writer) error @@ -74,6 +91,10 @@ func newCmdExec(cmd *exec.Cmd) *cmdExec { func (c *cmdExec) Start(stdout io.Writer, stderr io.Writer) error { c.Stderr = stderr c.Stdout = stdout + c.SysProcAttr = &syscall.SysProcAttr{ + // For linux only, kill this if the go test process dies before the cleanup. + Pdeathsig: syscall.SIGKILL, + } return c.Cmd.Start() } @@ -81,160 +102,186 @@ func (c *cmdExec) Kill() error { return c.Process.Signal(syscall.SIGKILL) } func (c *cmdExec) String() string { return fmt.Sprintf("%s %v", c.Path, c.Args[1:]) } -type cmdScheduleFunc func(workDir string) ([]Exec, error) - -type spinupSuite struct { - cmdScheduleFuncs []cmdScheduleFunc - - minioConfig s3.Config - withPreStartedMinio bool +type scheduler interface { + Schedule(workDir string) (Exec, error) } -func newSpinupSuite() *spinupSuite { return &spinupSuite{} } +type serverScheduler struct { + schedule func(workDir string) (Exec, error) -func (s *spinupSuite) Add(cmdSchedule cmdScheduleFunc) *spinupSuite { - s.cmdScheduleFuncs = append(s.cmdScheduleFuncs, cmdSchedule) - return s + HTTP address + GRPC address } -func scraper(i int, config string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - promDir := fmt.Sprintf("%s/data/prom%d", workDir, i) - if err := os.MkdirAll(promDir, 0777); err != nil { - return nil, errors.Wrap(err, "create prom dir failed") - } +func (s *serverScheduler) Schedule(workDir string) (Exec, error) { return s.schedule(workDir) } - if err := ioutil.WriteFile(promDir+"/prometheus.yml", []byte(config), 0666); err != nil { - return nil, errors.Wrap(err, "creating prom config failed") - } +type prometheusScheduler struct { + serverScheduler - var cmds []Exec - cmds = append(cmds, newCmdExec(exec.Command(testutil.PrometheusBinary(), - "--config.file", promDir+"/prometheus.yml", - "--storage.tsdb.path", promDir, - "--storage.tsdb.max-block-duration", "2h", - "--log.level", "info", - "--web.listen-address", promHTTP(i), - ))) - return append(cmds, newCmdExec(exec.Command("thanos", "sidecar", - "--debug.name", fmt.Sprintf("sidecar-%d", i), - "--grpc-address", sidecarGRPC(i), - "--http-address", sidecarHTTP(i), - "--prometheus.url", fmt.Sprintf("http://%s", promHTTP(i)), - "--tsdb.path", promDir, - "--log.level", "debug"))), nil - } + RelDir string } -func receiver(i int, config string, replicationFactor int, receiveAddresses ...string) cmdScheduleFunc { - if len(receiveAddresses) == 0 { - receiveAddresses = []string{remoteWriteEndpoint(1)} +func prometheus(http address, config string) *prometheusScheduler { + s := &prometheusScheduler{ + RelDir: path.Join("data", "prom", http.Port), } - return func(workDir string) ([]Exec, error) { - promDir := fmt.Sprintf("%s/data/remote-write-prom%d", workDir, i) - if err := os.MkdirAll(promDir, 0777); err != nil { - return nil, errors.Wrap(err, "create prom dir failed") - } - if err := ioutil.WriteFile(promDir+"/prometheus.yml", []byte(config), 0666); err != nil { - return nil, errors.Wrap(err, "creating prom config failed") - } + s.serverScheduler = serverScheduler{ + HTTP: http, + schedule: func(workDir string) (execs Exec, e error) { + promDir := path.Join(workDir, s.RelDir) + if err := os.MkdirAll(promDir, 0777); err != nil { + return nil, errors.Wrap(err, "create prom dir failed") + } - var cmds []Exec - cmds = append(cmds, newCmdExec(exec.Command(testutil.PrometheusBinary(), - "--config.file", promDir+"/prometheus.yml", - "--storage.tsdb.path", promDir, - "--log.level", "info", - "--web.listen-address", promRemoteWriteHTTP(i), - ))) - - hashringsFileDir := fmt.Sprintf("%s/data/receiveFile%d", workDir, i) - if err := os.MkdirAll(hashringsFileDir, 0777); err != nil { - return nil, errors.Wrap(err, "create receive dir failed") - } + if err := ioutil.WriteFile(promDir+"/prometheus.yml", []byte(config), 0666); err != nil { + return nil, errors.Wrap(err, "creating prom config failed") + } - if err := ioutil.WriteFile(path.Join(hashringsFileDir, "hashrings.json"), []byte(generateHashringsFile(receiveAddresses)), 0666); err != nil { - return nil, errors.Wrap(err, "creating receive config failed") - } + return newCmdExec(exec.Command(testutil.PrometheusBinary(), + "--config.file", promDir+"/prometheus.yml", + "--storage.tsdb.path", promDir, + "--storage.tsdb.max-block-duration", "2h", + "--log.level", "info", + "--web.listen-address", http.HostPort(), + )), nil + }, + } + return s +} - return append(cmds, newCmdExec(exec.Command("thanos", "receive", - "--debug.name", fmt.Sprintf("remote-write-receive-%d", i), - "--grpc-address", remoteWriteReceiveGRPC(i), - "--http-address", remoteWriteReceiveMetricHTTP(i), - "--remote-write.address", remoteWriteReceiveHTTP(i), - "--labels", "receive=\"true\"", - "--labels", fmt.Sprintf(`replica="%d"`, i), - "--tsdb.path", promDir, - "--log.level", "debug", - "--receive.replication-factor", strconv.Itoa(replicationFactor), - "--receive.local-endpoint", remoteWriteEndpoint(i), - "--receive.hashrings-file", path.Join(hashringsFileDir, "hashrings.json"), - "--receive.hashrings-file-refresh-interval", "5s"))), nil +func sidecar(http, grpc address, prom *prometheusScheduler) *serverScheduler { + return &serverScheduler{ + HTTP: http, + GRPC: grpc, + schedule: func(workDir string) (Exec, error) { + promDir := path.Join(workDir, prom.RelDir) + return newCmdExec(exec.Command("thanos", "sidecar", + "--debug.name", fmt.Sprintf("sidecar-%s", http.Port), + "--grpc-address", grpc.HostPort(), + "--http-address", http.HostPort(), + "--prometheus.url", prom.HTTP.URL(), + "--tsdb.path", promDir, + "--log.level", "debug")), nil + }, } } -func querierWithStoreFlags(i int, replicaLabel string, storeAddresses ...string) cmdScheduleFunc { - return func(_ string) ([]Exec, error) { - args := defaultQuerierFlags(i, replicaLabel) +func receiver(http, grpc, metric address, replicationFactor int, hashring ...receive.HashringConfig) *serverScheduler { + if len(hashring) == 0 { + hashring = []receive.HashringConfig{{Endpoints: []string{remoteWriteEndpoint(http)}}} + } - for _, addr := range storeAddresses { - args = append(args, "--store", addr) - } - return []Exec{newCmdExec(exec.Command("thanos", args...))}, nil + return &serverScheduler{ + HTTP: http, + GRPC: grpc, + schedule: func(workDir string) (Exec, error) { + receiveDir := path.Join(workDir, "data", "receive", http.Port) + if err := os.MkdirAll(receiveDir, 0777); err != nil { + return nil, errors.Wrap(err, "create receive dir") + } + + b, err := json.Marshal(hashring) + if err != nil { + return nil, errors.Wrapf(err, "generate hashring file: %v", hashring) + } + + if err := ioutil.WriteFile(path.Join(receiveDir, "hashrings.json"), b, 0666); err != nil { + return nil, errors.Wrap(err, "creating receive config") + } + + return newCmdExec(exec.Command("thanos", "receive", + "--debug.name", fmt.Sprintf("receive-%s", http.Port), + "--grpc-address", grpc.HostPort(), + "--http-address", metric.HostPort(), + "--remote-write.address", http.HostPort(), + "--labels", fmt.Sprintf(`receive="%s"`, http.Port), + "--tsdb.path", path.Join(receiveDir, "tsdb"), + "--log.level", "debug", + "--receive.replication-factor", strconv.Itoa(replicationFactor), + "--receive.local-endpoint", remoteWriteEndpoint(http), + "--receive.hashrings-file", path.Join(receiveDir, "hashrings.json"), + "--receive.hashrings-file-refresh-interval", "5s")), nil + }, } } -func querierWithFileSD(i int, replicaLabel string, storeAddresses ...string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - queryFileSDDir := fmt.Sprintf("%s/data/queryFileSd%d", workDir, i) - if err := os.MkdirAll(queryFileSDDir, 0777); err != nil { - return nil, errors.Wrap(err, "create query dir failed") - } +func querier(http, grpc address, storeAddresses []address, fileSDStoreAddresses []address) *serverScheduler { + const replicaLabel = "replica" + return &serverScheduler{ + HTTP: http, + GRPC: grpc, + schedule: func(workDir string) (Exec, error) { + args := []string{ + "query", + "--debug.name", fmt.Sprintf("querier-%s", http.Port), + "--grpc-address", grpc.HostPort(), + "--http-address", http.HostPort(), + "--log.level", "debug", + "--query.replica-label", replicaLabel, + "--store.sd-dns-interval", "5s", + } + for _, addr := range storeAddresses { + args = append(args, "--store", addr.HostPort()) + } - if err := ioutil.WriteFile(queryFileSDDir+"/filesd.json", []byte(generateFileSD(storeAddresses)), 0666); err != nil { - return nil, errors.Wrap(err, "creating query SD config failed") - } + if len(fileSDStoreAddresses) > 0 { + queryFileSDDir := path.Join(workDir, "data", "querier", http.Port) + if err := os.MkdirAll(queryFileSDDir, 0777); err != nil { + return nil, errors.Wrap(err, "create query dir failed") + } - args := append( - defaultQuerierFlags(i, replicaLabel), - "--store.sd-files", path.Join(queryFileSDDir, "filesd.json"), - "--store.sd-interval", "5s", - ) + if err := ioutil.WriteFile(queryFileSDDir+"/filesd.json", []byte(generateFileSD(fileSDStoreAddresses)), 0666); err != nil { + return nil, errors.Wrap(err, "creating query SD config failed") + } + + args = append(args, + "--store.sd-files", path.Join(queryFileSDDir, "filesd.json"), + "--store.sd-interval", "5s", + ) + } - return []Exec{newCmdExec(exec.Command("thanos", args...))}, nil + return newCmdExec(exec.Command("thanos", args...)), nil + }, } } -func storeGateway(i int, bucketConfig []byte) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dbDir := fmt.Sprintf("%s/data/store-gateway%d", workDir, i) +func storeGateway(http, grpc address, bucketConfig []byte) *serverScheduler { + return &serverScheduler{ + HTTP: http, + GRPC: grpc, + schedule: func(workDir string) (Exec, error) { + dbDir := path.Join(workDir, "data", "store-gateway", http.Port) - if err := os.MkdirAll(dbDir, 0777); err != nil { - return nil, errors.Wrap(err, "creating store gateway dir failed") - } + if err := os.MkdirAll(dbDir, 0777); err != nil { + return nil, errors.Wrap(err, "creating store gateway dir failed") + } - return []Exec{newCmdExec(exec.Command("thanos", - "store", - "--debug.name", fmt.Sprintf("store-%d", i), - "--data-dir", dbDir, - "--grpc-address", storeGatewayGRPC(i), - "--http-address", storeGatewayHTTP(i), - "--log.level", "debug", - "--objstore.config", string(bucketConfig), - // Accelerated sync time for quicker test (3m by default) - "--sync-block-duration", "5s", - ))}, nil + return newCmdExec(exec.Command("thanos", + "store", + "--debug.name", fmt.Sprintf("store-gw-%s", http.Port), + "--data-dir", dbDir, + "--grpc-address", grpc.HostPort(), + "--http-address", http.HostPort(), + "--log.level", "debug", + "--objstore.config", string(bucketConfig), + // Accelerated sync time for quicker test (3m by default) + "--sync-block-duration", "5s", + )), nil + }, } } -func alertManager(i int) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dir := fmt.Sprintf("%s/data/alertmanager%d", workDir, i) +func alertManager(http address) *serverScheduler { + return &serverScheduler{ + HTTP: http, + schedule: func(workDir string) (Exec, error) { + dir := path.Join(workDir, "data", "alertmanager", http.Port) - if err := os.MkdirAll(dir, 0777); err != nil { - return nil, errors.Wrap(err, "creating alertmanager dir failed") - } - config := ` + if err := os.MkdirAll(dir, 0777); err != nil { + return nil, errors.Wrap(err, "creating alertmanager dir failed") + } + config := ` route: group_by: ['alertname'] group_wait: 1s @@ -243,88 +290,72 @@ route: receivers: - name: 'null' ` - if err := ioutil.WriteFile(dir+"/config.yaml", []byte(config), 0666); err != nil { - return nil, errors.Wrap(err, "creating alertmanager config file failed") - } - return []Exec{newCmdExec(exec.Command(testutil.AlertmanagerBinary(), - "--config.file", dir+"/config.yaml", - "--web.listen-address", "127.0.0.1:29093", - "--log.level", "debug", - ))}, nil - } -} - -func rulerWithQueryFlags(i int, rules []string, queryAddresses ...string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dbDir := fmt.Sprintf("%s/data/rule%d", workDir, i) - - if err := os.MkdirAll(dbDir, 0777); err != nil { - return nil, errors.Wrap(err, "creating ruler dir") - } - for i, rule := range rules { - if err := ioutil.WriteFile(path.Join(dbDir, fmt.Sprintf("/rules-%d.yaml", i)), []byte(rule), 0666); err != nil { - return nil, errors.Wrapf(err, "writing rule %s", path.Join(dbDir, fmt.Sprintf("/rules-%d.yaml", i))) + if err := ioutil.WriteFile(dir+"/config.yaml", []byte(config), 0666); err != nil { + return nil, errors.Wrap(err, "creating alertmanager config file failed") } - } - - args := defaultRulerFlags(i, dbDir, dbDir) - - for _, addr := range queryAddresses { - args = append(args, "--query", addr) - } - return []Exec{newCmdExec(exec.Command("thanos", args...))}, nil + return newCmdExec(exec.Command(testutil.AlertmanagerBinary(), + "--config.file", dir+"/config.yaml", + "--web.listen-address", http.HostPort(), + "--log.level", "debug", + )), nil + }, } } -func rulerWithDir(i int, ruleDir string, queryAddresses ...string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dbDir := fmt.Sprintf("%s/data/rule%d", workDir, i) - - if err := os.MkdirAll(dbDir, 0777); err != nil { - return nil, errors.Wrap(err, "creating ruler dir") - } - - args := defaultRulerFlags(i, dbDir, ruleDir) - - for _, addr := range queryAddresses { - args = append(args, "--query", addr) - } - return []Exec{newCmdExec(exec.Command("thanos", args...))}, nil - } +func rule(http, grpc address, rules []string, am address, queryAddresses []address, queryFileSDAddresses []address) *serverScheduler { + return ruleWithDir(http, grpc, "", rules, am, queryAddresses, queryFileSDAddresses) } -func rulerWithFileSD(i int, rules []string, queryAddresses ...string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dbDir := fmt.Sprintf("%s/data/rule%d", workDir, i) - - if err := os.MkdirAll(dbDir, 0777); err != nil { - return nil, errors.Wrap(err, "creating ruler dir") - } - for i, rule := range rules { - if err := ioutil.WriteFile(path.Join(dbDir, fmt.Sprintf("/rules-%d.yaml", i)), []byte(rule), 0666); err != nil { - return nil, errors.Wrapf(err, "writing rule %s", path.Join(dbDir, fmt.Sprintf("/rules-%d.yaml", i))) +func ruleWithDir(http, grpc address, dir string, rules []string, am address, queryAddresses []address, queryFileSDAddresses []address) *serverScheduler { + return &serverScheduler{ + HTTP: http, + GRPC: grpc, + schedule: func(workDir string) (Exec, error) { + ruleDir := path.Join(workDir, "data", "rule", http.Port) + if dir != "" { + ruleDir = dir } - } - ruleFileSDDir := fmt.Sprintf("%s/data/ruleFileSd%d", workDir, i) - if err := os.MkdirAll(ruleFileSDDir, 0777); err != nil { - return nil, errors.Wrap(err, "create ruler filesd dir") - } + if err := os.MkdirAll(ruleDir, 0777); err != nil { + return nil, errors.Wrap(err, "creating ruler dir") + } + for i, rule := range rules { + if err := ioutil.WriteFile(path.Join(ruleDir, fmt.Sprintf("/rules-%d.yaml", i)), []byte(rule), 0666); err != nil { + return nil, errors.Wrapf(err, "writing rule %s", path.Join(ruleDir, fmt.Sprintf("/rules-%d.yaml", i))) + } + } - if err := ioutil.WriteFile(ruleFileSDDir+"/filesd.json", []byte(generateFileSD(queryAddresses)), 0666); err != nil { - return nil, errors.Wrap(err, "creating ruler filesd config") - } + args := []string{ + "rule", + "--debug.name", fmt.Sprintf("rule-%s", http.Port), + "--label", fmt.Sprintf(`replica="%s"`, http.Port), + "--data-dir", path.Join(ruleDir, "data"), + "--rule-file", path.Join(ruleDir, "*.yaml"), + "--eval-interval", "1s", + "--alertmanagers.url", am.URL(), + "--grpc-address", grpc.HostPort(), + "--http-address", http.HostPort(), + "--log.level", "debug", + "--query.sd-dns-interval", "5s", + } - args := append(defaultRulerFlags(i, dbDir, dbDir), - "--query.sd-files", path.Join(ruleFileSDDir, "filesd.json"), - "--query.sd-interval", "5s") + for _, addr := range queryAddresses { + args = append(args, "--query", addr.HostPort()) + } - return []Exec{newCmdExec(exec.Command("thanos", args...))}, nil + if len(queryFileSDAddresses) > 0 { + if err := ioutil.WriteFile(path.Join(ruleDir, "filesd.json"), []byte(generateFileSD(queryFileSDAddresses)), 0666); err != nil { + return nil, errors.Wrap(err, "creating ruler filesd config") + } + args = append(args, "--query.sd-files", path.Join(ruleDir, "filesd.json")) + } + return newCmdExec(exec.Command("thanos", args...)), nil + }, } } type sameProcessGRPCServiceExec struct { - i int + addr string stdout io.Writer stderr io.Writer @@ -343,7 +374,7 @@ func (c *sameProcessGRPCServiceExec) Start(stdout io.Writer, stderr io.Writer) e } c.ctx, c.cancel = context.WithCancel(context.Background()) - l, err := net.Listen("tcp", fakeStoreAPIGRPC(c.i)) + l, err := net.Listen("tcp", c.addr) if err != nil { return errors.Wrap(err, "listen API address") } @@ -376,49 +407,53 @@ func (c *sameProcessGRPCServiceExec) Kill() error { } func (c *sameProcessGRPCServiceExec) String() string { - return fmt.Sprintf("gRPC service %v on %v", c.i, fakeStoreAPIGRPC(c.i)) + return fmt.Sprintf("gRPC service %v", c.addr) } -func fakeStoreAPI(i int, svc storepb.StoreServer) cmdScheduleFunc { - return func(_ string) ([]Exec, error) { - srv := grpc.NewServer() - storepb.RegisterStoreServer(srv, svc) +func fakeStoreAPI(grpcAddr address, svc storepb.StoreServer) *serverScheduler { + return &serverScheduler{ + GRPC: grpcAddr, + schedule: func(_ string) (Exec, error) { + + srv := grpc.NewServer() + storepb.RegisterStoreServer(srv, svc) - return []Exec{&sameProcessGRPCServiceExec{i: i, srv: srv}}, nil + return &sameProcessGRPCServiceExec{addr: grpcAddr.HostPort(), srv: srv}, nil + }, } } -func minio(accessKey string, secretKey string) cmdScheduleFunc { - return func(workDir string) ([]Exec, error) { - dbDir := fmt.Sprintf("%s/data/minio", workDir) - - if err := os.MkdirAll(dbDir, 0777); err != nil { - return nil, errors.Wrap(err, "creating minio dir failed") - } - - cmd := exec.Command(testutil.MinioBinary(), - "server", - "--address", minioHTTP(1), - dbDir, - ) - cmd.Env = append(os.Environ(), - fmt.Sprintf("MINIO_ACCESS_KEY=%s", accessKey), - fmt.Sprintf("MINIO_SECRET_KEY=%s", secretKey)) +func minio(http address, config s3.Config) *serverScheduler { + return &serverScheduler{ + HTTP: http, + schedule: func(workDir string) (Exec, error) { + dbDir := path.Join(workDir, "data", "minio", http.Port) + if err := os.MkdirAll(dbDir, 0777); err != nil { + return nil, errors.Wrap(err, "creating minio dir failed") + } - return []Exec{newCmdExec(cmd)}, nil + cmd := exec.Command(testutil.MinioBinary(), + "server", + "--address", http.HostPort(), + dbDir, + ) + cmd.Env = append(os.Environ(), + fmt.Sprintf("MINIO_ACCESS_KEY=%s", config.AccessKey), + fmt.Sprintf("MINIO_SECRET_KEY=%s", config.SecretKey)) + + return newCmdExec(cmd), nil + }, } } -func (s *spinupSuite) WithPreStartedMinio(config s3.Config) *spinupSuite { - s.minioConfig = config - s.withPreStartedMinio = true - return s +// NOTE: It is important to install Thanos before using this function to compile latest changes. +// This means that export GOCACHE=/unique/path is must have to avoid having this test cached locally. +func e2eSpinup(t testing.TB, ctx context.Context, cmds ...scheduler) (exit chan struct{}, err error) { + return e2eSpinupWithS3ObjStorage(t, ctx, address{}, nil, cmds...) } -// NOTE: It is important to install Thanos before using this function to compile latest changes. -// This means that export GOCACHE=/unique/path is must have to avoid having this test cached. -func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) (exit chan struct{}, err error) { - dir, err := ioutil.TempDir("", testName) +func e2eSpinupWithS3ObjStorage(t testing.TB, ctx context.Context, minioAddr address, s3Config *s3.Config, cmds ...scheduler) (exit chan struct{}, err error) { + dir, err := ioutil.TempDir("", "spinup_test") if err != nil { return nil, err } @@ -431,13 +466,9 @@ func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) ( } }() - var minioExit chan struct{} - if s.withPreStartedMinio { - // Start minio before anything else. - // NewTestBucketFromConfig is responsible for healthchecking by creating a requested bucket in retry loop. - minioExit, err = newSpinupSuite(). - Add(minio(s.minioConfig.AccessKey, s.minioConfig.SecretKey)). - Exec(t, ctx, testName+"_minio") + var s3Exit chan struct{} + if s3Config != nil { + s3Exit, err = e2eSpinupWithS3ObjStorage(t, ctx, address{}, nil, minio(minioAddr, *s3Config)) if err != nil { return nil, errors.Wrap(err, "start minio") } @@ -445,13 +476,13 @@ func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) ( ctx, cancel := context.WithCancel(ctx) if err := runutil.Retry(time.Second, ctx.Done(), func() error { select { - case <-minioExit: + case <-s3Exit: cancel() return nil default: } - bkt, _, err := s3.NewTestBucketFromConfig(t, "eu-west1", s.minioConfig, false) + bkt, _, err := s3.NewTestBucketFromConfig(t, "eu-west1", *s3Config, false) if err != nil { return errors.Wrap(err, "create bkt client for minio healthcheck") } @@ -468,20 +499,22 @@ func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) ( { ctx, cancel := context.WithCancel(ctx) g.Add(func() error { - if s.withPreStartedMinio { + // This go routine will return only when: + // 1) Any other process from group exited unexpectedly + // 2) Global context will be cancelled. + // 3) Minio (if started) exited unexpectedly. + + if s3Exit != nil { select { case <-ctx.Done(): - case <-minioExit: + case <-s3Exit: } - } else { - <-ctx.Done() + return nil } - // This go routine will return only when: - // 1) Any other process from group exited unexpectedly - // 2) Global context will be cancelled. - // 3) Minio (if started) exited unexpectedly. + <-ctx.Done() return nil + }, func(error) { cancel() if err := os.RemoveAll(dir); err != nil { @@ -490,40 +523,34 @@ func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) ( }) } - var commands []Exec - - for _, cmdFunc := range s.cmdScheduleFuncs { - cmds, err := cmdFunc(dir) + var stdFiles []*os.File + // Run go routine for each command. + for _, command := range cmds { + c, err := command.Schedule(dir) if err != nil { return nil, err } + // Store buffers in temp files to avoid excessive memory consumption. + stdout, err := ioutil.TempFile(dir, "stdout") + if err != nil { + return nil, errors.Wrap(err, "create file for stdout") + } - commands = append(commands, cmds...) - } + stderr, err := ioutil.TempFile(dir, "stderr") + if err != nil { + return nil, errors.Wrap(err, "create file for stderr") + } - // Run go routine for each command. - for _, c := range commands { - var stderr, stdout bytes.Buffer - if err := c.Start(&stdout, &stderr); err != nil { + stdFiles = append(stdFiles, stdout, stderr) + if err := c.Start(stdout, stderr); err != nil { // Let already started commands finish. go func() { _ = g.Run() }() - return nil, errors.Wrap(err, "failed to start") + return nil, errors.Wrap(err, "start") } cmd := c g.Add(func() error { - id := c.String() - - err := cmd.Wait() - - if stderr.Len() > 0 { - t.Logf("%s STDERR\n %s", id, stderr.String()) - } - if stdout.Len() > 0 { - t.Logf("%s STDOUT\n %s", id, stdout.String()) - } - - return errors.Wrap(err, id) + return errors.Wrap(cmd.Wait(), cmd.String()) }, func(error) { // This's accepted scenario to kill a process immediately for sure and run tests as fast as possible. _ = cmd.Kill() @@ -535,19 +562,22 @@ func (s *spinupSuite) Exec(t testing.TB, ctx context.Context, testName string) ( if err := g.Run(); err != nil && ctx.Err() == nil { t.Errorf("Some process exited unexpectedly: %v", err) } - if minioExit != nil { - <-minioExit + + if s3Exit != nil { + <-s3Exit } + + printAndCloseFiles(t, stdFiles) close(exit) }(g) return exit, nil } -func generateFileSD(addresses []string) string { +func generateFileSD(addresses []address) string { conf := "[ { \"targets\": [" for index, addr := range addresses { - conf += fmt.Sprintf("\"%s\"", addr) + conf += fmt.Sprintf("\"%s\"", addr.HostPort()) if index+1 < len(addresses) { conf += "," } @@ -556,42 +586,36 @@ func generateFileSD(addresses []string) string { return conf } -func generateHashringsFile(addresses []string) string { - conf := "[ { \"endpoints\": [" - for index, addr := range addresses { - conf += fmt.Sprintf("\"%s\"", addr) - if index+1 < len(addresses) { - conf += "," +func printAndCloseFiles(t testing.TB, files []*os.File) { + defer func() { + for _, f := range files { + _ = f.Close() } - } - conf += "] } ]" - return conf -} + }() -func defaultQuerierFlags(i int, replicaLabel string) []string { - return []string{ - "query", - "--debug.name", fmt.Sprintf("querier-%d", i), - "--grpc-address", queryGRPC(i), - "--http-address", queryHTTP(i), - "--log.level", "debug", - "--query.replica-label", replicaLabel, - "--store.sd-dns-interval", "5s", - } -} + for _, f := range files { + info, err := f.Stat() + if err != nil { + t.Error(err) + } + + if info.Size() == 0 { + continue + } -func defaultRulerFlags(i int, dbDir string, ruleDir string) []string { - return []string{ - "rule", - "--debug.name", fmt.Sprintf("rule-%d", i), - "--label", fmt.Sprintf(`replica="%d"`, i), - "--data-dir", dbDir, - "--rule-file", path.Join(ruleDir, "*.yaml"), - "--eval-interval", "1s", - "--alertmanagers.url", "http://127.0.0.1:29093", - "--grpc-address", rulerGRPC(i), - "--http-address", rulerHTTP(i), - "--log.level", "debug", - "--query.sd-dns-interval", "5s", + if _, err := f.Seek(0, 0); err != nil { + t.Error(err) + } + t.Logf("-------------------------------------------") + t.Logf("------------------- %s ------------------", f.Name()) + t.Logf("-------------------------------------------") + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + t.Log(scanner.Text()) + } + if err := scanner.Err(); err != nil { + t.Error(err) + } } } diff --git a/test/e2e/store_gateway_test.go b/test/e2e/store_gateway_test.go index 7f49d820ac..abf1b00b69 100644 --- a/test/e2e/store_gateway_test.go +++ b/test/e2e/store_gateway_test.go @@ -22,14 +22,15 @@ import ( yaml "gopkg.in/yaml.v2" ) -func TestStoreGatewayQuery(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) +func TestStoreGateway(t *testing.T) { + a := newLocalAddresser() + minioAddr := a.New() s3Config := s3.Config{ Bucket: "test-storegateway-query", AccessKey: "abc", SecretKey: "mightysecret", - Endpoint: minioHTTP(1), + Endpoint: minioAddr.HostPort(), Insecure: true, } @@ -41,11 +42,11 @@ func TestStoreGatewayQuery(t *testing.T) { config, err := yaml.Marshal(bucketConfig) testutil.Ok(t, err) - exit, err := newSpinupSuite(). - WithPreStartedMinio(s3Config). - Add(storeGateway(1, config)). - Add(querierWithStoreFlags(1, "replica", storeGatewayGRPC(1))). - Exec(t, ctx, "test_store_gateway_query") + s := storeGateway(a.New(), a.New(), config) + q := querier(a.New(), a.New(), []address{s.GRPC}, nil) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + + exit, err := e2eSpinupWithS3ObjStorage(t, ctx, minioAddr, &s3Config, s, q) if err != nil { t.Errorf("spinup failed: %v", err) cancel() @@ -97,7 +98,7 @@ func TestStoreGatewayQuery(t *testing.T) { err error warnings []string ) - res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "{a=\"1\"}", time.Now(), promclient.QueryOptions{ + res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), "{a=\"1\"}", time.Now(), promclient.QueryOptions{ Deduplicate: false, }) if err != nil { @@ -142,7 +143,7 @@ func TestStoreGatewayQuery(t *testing.T) { err error warnings []string ) - res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, "http://"+queryHTTP(1)), "{a=\"1\"}", time.Now(), promclient.QueryOptions{ + res, warnings, err = promclient.QueryInstant(ctx, nil, urlParse(t, q.HTTP.URL()), "{a=\"1\"}", time.Now(), promclient.QueryOptions{ Deduplicate: true, }) if err != nil {