From a65ae9a379d10f9ca8777c86a411bc1af82ee699 Mon Sep 17 00:00:00 2001 From: Alvin Lin Date: Fri, 12 Aug 2022 12:14:31 -0700 Subject: [PATCH] Build Cortex with Go 1.19 Signed-off-by: Alvin Lin --- .github/workflows/test-build-deploy.yml | 12 +-- .golangci.yml | 6 +- CHANGELOG.md | 1 + Makefile | 2 +- cmd/cortex/main_test.go | 3 +- cmd/thanosconvert/main.go | 3 +- .../how-to-run-website-locally.md | 11 +-- integration/asserts.go | 1 + integration/blocks_storage_backends_test.go | 1 + integration/e2e/scenario_test.go | 1 + integration/e2e/service_test.go | 1 + integration/e2ecortex/client.go | 9 +- ...ting_started_single_process_config_test.go | 1 + ...getting_started_with_gossiped_ring_test.go | 1 + integration/ingester_limits_test.go | 1 + integration/ingester_sharding_test.go | 1 + ...tegration_memberlist_single_binary_test.go | 1 + integration/querier_remote_read_test.go | 1 + integration/querier_sharding_test.go | 1 + integration/querier_tenant_federation_test.go | 1 + integration/querier_test.go | 1 + integration/query_frontend_test.go | 1 + integration/util.go | 1 + pkg/configs/db/db.go | 4 +- pkg/configs/legacy_promql/ast.go | 15 ++-- pkg/configs/legacy_promql/engine.go | 2 +- pkg/configs/legacy_promql/parse.go | 51 ++++------- pkg/configs/legacy_promql/test.go | 2 +- pkg/cortex/modules.go | 87 +++++++++---------- pkg/ingester/active_series.go | 4 +- pkg/ingester/ingester.go | 9 +- pkg/querier/astmapper/shard_summer.go | 2 +- pkg/querier/astmapper/subtree_folder.go | 1 - pkg/querier/error_translate_queryable.go | 8 +- pkg/ring/kv/etcd/mock.go | 10 +-- pkg/ruler/ruler.go | 1 + pkg/ruler/rulestore/local/local.go | 3 +- pkg/storage/tsdb/config.go | 6 +- pkg/tenant/resolver.go | 6 +- pkg/tenant/tenant.go | 3 +- pkg/util/log/log.go | 3 +- pkg/util/log/wrappers.go | 5 +- pkg/util/services/basic_service.go | 26 +++--- pkg/util/services/service.go | 23 +++-- pkg/util/validation/errors.go | 3 +- pkg/util/validation/limits_test.go | 3 +- 46 files changed, 175 insertions(+), 164 deletions(-) diff --git a/.github/workflows/test-build-deploy.yml b/.github/workflows/test-build-deploy.yml index 302551e73c..342bfc0b49 100644 --- a/.github/workflows/test-build-deploy.yml +++ b/.github/workflows/test-build-deploy.yml @@ -10,7 +10,7 @@ jobs: lint: runs-on: ubuntu-20.04 container: - image: quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd + image: quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -34,7 +34,7 @@ jobs: test: runs-on: ubuntu-20.04 container: - image: quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd + image: quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -48,7 +48,7 @@ jobs: build: runs-on: ubuntu-20.04 container: - image: quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd + image: quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -163,14 +163,14 @@ jobs: run: | touch build-image/.uptodate MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations - make BUILD_IMAGE=quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd TTY='' configs-integration-test + make BUILD_IMAGE=quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 TTY='' configs-integration-test deploy_website: needs: [build, test] if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex' runs-on: ubuntu-20.04 container: - image: quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd + image: quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -207,7 +207,7 @@ jobs: if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex' runs-on: ubuntu-20.04 container: - image: quay.io/cortexproject/build-image:update-hugo-0.94.x-96d1d7cdd + image: quay.io/cortexproject/build-image:update-go-1-19-a2f4d2c79 steps: - name: Checkout Repo uses: actions/checkout@v2 diff --git a/.golangci.yml b/.golangci.yml index 38334b935a..2d45dc696b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,12 +4,16 @@ output: linters: enable: - goimports - - golint + - revive - gofmt - misspell - depguard linters-settings: + staticcheck: + checks: + - all + - "-SA1019" # Disable because too many file uses io/ioutil now, will fix later errcheck: # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details diff --git a/CHANGELOG.md b/CHANGELOG.md index 5373265fa8..f4ed23e691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * [CHANGE] Disables TSDB isolation. #4825 * [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532 * [ENHANCEMENT] Ring: DoBatch prioritize 4xx errors when failing. #4783 +* [ENHANCEMENT] Cortex now built with Go 1.18. #4829 * [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784 * [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787 * [FEATURE] Compactor: Added configurations for Azure MSI in blocks-storage, ruler-storage and alertmanager-storage. #4818 diff --git a/Makefile b/Makefile index 2a658b8ffe..b347176353 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ build-image/$(UPTODATE): build-image/* SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E") BUILD_IN_CONTAINER := true BUILD_IMAGE ?= $(IMAGE_PREFIX)build-image -LATEST_BUILD_IMAGE_TAG ?= update-hugo-0.94.x-96d1d7cdd +LATEST_BUILD_IMAGE_TAG ?= update-go-1-19-a2f4d2c79 # TTY is parameterized to allow Google Cloud Builder to run builds, # as it currently disallows TTY devices. This value needs to be overridden diff --git a/cmd/cortex/main_test.go b/cmd/cortex/main_test.go index d5c5a14a1a..208e8ff02a 100644 --- a/cmd/cortex/main_test.go +++ b/cmd/cortex/main_test.go @@ -4,7 +4,6 @@ import ( "bytes" "flag" "io" - "io/ioutil" "os" "strings" "sync" @@ -111,7 +110,7 @@ func testSingle(t *testing.T, arguments []string, yaml string, stdoutMessage, st defer restoreIfNeeded() if yaml != "" { - tempFile, err := ioutil.TempFile("", "test") + tempFile, err := os.CreateTemp("", "test") require.NoError(t, err) defer func() { diff --git a/cmd/thanosconvert/main.go b/cmd/thanosconvert/main.go index 69242cd839..d37b3fa5e7 100644 --- a/cmd/thanosconvert/main.go +++ b/cmd/thanosconvert/main.go @@ -4,7 +4,6 @@ import ( "context" "flag" "fmt" - "io/ioutil" "os" "strings" @@ -42,7 +41,7 @@ func main() { } if configFilename != "" { - buf, err := ioutil.ReadFile(configFilename) + buf, err := os.ReadFile(configFilename) if err != nil { fatal("failed to load config file from %s: %v", configFilename, err) } diff --git a/docs/contributing/how-to-run-website-locally.md b/docs/contributing/how-to-run-website-locally.md index b06be563a1..cde307e582 100644 --- a/docs/contributing/how-to-run-website-locally.md +++ b/docs/contributing/how-to-run-website-locally.md @@ -12,17 +12,18 @@ The Cortex documentation is compiled into a website published at [cortexmetrics. The following initial setup is required only once: -1. Install [Hugo](https://gohugo.io/) `v0.94.2` (**extended** version) -2. Install [Node.js](https://nodejs.org/en/) `v14` or above (alternatively via [`nvm`](https://github.com/nvm-sh/nvm)) -3. Install required Node modules with: +1. Install [Hugo](https://gohugo.io/) (**extended** version) + * Look for value of `HUGO_VERSION` in `build-image/Dockerfile`. +1. Install [Node.js](https://nodejs.org/en/) `v14` or above (alternatively via [`nvm`](https://github.com/nvm-sh/nvm)) +1. Install required Node modules with: ``` cd website && npm install && cd - ``` -4. Install [embedmd](https://github.com/campoy/embedmd) `v1.0.0`: +1. Install [embedmd](https://github.com/campoy/embedmd) `v1.0.0`: ``` go install github.com/campoy/embedmd@v1.0.0 ``` -5. Run `make BUILD_IN_CONTAINER=false web-build` +1. Run `make BUILD_IN_CONTAINER=false web-build` ## Run it diff --git a/integration/asserts.go b/integration/asserts.go index 2958133ae9..bb07c4ee17 100644 --- a/integration/asserts.go +++ b/integration/asserts.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/blocks_storage_backends_test.go b/integration/blocks_storage_backends_test.go index 66b141b2d6..8fc93fe58f 100644 --- a/integration/blocks_storage_backends_test.go +++ b/integration/blocks_storage_backends_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/e2e/scenario_test.go b/integration/e2e/scenario_test.go index a31ed9d59b..15c018d0ed 100644 --- a/integration/e2e/scenario_test.go +++ b/integration/e2e/scenario_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package e2e_test diff --git a/integration/e2e/service_test.go b/integration/e2e/service_test.go index 0ecde7776e..38ffa353a2 100644 --- a/integration/e2e/service_test.go +++ b/integration/e2e/service_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package e2e diff --git a/integration/e2ecortex/client.go b/integration/e2ecortex/client.go index d8c416bddc..4971c6e99e 100644 --- a/integration/e2ecortex/client.go +++ b/integration/e2ecortex/client.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -171,7 +170,7 @@ func (c *Client) query(addr string) (*http.Response, []byte, error) { } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return nil, nil, err } @@ -234,7 +233,7 @@ func (c *Client) GetPrometheusRules() ([]*ruler.RuleGroup, error) { } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return nil, err } @@ -278,7 +277,7 @@ func (c *Client) GetRuleGroups() (map[string][]rulefmt.RuleGroup, error) { defer res.Body.Close() rgs := map[string][]rulefmt.RuleGroup{} - data, err := ioutil.ReadAll(res.Body) + data, err := io.ReadAll(res.Body) if err != nil { return nil, err } @@ -412,7 +411,7 @@ func (c *Client) getRawPage(ctx context.Context, url string) ([]byte, error) { } defer resp.Body.Close() - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/integration/getting_started_single_process_config_test.go b/integration/getting_started_single_process_config_test.go index fb46cf38c7..1cdf689790 100644 --- a/integration/getting_started_single_process_config_test.go +++ b/integration/getting_started_single_process_config_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/getting_started_with_gossiped_ring_test.go b/integration/getting_started_with_gossiped_ring_test.go index 0fc97c4d11..bc7dbd42c8 100644 --- a/integration/getting_started_with_gossiped_ring_test.go +++ b/integration/getting_started_with_gossiped_ring_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/ingester_limits_test.go b/integration/ingester_limits_test.go index a8ba64ab6d..e94c83d5bf 100644 --- a/integration/ingester_limits_test.go +++ b/integration/ingester_limits_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/ingester_sharding_test.go b/integration/ingester_sharding_test.go index 20a756c437..ab8e2ca06d 100644 --- a/integration/ingester_sharding_test.go +++ b/integration/ingester_sharding_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/integration_memberlist_single_binary_test.go b/integration/integration_memberlist_single_binary_test.go index 6dad2daf4e..4ca4d5a4e1 100644 --- a/integration/integration_memberlist_single_binary_test.go +++ b/integration/integration_memberlist_single_binary_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/querier_remote_read_test.go b/integration/querier_remote_read_test.go index 208c78fd02..0f80405d23 100644 --- a/integration/querier_remote_read_test.go +++ b/integration/querier_remote_read_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/querier_sharding_test.go b/integration/querier_sharding_test.go index 6695bdfa25..c4a14e3927 100644 --- a/integration/querier_sharding_test.go +++ b/integration/querier_sharding_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/querier_tenant_federation_test.go b/integration/querier_tenant_federation_test.go index cb4b33d50b..032edb48d6 100644 --- a/integration/querier_tenant_federation_test.go +++ b/integration/querier_tenant_federation_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/querier_test.go b/integration/querier_test.go index 71a8bb3f9a..ff3ff01d27 100644 --- a/integration/querier_test.go +++ b/integration/querier_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/query_frontend_test.go b/integration/query_frontend_test.go index db766177e8..556edb4b73 100644 --- a/integration/query_frontend_test.go +++ b/integration/query_frontend_test.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/integration/util.go b/integration/util.go index 81135977e3..d43785638e 100644 --- a/integration/util.go +++ b/integration/util.go @@ -1,3 +1,4 @@ +//go:build requires_docker // +build requires_docker package integration diff --git a/pkg/configs/db/db.go b/pkg/configs/db/db.go index 0ec290494c..4de9ef000b 100644 --- a/pkg/configs/db/db.go +++ b/pkg/configs/db/db.go @@ -4,8 +4,8 @@ import ( "context" "flag" "fmt" - "io/ioutil" "net/url" + "os" "github.com/cortexproject/cortex/pkg/configs/db/memory" "github.com/cortexproject/cortex/pkg/configs/db/postgres" @@ -73,7 +73,7 @@ func New(cfg Config) (DB, error) { if u.User == nil { return nil, fmt.Errorf("--database.password-file requires username in --database.uri") } - passwordBytes, err := ioutil.ReadFile(cfg.PasswordFile) + passwordBytes, err := os.ReadFile(cfg.PasswordFile) if err != nil { return nil, fmt.Errorf("Could not read database password file: %v", err) } diff --git a/pkg/configs/legacy_promql/ast.go b/pkg/configs/legacy_promql/ast.go index ca11657537..be05419373 100644 --- a/pkg/configs/legacy_promql/ast.go +++ b/pkg/configs/legacy_promql/ast.go @@ -10,7 +10,7 @@ // 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. -//nolint //Since this was copied from Prometheus leave it as is +// nolint //Since this was copied from Prometheus leave it as is package promql import ( @@ -27,13 +27,12 @@ import ( // or a chain of function definitions (e.g. String(), expr(), etc.) convention is // to list them as follows: // -// - Statements -// - statement types (alphabetical) -// - ... -// - Expressions -// - expression types (alphabetical) -// - ... -// +// - Statements +// - statement types (alphabetical) +// - ... +// - Expressions +// - expression types (alphabetical) +// - ... type Node interface { // String representation of the node that returns the given node when parsed // as part of a valid query. diff --git a/pkg/configs/legacy_promql/engine.go b/pkg/configs/legacy_promql/engine.go index 11f012d9a9..e9fc1212db 100644 --- a/pkg/configs/legacy_promql/engine.go +++ b/pkg/configs/legacy_promql/engine.go @@ -10,7 +10,7 @@ // 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. -//nolint //Since this was copied from Prometheus leave it as is +// nolint //Since this was copied from Prometheus leave it as is package promql import ( diff --git a/pkg/configs/legacy_promql/parse.go b/pkg/configs/legacy_promql/parse.go index 86a01d41ec..74162dc81b 100644 --- a/pkg/configs/legacy_promql/parse.go +++ b/pkg/configs/legacy_promql/parse.go @@ -10,7 +10,7 @@ // 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. -//nolint //Since this was copied from Prometheus leave it as is +// nolint //Since this was copied from Prometheus leave it as is package promql import ( @@ -352,8 +352,7 @@ func (p *parser) recover(errp *error) { // stmt parses any statement. // -// alertStatement | recordStatement -// +// alertStatement | recordStatement func (p *parser) stmt() Statement { switch tok := p.peek(); tok.typ { case itemAlert: @@ -367,10 +366,9 @@ func (p *parser) stmt() Statement { // alertStmt parses an alert rule. // -// ALERT name IF expr [FOR duration] -// [LABELS label_set] -// [ANNOTATIONS label_set] -// +// ALERT name IF expr [FOR duration] +// [LABELS label_set] +// [ANNOTATIONS label_set] func (p *parser) alertStmt() *AlertStmt { const ctx = "alert statement" @@ -540,8 +538,7 @@ func (p *parser) balance(lhs Expr, op ItemType, rhs Expr, vecMatching *VectorMat // unaryExpr parses a unary expression. // -// | | (+|-) | '(' ')' -// +// | | (+|-) | '(' ')' func (p *parser) unaryExpr() Expr { switch t := p.peek(); t.typ { case itemADD, itemSUB: @@ -595,8 +592,7 @@ func (p *parser) unaryExpr() Expr { // rangeSelector parses a Matrix (a.k.a. range) selector based on a given // Vector selector. // -// '[' ']' -// +// '[' ']' func (p *parser) rangeSelector(vs *VectorSelector) *MatrixSelector { const ctx = "range selector" p.next() @@ -635,8 +631,7 @@ func (p *parser) number(val string) float64 { // primaryExpr parses a primary expression. // -// | | | -// +// | | | func (p *parser) primaryExpr() Expr { switch t := p.next(); { case t.typ == itemNumber: @@ -673,8 +668,7 @@ func (p *parser) primaryExpr() Expr { // labels parses a list of labelnames. // -// '(' , ... ')' -// +// '(' , ... ')' func (p *parser) labels() []string { const ctx = "grouping opts" @@ -702,9 +696,8 @@ func (p *parser) labels() []string { // aggrExpr parses an aggregation expression. // -// () [by|without ] -// [by|without ] () -// +// () [by|without ] +// [by|without ] () func (p *parser) aggrExpr() *AggregateExpr { const ctx = "aggregation" @@ -759,8 +752,7 @@ func (p *parser) aggrExpr() *AggregateExpr { // call parses a function call. // -// '(' [ , ...] ')' -// +// '(' [ , ...] ')' func (p *parser) call(name string) *Call { const ctx = "function call" @@ -796,8 +788,7 @@ func (p *parser) call(name string) *Call { // labelSet parses a set of label matchers // -// '{' [ '=' , ... ] '}' -// +// '{' [ '=' , ... ] '}' func (p *parser) labelSet() labels.Labels { set := []labels.Label{} for _, lm := range p.labelMatchers(itemEQL) { @@ -808,8 +799,7 @@ func (p *parser) labelSet() labels.Labels { // labelMatchers parses a set of label matchers. // -// '{' [ , ... ] '}' -// +// '{' [ , ... ] '}' func (p *parser) labelMatchers(operators ...ItemType) []*labels.Matcher { const ctx = "label matching" @@ -887,9 +877,8 @@ func (p *parser) labelMatchers(operators ...ItemType) []*labels.Matcher { // metric parses a metric. // -// -// [] -// +// +// [] func (p *parser) metric() labels.Labels { name := "" var m labels.Labels @@ -914,8 +903,7 @@ func (p *parser) metric() labels.Labels { // offset parses an offset modifier. // -// offset -// +// offset func (p *parser) offset() time.Duration { const ctx = "offset" @@ -932,9 +920,8 @@ func (p *parser) offset() time.Duration { // VectorSelector parses a new (instant) vector selector. // -// [] -// [] -// +// [] +// [] func (p *parser) VectorSelector(name string) *VectorSelector { var matchers []*labels.Matcher // Parse label matching if any. diff --git a/pkg/configs/legacy_promql/test.go b/pkg/configs/legacy_promql/test.go index 1c823d78b8..e13aa0cba9 100644 --- a/pkg/configs/legacy_promql/test.go +++ b/pkg/configs/legacy_promql/test.go @@ -10,7 +10,7 @@ // 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. -//nolint //Since this was copied from Prometheus leave it as is +// nolint //Since this was copied from Prometheus leave it as is package promql import ( diff --git a/pkg/cortex/modules.go b/pkg/cortex/modules.go index 288730d8f6..c7da7edacb 100644 --- a/pkg/cortex/modules.go +++ b/pkg/cortex/modules.go @@ -237,53 +237,52 @@ func (t *Cortex) initTenantFederation() (serv services.Service, err error) { // initQuerier registers an internal HTTP router with a Prometheus API backed by the // Cortex Queryable. Then it does one of the following: // -// 1. Query-Frontend Enabled: If Cortex has an All or QueryFrontend target, the internal -// HTTP router is wrapped with Tenant ID parsing middleware and passed to the frontend -// worker. +// 1. Query-Frontend Enabled: If Cortex has an All or QueryFrontend target, the internal +// HTTP router is wrapped with Tenant ID parsing middleware and passed to the frontend +// worker. // -// 2. Querier Standalone: The querier will register the internal HTTP router with the external -// HTTP router for the Prometheus API routes. Then the external HTTP server will be passed -// as a http.Handler to the frontend worker. +// 2. Querier Standalone: The querier will register the internal HTTP router with the external +// HTTP router for the Prometheus API routes. Then the external HTTP server will be passed +// as a http.Handler to the frontend worker. // // Route Diagram: // -// │ query -// │ request -// │ -// ▼ -// ┌──────────────────┐ QF to ┌──────────────────┐ -// │ external HTTP │ Worker │ │ -// │ router │──────────────▶│ frontend worker │ -// │ │ │ │ -// └──────────────────┘ └──────────────────┘ -// │ │ -// │ -// only in │ │ -// microservice ┌──────────────────┐ │ -// querier │ │ internal Querier │ │ -// ─ ─ ─ ─▶│ router │◀─────┘ -// │ │ -// └──────────────────┘ -// │ -// │ -// /metadata & /chunk ┌─────────────────────┼─────────────────────┐ -// requests │ │ │ -// │ │ │ -// ▼ ▼ ▼ -// ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ -// │ │ │ │ │ │ -// │Querier Queryable │ │ /api/v1 router │ │ /api/prom router │ -// │ │ │ │ │ │ -// └──────────────────┘ └──────────────────┘ └──────────────────┘ -// ▲ │ │ -// │ └──────────┬──────────┘ -// │ ▼ -// │ ┌──────────────────┐ -// │ │ │ -// └──────────────────────│ Prometheus API │ -// │ │ -// └──────────────────┘ -// +// │ query +// │ request +// │ +// ▼ +// ┌──────────────────┐ QF to ┌──────────────────┐ +// │ external HTTP │ Worker │ │ +// │ router │──────────────▶│ frontend worker │ +// │ │ │ │ +// └──────────────────┘ └──────────────────┘ +// │ │ +// │ +// only in │ │ +// microservice ┌──────────────────┐ │ +// querier │ │ internal Querier │ │ +// ─ ─ ─ ─▶│ router │◀─────┘ +// │ │ +// └──────────────────┘ +// │ +// │ +// /metadata & /chunk ┌─────────────────────┼─────────────────────┐ +// requests │ │ │ +// │ │ │ +// ▼ ▼ ▼ +// ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ +// │ │ │ │ │ │ +// │Querier Queryable │ │ /api/v1 router │ │ /api/prom router │ +// │ │ │ │ │ │ +// └──────────────────┘ └──────────────────┘ └──────────────────┘ +// ▲ │ │ +// │ └──────────┬──────────┘ +// │ ▼ +// │ ┌──────────────────┐ +// │ │ │ +// └──────────────────────│ Prometheus API │ +// │ │ +// └──────────────────┘ func (t *Cortex) initQuerier() (serv services.Service, err error) { // Create a internal HTTP handler that is configured with the Prometheus API routes and points // to a Prometheus API struct instantiated with the Cortex Queryable. @@ -341,7 +340,7 @@ func (t *Cortex) initQuerier() (serv services.Service, err error) { func (t *Cortex) initStoreQueryables() (services.Service, error) { var servs []services.Service - //nolint:golint // I prefer this form over removing 'else', because it allows q to have smaller scope. + //nolint:revive // I prefer this form over removing 'else', because it allows q to have smaller scope. if q, err := initQueryableForEngine(t.Cfg, t.Overrides, prometheus.DefaultRegisterer); err != nil { return nil, fmt.Errorf("failed to initialize querier: %v", err) } else { diff --git a/pkg/ingester/active_series.go b/pkg/ingester/active_series.go index 6b7655364a..4e2d0e6e59 100644 --- a/pkg/ingester/active_series.go +++ b/pkg/ingester/active_series.go @@ -87,7 +87,7 @@ func (c *ActiveSeries) Purge(keepUntil time.Time) { } } -//nolint // Linter reports that this method is unused, but it is. +// nolint // Linter reports that this method is unused, but it is. func (c *ActiveSeries) clear() { for s := 0; s < numActiveSeriesStripes; s++ { c.stripes[s].clear() @@ -164,7 +164,7 @@ func (s *activeSeriesStripe) findOrCreateEntryForSeries(fingerprint uint64, seri return e.nanos, true } -//nolint // Linter reports that this method is unused, but it is. +// nolint // Linter reports that this method is unused, but it is. func (s *activeSeriesStripe) clear() { s.mu.Lock() defer s.mu.Unlock() diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index de377d50c0..a7537a7f09 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -666,8 +666,9 @@ func New(cfg Config, limits *validation.Overrides, registerer prometheus.Registe // NewForFlusher constructs a new Ingester to be used by flusher target. // Compared to the 'New' method: -// * Always replays the WAL. -// * Does not start the lifecycler. +// - Always replays the WAL. +// - Does not start the lifecycler. +// // this is a special version of ingester used by Flusher. This ingester is not ingesting anything, its only purpose is to react // on Flush method and flush all openened TSDBs when called. func NewForFlusher(cfg Config, limits *validation.Overrides, registerer prometheus.Registerer, logger log.Logger) (*Ingester, error) { @@ -840,8 +841,8 @@ func (i *Ingester) updateActiveSeries() { } // ShutdownHandler triggers the following set of operations in order: -// * Change the state of ring to stop accepting writes. -// * Flush all the chunks. +// - Change the state of ring to stop accepting writes. +// - Flush all the chunks. func (i *Ingester) ShutdownHandler(w http.ResponseWriter, _ *http.Request) { originalFlush := i.lifecycler.FlushOnShutdown() // We want to flush the chunks if transfer fails irrespective of original flag. diff --git a/pkg/querier/astmapper/shard_summer.go b/pkg/querier/astmapper/shard_summer.go index 50a276a902..681399d09f 100644 --- a/pkg/querier/astmapper/shard_summer.go +++ b/pkg/querier/astmapper/shard_summer.go @@ -207,7 +207,7 @@ func (summer *shardSummer) splitSum( // ShardSummer is explicitly passed a prometheus.Counter during construction // in order to prevent duplicate metric registerings (ShardSummers are created per request). -//recordShards prevents calling nil interfaces (commonly used in tests). +// recordShards prevents calling nil interfaces (commonly used in tests). func (summer *shardSummer) recordShards(n float64) { if summer.shardedQueries != nil { summer.shardedQueries.Add(float64(summer.shards)) diff --git a/pkg/querier/astmapper/subtree_folder.go b/pkg/querier/astmapper/subtree_folder.go index 2e78bb468f..4e17ea9309 100644 --- a/pkg/querier/astmapper/subtree_folder.go +++ b/pkg/querier/astmapper/subtree_folder.go @@ -8,7 +8,6 @@ import ( subtreeFolder is a NodeMapper which embeds an entire parser.Node in an embedded query if it does not contain any previously embedded queries. This allows the frontend to "zip up" entire subtrees of an AST that have not already been parallelized. - */ type subtreeFolder struct{} diff --git a/pkg/querier/error_translate_queryable.go b/pkg/querier/error_translate_queryable.go index 174071aff6..43ace739b5 100644 --- a/pkg/querier/error_translate_queryable.go +++ b/pkg/querier/error_translate_queryable.go @@ -17,10 +17,10 @@ import ( // // Specifically, it supports: // -// promql.ErrQueryCanceled, mapped to 503 -// promql.ErrQueryTimeout, mapped to 503 -// promql.ErrStorage mapped to 500 -// anything else is mapped to 422 +// promql.ErrQueryCanceled, mapped to 503 +// promql.ErrQueryTimeout, mapped to 503 +// promql.ErrStorage mapped to 500 +// anything else is mapped to 422 // // Querier code produces different kinds of errors, and we want to map them to above-mentioned HTTP status codes correctly. // diff --git a/pkg/ring/kv/etcd/mock.go b/pkg/ring/kv/etcd/mock.go index 823dcb4b43..7d307440d5 100644 --- a/pkg/ring/kv/etcd/mock.go +++ b/pkg/ring/kv/etcd/mock.go @@ -62,11 +62,11 @@ func newMockKV() *mockKV { // // Known limitations: // -// * Compact is not implemented and will panic -// * RequestProgress is not implemented and will panic -// * Only exact and prefix matching is supported for Get, Put, and Delete -// * There may be inconsistencies with how various version numbers are adjusted -// but none that are exposed by kv.Client unit tests +// - Compact is not implemented and will panic +// - RequestProgress is not implemented and will panic +// - Only exact and prefix matching is supported for Get, Put, and Delete +// - There may be inconsistencies with how various version numbers are adjusted +// but none that are exposed by kv.Client unit tests type mockKV struct { // Key-value pairs created by put calls or transactions values map[string]mvccpb.KeyValue diff --git a/pkg/ruler/ruler.go b/pkg/ruler/ruler.go index 3884a6d5b2..db565afa9b 100644 --- a/pkg/ruler/ruler.go +++ b/pkg/ruler/ruler.go @@ -201,6 +201,7 @@ type MultiTenantManager interface { } // Ruler evaluates rules. +// // +---------------------------------------------------------------+ // | | // | Query +-------------+ | diff --git a/pkg/ruler/rulestore/local/local.go b/pkg/ruler/rulestore/local/local.go index 080e294147..f31612e823 100644 --- a/pkg/ruler/rulestore/local/local.go +++ b/pkg/ruler/rulestore/local/local.go @@ -27,7 +27,8 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { } // Client expects to load already existing rules located at: -// cfg.Directory / userID / namespace +// +// cfg.Directory / userID / namespace type Client struct { cfg Config loader promRules.GroupLoader diff --git a/pkg/storage/tsdb/config.go b/pkg/storage/tsdb/config.go index 45bfcc48e4..2fcc0cded1 100644 --- a/pkg/storage/tsdb/config.go +++ b/pkg/storage/tsdb/config.go @@ -53,7 +53,8 @@ var ( ) // BlocksStorageConfig holds the config information for the blocks storage. -//nolint:golint +// +//nolint:revive type BlocksStorageConfig struct { Bucket bucket.Config `yaml:",inline"` BucketStore BucketStoreConfig `yaml:"bucket_store" doc:"description=This configures how the querier and store-gateway discover and synchronize blocks stored in the bucket."` @@ -118,7 +119,8 @@ func (cfg *BlocksStorageConfig) Validate() error { } // TSDBConfig holds the config for TSDB opened in the ingesters. -//nolint:golint +// +//nolint:revive type TSDBConfig struct { Dir string `yaml:"dir"` BlockRanges DurationList `yaml:"block_ranges_period"` diff --git a/pkg/tenant/resolver.go b/pkg/tenant/resolver.go index 72517b082f..f0fd8abfea 100644 --- a/pkg/tenant/resolver.go +++ b/pkg/tenant/resolver.go @@ -22,7 +22,8 @@ func WithDefaultResolver(r Resolver) { // supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present. // // ignore stutter warning -//nolint:golint +// +//nolint:revive func TenantID(ctx context.Context) (string, error) { return defaultResolver.TenantID(ctx) } @@ -32,7 +33,8 @@ func TenantID(ctx context.Context) (string, error) { // NormalizeTenantIDs). // // ignore stutter warning -//nolint:golint +// +//nolint:revive func TenantIDs(ctx context.Context) ([]string, error) { return defaultResolver.TenantIDs(ctx) } diff --git a/pkg/tenant/tenant.go b/pkg/tenant/tenant.go index fa80898907..c7c772648c 100644 --- a/pkg/tenant/tenant.go +++ b/pkg/tenant/tenant.go @@ -99,7 +99,8 @@ func isSupported(c rune) bool { // TenantIDsFromOrgID extracts different tenants from an orgID string value // // ignore stutter warning -//nolint:golint +// +//nolint:revive func TenantIDsFromOrgID(orgID string) ([]string, error) { return TenantIDs(user.InjectOrgID(context.TODO(), orgID)) } diff --git a/pkg/util/log/log.go b/pkg/util/log/log.go index ce937e93fb..a254c4bbd9 100644 --- a/pkg/util/log/log.go +++ b/pkg/util/log/log.go @@ -109,7 +109,8 @@ func CheckFatal(location string, err error) { } // TODO(dannyk): remove once weaveworks/common updates to go-kit/log -// -> we can then revert to using Level.Gokit +// +// -> we can then revert to using Level.Gokit func LevelFilter(l string) level.Option { switch l { case "debug": diff --git a/pkg/util/log/wrappers.go b/pkg/util/log/wrappers.go index f7307cccd6..a155b93ee7 100644 --- a/pkg/util/log/wrappers.go +++ b/pkg/util/log/wrappers.go @@ -28,8 +28,9 @@ func WithTraceID(traceID string, l kitlog.Logger) kitlog.Logger { // its details. // // e.g. -// log := util.WithContext(ctx) -// log.Errorf("Could not chunk chunks: %v", err) +// +// log := util.WithContext(ctx) +// log.Errorf("Could not chunk chunks: %v", err) func WithContext(ctx context.Context, l kitlog.Logger) kitlog.Logger { // Weaveworks uses "orgs" and "orgID" to represent Cortex users, // even though the code-base generally uses `userID` to refer to the same thing. diff --git a/pkg/util/services/basic_service.go b/pkg/util/services/basic_service.go index ead611a3f9..017ed16a16 100644 --- a/pkg/util/services/basic_service.go +++ b/pkg/util/services/basic_service.go @@ -255,20 +255,20 @@ func (b *BasicService) StopAsync() { // // Example: // -// func (s *exampleService) Send(msg string) bool { -// ctx := s.ServiceContext() -// if ctx == nil { -// // Service is not yet started -// return false -// } -// select { -// case s.ch <- msg: -// return true -// case <-ctx.Done(): -// // Service is not running anymore. -// return false -// } +// func (s *exampleService) Send(msg string) bool { +// ctx := s.ServiceContext() +// if ctx == nil { +// // Service is not yet started +// return false // } +// select { +// case s.ch <- msg: +// return true +// case <-ctx.Done(): +// // Service is not running anymore. +// return false +// } +// } // // This is not part of Service interface, and clients of the Service should not use it. func (b *BasicService) ServiceContext() context.Context { diff --git a/pkg/util/services/service.go b/pkg/util/services/service.go index c559ef96a3..7795e02326 100644 --- a/pkg/util/services/service.go +++ b/pkg/util/services/service.go @@ -41,18 +41,17 @@ func (s State) String() string { // // State diagram for the service: // -// ┌────────────────────────────────────────────────────────────────────┐ -// │ │ -// │ ▼ -// ┌─────┐ ┌──────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐ -// │ New │─────▶│ Starting │─────▶│ Running │────▶│ Stopping │───┬─▶│ Terminated │ -// └─────┘ └──────────┘ └─────────┘ └──────────┘ │ └────────────┘ -// │ │ -// │ │ -// │ │ ┌────────┐ -// └──────────────────────────────────────────┴──▶│ Failed │ -// └────────┘ -// +// ┌────────────────────────────────────────────────────────────────────┐ +// │ │ +// │ ▼ +// ┌─────┐ ┌──────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐ +// │ New │─────▶│ Starting │─────▶│ Running │────▶│ Stopping │───┬─▶│ Terminated │ +// └─────┘ └──────────┘ └─────────┘ └──────────┘ │ └────────────┘ +// │ │ +// │ │ +// │ │ ┌────────┐ +// └──────────────────────────────────────────┴──▶│ Failed │ +// └────────┘ type Service interface { // StartAsync starts Service asynchronously. Service must be in New State, otherwise error is returned. // Context is used as a parent context for service own context. diff --git a/pkg/util/validation/errors.go b/pkg/util/validation/errors.go index efe738d8fb..d4b490b9b5 100644 --- a/pkg/util/validation/errors.go +++ b/pkg/util/validation/errors.go @@ -12,7 +12,8 @@ import ( // ValidationError is an error returned by series validation. // -// nolint:golint ignore stutter warning +// Ignore stutter warning. +// nolint:revive type ValidationError error // genericValidationError is a basic implementation of ValidationError which can be used when the diff --git a/pkg/util/validation/limits_test.go b/pkg/util/validation/limits_test.go index 5560bb37d1..09b46aba9c 100644 --- a/pkg/util/validation/limits_test.go +++ b/pkg/util/validation/limits_test.go @@ -95,8 +95,7 @@ func TestOverridesManager_GetOverrides(t *testing.T) { // Update limits for tenant user1. We only update single field, the rest is copied from defaults. // (That is how limits work when loaded from YAML) - l := Limits{} - l = defaults + l := defaults l.MaxLabelValueLength = 150 tenantLimits["user1"] = &l