diff --git a/.golangci.yml b/.golangci.yml index 4632d5a844..22c89a6beb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,7 +47,7 @@ linters: exclusions: paths: # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ + - ^.*\.(l|pb|y)\.go$ rules: - linters: - errcheck @@ -76,7 +76,7 @@ linters: source: "^// ===" - linters: - staticcheck - text: 'v1\.(Endpoints|EndpointSubset|EndpointPort|EndpointAddress) is deprecated: This API is deprecated in v1.33+' + text: '(labels.MetricName|v1\.(Endpoints|EndpointSubset|EndpointPort|EndpointAddress)) is deprecated: .*' warn-unused: true settings: depguard: @@ -128,6 +128,8 @@ linters: sprintf1: true # Optimizes into strings concatenation. strconcat: false + # Disable optimization of concat loop. + concat-loop: false revive: # By default, revive will enable only the linting rules that are named in the configuration file. # So, it's needed to explicitly enable all required rules here. diff --git a/Makefile.common b/Makefile.common index 6762d0f830..143bf03fbc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v2.4.0 +GOLANGCI_LINT_VERSION ?= v2.6.0 GOLANGCI_FMT_OPTS ?= # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index a6d8b352e3..460e47fd25 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -928,15 +928,16 @@ func checkRuleGroups(rgs *rulefmt.RuleGroups, lintSettings rulesLintConfig) (int if lintSettings.lintDuplicateRules() { dRules := checkDuplicates(rgs.Groups) if len(dRules) != 0 { - errMessage := fmt.Sprintf("%d duplicate rule(s) found.\n", len(dRules)) + var errMessage strings.Builder + errMessage.WriteString(fmt.Sprintf("%d duplicate rule(s) found.\n", len(dRules))) for _, n := range dRules { - errMessage += fmt.Sprintf("Metric: %s\nLabel(s):\n", n.metric) + errMessage.WriteString(fmt.Sprintf("Metric: %s\nLabel(s):\n", n.metric)) n.label.Range(func(l labels.Label) { - errMessage += fmt.Sprintf("\t%s: %s\n", l.Name, l.Value) + errMessage.WriteString(fmt.Sprintf("\t%s: %s\n", l.Name, l.Value)) }) } - errMessage += "Might cause inconsistency while recording expressions" - return 0, []error{fmt.Errorf("%w %s", errLint, errMessage)} + errMessage.WriteString("Might cause inconsistency while recording expressions") + return 0, []error{fmt.Errorf("%w %s", errLint, errMessage.String())} } } diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index da14c5d809..1da95e862c 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -799,7 +799,7 @@ func formatSeriesSetOpenMetrics(ss storage.SeriesSet) error { series := ss.At() lbs := series.Labels() metricName := lbs.Get(labels.MetricName) - lbs = lbs.DropMetricName() + lbs = lbs.DropReserved(func(n string) bool { return n == labels.MetricName }) it := series.Iterator(nil) for it.Next() == chunkenc.ValFloat { ts, val := it.At() @@ -889,5 +889,5 @@ func generateBucket(minVal, maxVal int) (start, end, step int) { start = minVal - minVal%step end = maxVal - maxVal%step + step - return + return start, end, step } diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 500f46c9ca..15b5171645 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -527,11 +527,12 @@ Outer: // seriesLoadingString returns the input series in PromQL notation. func (tg *testGroup) seriesLoadingString() string { - result := fmt.Sprintf("load %v\n", shortDuration(tg.Interval)) + var result strings.Builder + result.WriteString(fmt.Sprintf("load %v\n", shortDuration(tg.Interval))) for _, is := range tg.InputSeries { - result += fmt.Sprintf(" %v %v\n", is.Series, is.Values) + result.WriteString(fmt.Sprintf(" %v %v\n", is.Series, is.Values)) } - return result + return result.String() } func shortDuration(d model.Duration) string { diff --git a/discovery/azure/azure_test.go b/discovery/azure/azure_test.go index 69c815da2d..a88738da9f 100644 --- a/discovery/azure/azure_test.go +++ b/discovery/azure/azure_test.go @@ -725,11 +725,11 @@ func defaultMockInterfaceServer(interfaceResp armnetwork.Interface) fakenetwork. return fakenetwork.InterfacesServer{ Get: func(context.Context, string, string, *armnetwork.InterfacesClientGetOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetResponse], errResp azfake.ErrorResponder) { resp.SetResponse(http.StatusOK, armnetwork.InterfacesClientGetResponse{Interface: interfaceResp}, nil) - return + return resp, errResp }, GetVirtualMachineScaleSetNetworkInterface: func(context.Context, string, string, string, string, *armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse], errResp azfake.ErrorResponder) { resp.SetResponse(http.StatusOK, armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{Interface: interfaceResp}, nil) - return + return resp, errResp }, } } @@ -740,7 +740,7 @@ func defaultMockVMServer(vmResp []armcompute.VirtualMachinesClientListAllRespons for _, page := range vmResp { resp.AddPage(http.StatusOK, page, nil) } - return + return resp }, } } @@ -751,7 +751,7 @@ func defaultMockVMSSServer(vmssResp []armcompute.VirtualMachineScaleSetsClientLi for _, page := range vmssResp { resp.AddPage(http.StatusOK, page, nil) } - return + return resp }, } } @@ -762,7 +762,7 @@ func defaultMockVMSSVMServer(vmssvmResp []armcompute.VirtualMachineScaleSetVMsCl for _, page := range vmssvmResp { resp.AddPage(http.StatusOK, page, nil) } - return + return resp }, } } diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index b221201744..21c401da2c 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -32,6 +32,7 @@ import ( ) // Endpoints discovers new endpoint targets. +// // Deprecated: The Endpoints API is deprecated starting in K8s v1.33+. Use EndpointSlice. type Endpoints struct { logger *slog.Logger @@ -52,6 +53,7 @@ type Endpoints struct { } // NewEndpoints returns a new endpoints discovery. +// // Deprecated: The Endpoints API is deprecated starting in K8s v1.33+. Use NewEndpointSlice. func NewEndpoints(l *slog.Logger, eps cache.SharedIndexInformer, svc, pod, node, namespace cache.SharedInformer, eventCount *prometheus.CounterVec) *Endpoints { if l == nil { diff --git a/model/labels/labels_common.go b/model/labels/labels_common.go index e27da94a47..5a3979784c 100644 --- a/model/labels/labels_common.go +++ b/model/labels/labels_common.go @@ -25,6 +25,7 @@ import ( const ( // MetricName is a special label name that represent a metric name. + // // Deprecated: Use schema.Metadata structure and its methods. MetricName = "__name__" diff --git a/model/labels/labels_dedupelabels.go b/model/labels/labels_dedupelabels.go index 04526b84d3..1e736c832e 100644 --- a/model/labels/labels_dedupelabels.go +++ b/model/labels/labels_dedupelabels.go @@ -562,6 +562,7 @@ func (Labels) ReleaseStrings(func(string)) { } // DropMetricName returns Labels with the "__name__" removed. +// // Deprecated: Use DropReserved instead. func (ls Labels) DropMetricName() Labels { return ls.DropReserved(func(n string) bool { return n == MetricName }) diff --git a/model/labels/labels_slicelabels.go b/model/labels/labels_slicelabels.go index 338cd47b68..21ad145c1c 100644 --- a/model/labels/labels_slicelabels.go +++ b/model/labels/labels_slicelabels.go @@ -349,6 +349,7 @@ func (ls Labels) Validate(f func(l Label) error) error { } // DropMetricName returns Labels with the "__name__" removed. +// // Deprecated: Use DropReserved instead. func (ls Labels) DropMetricName() Labels { return ls.DropReserved(func(n string) bool { return n == MetricName }) diff --git a/model/labels/labels_stringlabels.go b/model/labels/labels_stringlabels.go index 68277f64f7..f087223802 100644 --- a/model/labels/labels_stringlabels.go +++ b/model/labels/labels_stringlabels.go @@ -421,6 +421,7 @@ func (ls Labels) Validate(f func(l Label) error) error { } // DropMetricName returns Labels with the "__name__" removed. +// // Deprecated: Use DropReserved instead. func (ls Labels) DropMetricName() Labels { return ls.DropReserved(func(n string) bool { return n == MetricName }) diff --git a/model/labels/regexp.go b/model/labels/regexp.go index dfab677031..47b50e703a 100644 --- a/model/labels/regexp.go +++ b/model/labels/regexp.go @@ -370,7 +370,7 @@ func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix string, contains []st } if len(sub) == 0 { - return + return prefix, suffix, contains } // Given Prometheus regex matchers are always anchored to the begin/end @@ -391,7 +391,7 @@ func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix string, contains []st } } - return + return prefix, suffix, contains } // StringMatcher is a matcher that matches a string in place of a regular expression. diff --git a/model/labels/regexp_test.go b/model/labels/regexp_test.go index efb511fcc5..94ef14028b 100644 --- a/model/labels/regexp_test.go +++ b/model/labels/regexp_test.go @@ -988,7 +988,7 @@ func TestFindEqualOrPrefixStringMatchers(t *testing.T) { return true }) - return + return matches, ok } t.Run("empty matcher", func(t *testing.T) { diff --git a/model/rulefmt/rulefmt.go b/model/rulefmt/rulefmt.go index 68681d6ac0..83203ba769 100644 --- a/model/rulefmt/rulefmt.go +++ b/model/rulefmt/rulefmt.go @@ -100,7 +100,7 @@ type ruleGroups struct { func (g *RuleGroups) Validate(node ruleGroups, nameValidationScheme model.ValidationScheme) (errs []error) { if err := namevalidationutil.CheckNameValidationScheme(nameValidationScheme); err != nil { errs = append(errs, err) - return + return errs } set := map[string]struct{}{} @@ -286,7 +286,7 @@ func (r *Rule) Validate(node RuleNode, nameValidationScheme model.ValidationSche nodes = append(nodes, WrappedError{err: err}) } - return + return nodes } // testTemplateParsing checks if the templates used in labels and annotations diff --git a/model/textparse/nhcbparse.go b/model/textparse/nhcbparse.go index d820a0f8b1..8ec541de8a 100644 --- a/model/textparse/nhcbparse.go +++ b/model/textparse/nhcbparse.go @@ -373,7 +373,7 @@ func (p *NHCBParser) processNHCB() bool { p.fhNHCB = fh } - lblsWithMetricName := p.tempLsetNHCB.DropMetricName() + lblsWithMetricName := p.tempLsetNHCB.DropReserved(func(n string) bool { return n == labels.MetricName }) // Ensure we return `metric` instead of `metric{}` for name only // series, for consistency with wrapped parsers. if lblsWithMetricName.IsEmpty() { diff --git a/model/textparse/openmetricslex.l.go b/model/textparse/openmetricslex.l.go index c0b2fcdb4d..a99bb9df8e 100644 --- a/model/textparse/openmetricslex.l.go +++ b/model/textparse/openmetricslex.l.go @@ -74,10 +74,10 @@ yystart1: yystate2: c = l.next() - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate3 } @@ -101,43 +101,43 @@ yystate5: yystate6: c = l.next() yystart6: - switch { + switch c { default: goto yyabort - case c == 'E': + case 'E': goto yystate7 - case c == 'H': + case 'H': goto yystate11 - case c == 'T': + case 'T': goto yystate16 - case c == 'U': + case 'U': goto yystate21 } yystate7: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'O': + case 'O': goto yystate8 } yystate8: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'F': + case 'F': goto yystate9 } yystate9: c = l.next() - switch { + switch c { default: goto yyrule5 - case c == '\n': + case '\n': goto yystate10 } @@ -147,37 +147,37 @@ yystate10: yystate11: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'E': + case 'E': goto yystate12 } yystate12: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'L': + case 'L': goto yystate13 } yystate13: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'P': + case 'P': goto yystate14 } yystate14: c = l.next() - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate15 } @@ -187,37 +187,37 @@ yystate15: yystate16: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'Y': + case 'Y': goto yystate17 } yystate17: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'P': + case 'P': goto yystate18 } yystate18: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'E': + case 'E': goto yystate19 } yystate19: c = l.next() - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate20 } @@ -227,37 +227,37 @@ yystate20: yystate21: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'N': + case 'N': goto yystate22 } yystate22: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'I': + case 'I': goto yystate23 } yystate23: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'T': + case 'T': goto yystate24 } yystate24: c = l.next() - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate25 } @@ -315,10 +315,10 @@ yystate30: yystate31: c = l.next() yystart31: - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate32 } @@ -405,10 +405,10 @@ yystate41: yystate42: c = l.next() yystart42: - switch { + switch c { default: goto yyabort - case c == '"': + case '"': goto yystate43 } @@ -441,12 +441,12 @@ yystate45: yystate46: c = l.next() yystart46: - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate47 - case c == '{': + case '{': goto yystate49 } @@ -475,12 +475,12 @@ yystate49: yystate50: c = l.next() yystart50: - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate52 - case c == '\n': + case '\n': goto yystate51 } @@ -521,10 +521,10 @@ yystate54: yystate55: c = l.next() - switch { + switch c { default: goto yyabort - case c == '{': + case '{': goto yystate56 } @@ -600,12 +600,12 @@ yystate64: yystate65: c = l.next() yystart65: - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate66 - case c == '"': + case '"': goto yystate68 } @@ -656,12 +656,12 @@ yystate70: yystate71: c = l.next() yystart71: - switch { + switch c { default: goto yyabort - case c == ' ': + case ' ': goto yystate73 - case c == '\n': + case '\n': goto yystate72 } @@ -696,61 +696,61 @@ yyrule2: // HELP{S} { l.state = sMeta1 return tHelp - goto yystate0 + } yyrule3: // TYPE{S} { l.state = sMeta1 return tType - goto yystate0 + } yyrule4: // UNIT{S} { l.state = sMeta1 return tUnit - goto yystate0 + } yyrule5: // "EOF"\n? { l.state = sInit return tEOFWord - goto yystate0 + } yyrule6: // \"(\\.|[^\\"])*\" { l.state = sMeta2 return tMName - goto yystate0 + } yyrule7: // {M}({M}|{D})* { l.state = sMeta2 return tMName - goto yystate0 + } yyrule8: // {S}{C}*\n { l.state = sInit return tText - goto yystate0 + } yyrule9: // {M}({M}|{D})* { l.state = sValue return tMName - goto yystate0 + } yyrule10: // \{ { l.state = sLabels return tBraceOpen - goto yystate0 + } yyrule11: // \{ { l.state = sLabels return tBraceOpen - goto yystate0 + } yyrule12: // {L}({L}|{D})* { @@ -760,19 +760,19 @@ yyrule13: // \"(\\.|[^\\"])*\" { l.state = sLabels return tQString - goto yystate0 + } yyrule14: // \} { l.state = sValue return tBraceClose - goto yystate0 + } yyrule15: // = { l.state = sLValue return tEqual - goto yystate0 + } yyrule16: // , { @@ -782,13 +782,13 @@ yyrule17: // \"(\\.|[^\\"\n])*\" { l.state = sLabels return tLValue - goto yystate0 + } yyrule18: // {S}[^ \n]+ { l.state = sTimestamp return tValue - goto yystate0 + } yyrule19: // {S}[^ \n]+ { @@ -798,13 +798,13 @@ yyrule20: // \n { l.state = sInit return tLinebreak - goto yystate0 + } yyrule21: // {S}#{S}\{ { l.state = sExemplar return tComment - goto yystate0 + } yyrule22: // {L}({L}|{D})* { @@ -814,25 +814,25 @@ yyrule23: // \"(\\.|[^\\"\n])*\" { l.state = sExemplar return tQString - goto yystate0 + } yyrule24: // \} { l.state = sEValue return tBraceClose - goto yystate0 + } yyrule25: // = { l.state = sEValue return tEqual - goto yystate0 + } yyrule26: // \"(\\.|[^\\"\n])*\" { l.state = sExemplar return tLValue - goto yystate0 + } yyrule27: // , { @@ -842,7 +842,7 @@ yyrule28: // {S}[^ \n]+ { l.state = sETimestamp return tValue - goto yystate0 + } yyrule29: // {S}[^ \n]+ { @@ -852,7 +852,7 @@ yyrule30: // \n if true { // avoid go vet determining the below panic will not be reached l.state = sInit return tLinebreak - goto yystate0 + } panic("unreachable") diff --git a/model/textparse/promlex.l.go b/model/textparse/promlex.l.go index a083e5549b..9ff5d6c9f8 100644 --- a/model/textparse/promlex.l.go +++ b/model/textparse/promlex.l.go @@ -92,10 +92,10 @@ yystate2: yystate3: c = l.next() - switch { + switch c { default: goto yyrule3 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate3 } @@ -105,19 +105,19 @@ yystate4: yystate5: c = l.next() - switch { + switch c { default: goto yyrule5 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate6 } yystate6: c = l.next() - switch { + switch c { default: goto yyrule4 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate6 } @@ -137,104 +137,104 @@ yystate8: yystate9: c = l.next() yystart9: - switch { + switch c { default: goto yyabort - case c == 'H': + case 'H': goto yystate10 - case c == 'T': + case 'T': goto yystate15 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate3 } yystate10: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'E': + case 'E': goto yystate11 } yystate11: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'L': + case 'L': goto yystate12 } yystate12: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'P': + case 'P': goto yystate13 } yystate13: c = l.next() - switch { + switch c { default: goto yyabort - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate14 } yystate14: c = l.next() - switch { + switch c { default: goto yyrule6 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate14 } yystate15: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'Y': + case 'Y': goto yystate16 } yystate16: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'P': + case 'P': goto yystate17 } yystate17: c = l.next() - switch { + switch c { default: goto yyabort - case c == 'E': + case 'E': goto yystate18 } yystate18: c = l.next() - switch { + switch c { default: goto yyabort - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate19 } yystate19: c = l.next() - switch { + switch c { default: goto yyrule7 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate19 } @@ -389,12 +389,12 @@ yystate35: yystate36: c = l.next() yystart36: - switch { + switch c { default: goto yyabort - case c == '"': + case '"': goto yystate37 - case c == '\t' || c == ' ': + case '\t', ' ': goto yystate3 } @@ -486,7 +486,7 @@ yyrule2: // \n { l.state = sInit return tLinebreak - goto yystate0 + } yyrule3: // [ \t]+ { @@ -505,49 +505,49 @@ yyrule6: // HELP[\t ]+ { l.state = sMeta1 return tHelp - goto yystate0 + } yyrule7: // TYPE[\t ]+ { l.state = sMeta1 return tType - goto yystate0 + } yyrule8: // \"(\\.|[^\\"])*\" { l.state = sMeta2 return tMName - goto yystate0 + } yyrule9: // {M}({M}|{D})* { l.state = sMeta2 return tMName - goto yystate0 + } yyrule10: // {C}* { l.state = sInit return tText - goto yystate0 + } yyrule11: // {M}({M}|{D})* { l.state = sValue return tMName - goto yystate0 + } yyrule12: // \{ { l.state = sLabels return tBraceOpen - goto yystate0 + } yyrule13: // \{ { l.state = sLabels return tBraceOpen - goto yystate0 + } yyrule14: // {L}({L}|{D})* { @@ -557,19 +557,19 @@ yyrule15: // \"(\\.|[^\\"])*\" { l.state = sLabels return tQString - goto yystate0 + } yyrule16: // \} { l.state = sValue return tBraceClose - goto yystate0 + } yyrule17: // = { l.state = sLValue return tEqual - goto yystate0 + } yyrule18: // , { @@ -579,13 +579,13 @@ yyrule19: // \"(\\.|[^\\"])*\" { l.state = sLabels return tLValue - goto yystate0 + } yyrule20: // [^{ \t\n]+ { l.state = sTimestamp return tValue - goto yystate0 + } yyrule21: // {D}+ { @@ -595,7 +595,7 @@ yyrule22: // \n if true { // avoid go vet determining the below panic will not be reached l.state = sInit return tLinebreak - goto yystate0 + } panic("unreachable") diff --git a/prompb/io/prometheus/client/decoder_test.go b/prompb/io/prometheus/client/decoder_test.go index 480fb3cd36..b28fe43db9 100644 --- a/prompb/io/prometheus/client/decoder_test.go +++ b/prompb/io/prometheus/client/decoder_test.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "math/rand" + "strings" "testing" "github.com/gogo/protobuf/proto" @@ -236,9 +237,11 @@ func generateMetricFamilyText(labelsCount int) string { randomName := fmt.Sprintf("metric_%d", rand.Intn(1000)) randomHelp := fmt.Sprintf("Test metric to demonstrate forced corruption %d.", rand.Intn(1000)) labels10 := "" + var labels10Sb239 strings.Builder for range labelsCount { - labels10 += generateLabels() + labels10Sb239.WriteString(generateLabels()) } + labels10 += labels10Sb239.String() return fmt.Sprintf(`name: "%s" help: "%s" type: GAUGE diff --git a/promql/engine.go b/promql/engine.go index 63ad4aed51..75fc9b05d3 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -2310,7 +2310,7 @@ func reuseOrGetHPointSlices(prevSS *Series, numSteps int) (r []HPoint) { if prevSS != nil && cap(prevSS.Histograms)-2*len(prevSS.Histograms) > 0 { r = prevSS.Histograms[len(prevSS.Histograms):] prevSS.Histograms = prevSS.Histograms[0:len(prevSS.Histograms):len(prevSS.Histograms)] - return + return r } return getHPointSlice(numSteps) @@ -2322,7 +2322,7 @@ func reuseOrGetFPointSlices(prevSS *Series, numSteps int) (r []FPoint) { if prevSS != nil && cap(prevSS.Floats)-2*len(prevSS.Floats) > 0 { r = prevSS.Floats[len(prevSS.Floats):] prevSS.Floats = prevSS.Floats[0:len(prevSS.Floats):len(prevSS.Floats)] - return + return r } return getFPointSlice(numSteps) diff --git a/promql/functions.go b/promql/functions.go index 2ff25c3acf..ca8cfdce15 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1526,7 +1526,7 @@ func simpleHistogramFunc(vectorVals []Vector, enh *EvalNodeHelper, f func(h *his for _, el := range vectorVals[0] { if el.H != nil { // Process only histogram samples. if !enh.enableDelayedNameRemoval { - el.Metric = el.Metric.DropMetricName() + el.Metric = el.Metric.DropReserved(func(n string) bool { return n == labels.MetricName }) } enh.Out = append(enh.Out, Sample{ Metric: el.Metric, diff --git a/promql/parser/parse.go b/promql/parser/parse.go index d4bc4609eb..bcd511f467 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -453,14 +453,14 @@ func (p *parser) newAggregateExpr(op Item, modifier, args Node, overread bool) ( p.addParseErrf(ret.PositionRange(), "no arguments for aggregate expression provided") // Prevents invalid array accesses. - return + return ret } desiredArgs := 1 if ret.Op.IsAggregatorWithParam() { if !EnableExperimentalFunctions && ret.Op.IsExperimentalAggregator() { p.addParseErrf(ret.PositionRange(), "%s() is experimental and must be enabled with --enable-feature=promql-experimental-functions", ret.Op) - return + return ret } desiredArgs = 2 @@ -469,7 +469,7 @@ func (p *parser) newAggregateExpr(op Item, modifier, args Node, overread bool) ( if len(arguments) != desiredArgs { p.addParseErrf(ret.PositionRange(), "wrong number of arguments for aggregate expression provided, expected %d, got %d", desiredArgs, len(arguments)) - return + return ret } ret.Expr = arguments[desiredArgs-1] @@ -652,7 +652,7 @@ func (p *parser) buildHistogramBucketsAndSpans(desc *map[string]any, bucketsKey, if bucketCount > 0 { spans = []histogram.Span{{Offset: offset, Length: uint32(bucketCount)}} } - return + return buckets, spans } // number parses a number. @@ -730,7 +730,7 @@ func (p *parser) checkAST(node Node) (typ ValueType) { } for r.End = n.RHS.PositionRange().Start - 1; isSpace(rune(p.lex.input[r.End])); r.End-- { } - return + return r } if n.ReturnBool && !n.Op.IsComparisonOperator() { @@ -882,7 +882,7 @@ func (p *parser) checkAST(node Node) (typ ValueType) { default: p.addParseErrf(n.PositionRange(), "unknown node type: %T", node) } - return + return typ } func (p *parser) unquoteString(s string) string { diff --git a/rules/group.go b/rules/group.go index 8faf930b77..8cedcd40d1 100644 --- a/rules/group.go +++ b/rules/group.go @@ -789,7 +789,7 @@ func (g *Group) RestoreForState(ts time.Time) { // While not technically the same number of series we expect, it's as good of an approximation as any. seriesByLabels := make(map[string]storage.Series, alertRule.ActiveAlertsCount()) for sset.Next() { - seriesByLabels[sset.At().Labels().DropMetricName().String()] = sset.At() + seriesByLabels[sset.At().Labels().DropReserved(func(n string) bool { return n == labels.MetricName }).String()] = sset.At() } // No results for this alert rule. diff --git a/scrape/scrape.go b/scrape/scrape.go index 4043f6c0f6..09652d0484 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -1642,7 +1642,7 @@ func (sl *scrapeLoop) updateStaleMarkers(app storage.Appender, defTime int64) (e } return err == nil }) - return + return err } func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) { @@ -1652,7 +1652,7 @@ func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, // Empty scrape. Just update the stale makers and swap the cache (but don't flush it). err = sl.updateStaleMarkers(app, defTime) sl.cache.iterDone(false) - return + return total, added, seriesAdded, err } p, err := textparse.New(b, contentType, sl.symbolTable, textparse.ParserOptions{ @@ -1670,7 +1670,7 @@ func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, "fallback_media_type", sl.fallbackScrapeProtocol, "err", err, ) - return + return total, added, seriesAdded, err } if err != nil { sl.l.Debug( @@ -1952,7 +1952,7 @@ loop: if err == nil { err = sl.updateStaleMarkers(app, defTime) } - return + return total, added, seriesAdded, err } func isSeriesPartOfFamily(mName string, mfName []byte, typ model.MetricType) bool { @@ -2150,32 +2150,32 @@ func (sl *scrapeLoop) report(app storage.Appender, start time.Time, duration tim b := labels.NewBuilderWithSymbolTable(sl.symbolTable) if err = sl.addReportSample(app, scrapeHealthMetric, ts, health, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeDurationMetric, ts, duration.Seconds(), b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSamplesMetric, ts, float64(scraped), b); err != nil { - return + return err } if err = sl.addReportSample(app, samplesPostRelabelMetric, ts, float64(added), b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSeriesAddedMetric, ts, float64(seriesAdded), b); err != nil { - return + return err } if sl.reportExtraMetrics { if err = sl.addReportSample(app, scrapeTimeoutMetric, ts, sl.timeout.Seconds(), b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSampleLimitMetric, ts, float64(sl.sampleLimit), b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeBodySizeBytesMetric, ts, float64(bytes), b); err != nil { - return + return err } } - return + return err } func (sl *scrapeLoop) reportStale(app storage.Appender, start time.Time) (err error) { @@ -2185,32 +2185,32 @@ func (sl *scrapeLoop) reportStale(app storage.Appender, start time.Time) (err er b := labels.NewBuilder(labels.EmptyLabels()) if err = sl.addReportSample(app, scrapeHealthMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeDurationMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSamplesMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, samplesPostRelabelMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSeriesAddedMetric, ts, stale, b); err != nil { - return + return err } if sl.reportExtraMetrics { if err = sl.addReportSample(app, scrapeTimeoutMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeSampleLimitMetric, ts, stale, b); err != nil { - return + return err } if err = sl.addReportSample(app, scrapeBodySizeBytesMetric, ts, stale, b); err != nil { - return + return err } } - return + return err } func (sl *scrapeLoop) addReportSample(app storage.Appender, s reportSample, t int64, v float64, b *labels.Builder) error { diff --git a/storage/fanout.go b/storage/fanout.go index 4d076788a7..f99edb473a 100644 --- a/storage/fanout.go +++ b/storage/fanout.go @@ -253,7 +253,7 @@ func (f *fanoutAppender) Commit() (err error) { } } } - return + return err } func (f *fanoutAppender) Rollback() (err error) { diff --git a/storage/remote/otlptranslator/prometheusremotewrite/combined_appender.go b/storage/remote/otlptranslator/prometheusremotewrite/combined_appender.go index 36f2213453..1441aecb6d 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/combined_appender.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/combined_appender.go @@ -186,7 +186,7 @@ func (b *combinedAppender) appendFloatOrHistogram(ls labels.Labels, meta metadat if ref == 0 { // We cannot update metadata or add exemplars on non existent series. - return + return err } if !exists || series.meta.Help != meta.Help || series.meta.Type != meta.Type || series.meta.Unit != meta.Unit { @@ -210,7 +210,7 @@ func (b *combinedAppender) appendFloatOrHistogram(ls labels.Labels, meta metadat b.appendExemplars(ref, ls, es) - return + return err } func sampleType(h *histogram.Histogram) string { diff --git a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go index f0e623a72c..5e575e6174 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go @@ -165,7 +165,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric for k := 0; k < metricSlice.Len(); k++ { if err := c.everyN.checkContext(ctx); err != nil { errs = multierr.Append(errs, err) - return + return annots, errs } metric := metricSlice.At(k) @@ -213,7 +213,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric if err := c.addGaugeNumberDataPoints(ctx, dataPoints, resource, settings, scope, meta); err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } case pmetric.MetricTypeSum: @@ -225,7 +225,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric if err := c.addSumNumberDataPoints(ctx, dataPoints, resource, settings, scope, meta); err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } case pmetric.MetricTypeHistogram: @@ -242,14 +242,14 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric if err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } } else { if err := c.addHistogramDataPoints(ctx, dataPoints, resource, settings, scope, meta); err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } } @@ -272,7 +272,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric if err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } case pmetric.MetricTypeSummary: @@ -284,7 +284,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric if err := c.addSummaryDataPoints(ctx, dataPoints, resource, settings, scope, meta); err != nil { errs = multierr.Append(errs, err) if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return + return annots, errs } } default: @@ -301,7 +301,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric } } - return + return annots, errs } func NewPromoteResourceAttributes(otlpCfg config.OTLPConfig) *PromoteResourceAttributes { diff --git a/tsdb/chunkenc/float_histogram.go b/tsdb/chunkenc/float_histogram.go index f9baa1df9c..8002dd0d4e 100644 --- a/tsdb/chunkenc/float_histogram.go +++ b/tsdb/chunkenc/float_histogram.go @@ -230,59 +230,59 @@ func (a *FloatHistogramAppender) appendable(h *histogram.FloatHistogram) ( okToAppend, counterReset bool, ) { if a.NumSamples() > 0 && a.GetCounterResetHeader() == GaugeType { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if h.CounterResetHint == histogram.CounterReset { // Always honor the explicit counter reset hint. counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if value.IsStaleNaN(h.Sum) { // This is a stale sample whose buckets and spans don't matter. okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if value.IsStaleNaN(a.sum.value) { // If the last sample was stale, then we can only accept stale // samples in this chunk. - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if h.Count < a.cnt.value { // There has been a counter reset. counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.CustomBucketBoundsMatch(h.CustomValues, a.customValues) { counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } if h.ZeroCount < a.zCnt.value { // There has been a counter reset since ZeroThreshold didn't change. counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } var ok bool positiveInserts, backwardPositiveInserts, ok = expandFloatSpansAndBuckets(a.pSpans, h.PositiveSpans, a.pBuckets, h.PositiveBuckets) if !ok { counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } negativeInserts, backwardNegativeInserts, ok = expandFloatSpansAndBuckets(a.nSpans, h.NegativeSpans, a.nBuckets, h.NegativeBuckets) if !ok { counterReset = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterReset } // expandFloatSpansAndBuckets returns the inserts to expand the bucket spans 'a' so that @@ -478,31 +478,31 @@ func (a *FloatHistogramAppender) appendableGauge(h *histogram.FloatHistogram) ( okToAppend bool, ) { if a.NumSamples() > 0 && a.GetCounterResetHeader() != GaugeType { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if value.IsStaleNaN(h.Sum) { // This is a stale sample whose buckets and spans don't matter. okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if value.IsStaleNaN(a.sum.value) { // If the last sample was stale, then we can only accept stale // samples in this chunk. - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.CustomBucketBoundsMatch(h.CustomValues, a.customValues) { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } positiveInserts, backwardPositiveInserts, positiveSpans = expandSpansBothWays(a.pSpans, h.PositiveSpans) negativeInserts, backwardNegativeInserts, negativeSpans = expandSpansBothWays(a.nSpans, h.NegativeSpans) okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } // appendFloatHistogram appends a float histogram to the chunk. The caller must ensure that diff --git a/tsdb/chunkenc/histogram.go b/tsdb/chunkenc/histogram.go index 0488c6554d..cc1d771235 100644 --- a/tsdb/chunkenc/histogram.go +++ b/tsdb/chunkenc/histogram.go @@ -260,29 +260,29 @@ func (a *HistogramAppender) appendable(h *histogram.Histogram) ( ) { counterResetHint = NotCounterReset if a.NumSamples() > 0 && a.GetCounterResetHeader() == GaugeType { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if h.CounterResetHint == histogram.CounterReset { // Always honor the explicit counter reset hint. counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if value.IsStaleNaN(h.Sum) { // This is a stale sample whose buckets and spans don't matter. okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if value.IsStaleNaN(a.sum) { // If the last sample was stale, then we can only accept stale // samples in this chunk. counterResetHint = UnknownCounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if h.Count < a.cnt { // There has been a counter reset. counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold { @@ -291,34 +291,34 @@ func (a *HistogramAppender) appendable(h *histogram.Histogram) ( // as long as https://github.com/prometheus/prometheus/issues/15346 is still open. // TODO: consider adding the counter reset detection here once #15346 is fixed. counterResetHint = UnknownCounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.CustomBucketBoundsMatch(h.CustomValues, a.customValues) { counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } if h.ZeroCount < a.zCnt { // There has been a counter reset since ZeroThreshold didn't change. counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } var ok bool positiveInserts, backwardPositiveInserts, ok = expandIntSpansAndBuckets(a.pSpans, h.PositiveSpans, a.pBuckets, h.PositiveBuckets) if !ok { counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } negativeInserts, backwardNegativeInserts, ok = expandIntSpansAndBuckets(a.nSpans, h.NegativeSpans, a.nBuckets, h.NegativeBuckets) if !ok { counterResetHint = CounterReset - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, okToAppend, counterResetHint } // expandIntSpansAndBuckets returns the inserts to expand the bucket spans 'a' so that @@ -515,31 +515,31 @@ func (a *HistogramAppender) appendableGauge(h *histogram.Histogram) ( okToAppend bool, ) { if a.NumSamples() > 0 && a.GetCounterResetHeader() != GaugeType { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if value.IsStaleNaN(h.Sum) { // This is a stale sample whose buckets and spans don't matter. okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if value.IsStaleNaN(a.sum) { // If the last sample was stale, then we can only accept stale // samples in this chunk. - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.CustomBucketBoundsMatch(h.CustomValues, a.customValues) { - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } positiveInserts, backwardPositiveInserts, positiveSpans = expandSpansBothWays(a.pSpans, h.PositiveSpans) negativeInserts, backwardNegativeInserts, negativeSpans = expandSpansBothWays(a.nSpans, h.NegativeSpans) okToAppend = true - return + return positiveInserts, negativeInserts, backwardPositiveInserts, backwardNegativeInserts, positiveSpans, negativeSpans, okToAppend } // appendHistogram appends a histogram to the chunk. The caller must ensure that diff --git a/tsdb/chunkenc/histogram_meta.go b/tsdb/chunkenc/histogram_meta.go index 5ee783fd68..22bc4a6d3d 100644 --- a/tsdb/chunkenc/histogram_meta.go +++ b/tsdb/chunkenc/histogram_meta.go @@ -40,33 +40,33 @@ func readHistogramChunkLayout(b *bstreamReader) ( ) { zeroThreshold, err = readZeroThreshold(b) if err != nil { - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } v, err := readVarbitInt(b) if err != nil { - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } schema = int32(v) positiveSpans, err = readHistogramChunkLayoutSpans(b) if err != nil { - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } negativeSpans, err = readHistogramChunkLayoutSpans(b) if err != nil { - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } if histogram.IsCustomBucketsSchema(schema) { customValues, err = readHistogramChunkLayoutCustomBounds(b) if err != nil { - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } } - return + return schema, zeroThreshold, positiveSpans, negativeSpans, customValues, err } func putHistogramChunkLayoutSpans(b *bstream, spans []histogram.Span) { @@ -550,5 +550,5 @@ func adjustForInserts(spans []histogram.Span, inserts []Insert) (mergedSpans []h addBucket(insertIdx) consumeInsert() } - return + return mergedSpans } diff --git a/tsdb/chunks/chunks.go b/tsdb/chunks/chunks.go index 4e48836be9..8b8f5d0f81 100644 --- a/tsdb/chunks/chunks.go +++ b/tsdb/chunks/chunks.go @@ -197,7 +197,7 @@ func ChunkFromSamplesGeneric(s Samples) (Meta, error) { // Used in tests to compare the content of chunks. func ChunkMetasToSamples(chunks []Meta) (result []Sample) { if len(chunks) == 0 { - return + return result } for _, chunk := range chunks { @@ -218,7 +218,7 @@ func ChunkMetasToSamples(chunks []Meta) (result []Sample) { } } } - return + return result } // Iterator iterates over the chunks of a single time series. diff --git a/tsdb/chunks/head_chunks_test.go b/tsdb/chunks/head_chunks_test.go index 15e0d9acd7..2d7744193d 100644 --- a/tsdb/chunks/head_chunks_test.go +++ b/tsdb/chunks/head_chunks_test.go @@ -579,5 +579,5 @@ func createChunk(t *testing.T, idx int, hrw *ChunkDiskMapper) (seriesRef HeadSer close(awaitCb) }) <-awaitCb - return + return seriesRef, chunkRef, mint, maxt, chunk, isOOO } diff --git a/tsdb/db.go b/tsdb/db.go index a8e080e4d8..c57ae84c9c 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -1768,7 +1768,7 @@ func BeyondTimeRetention(db *DB, blocks []*Block) (deletable map[ulid.ULID]struc // Time retention is disabled or no blocks to work with. retentionDuration := db.getRetentionDuration() if len(blocks) == 0 || retentionDuration == 0 { - return + return deletable } deletable = make(map[ulid.ULID]struct{}) @@ -1792,7 +1792,7 @@ func BeyondSizeRetention(db *DB, blocks []*Block) (deletable map[ulid.ULID]struc // Size retention is disabled or no blocks to work with. maxBytes := db.getMaxBytes() if len(blocks) == 0 || maxBytes <= 0 { - return + return deletable } deletable = make(map[ulid.ULID]struct{}) diff --git a/tsdb/db_test.go b/tsdb/db_test.go index ff89899db8..100318c474 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -1433,7 +1433,7 @@ func intersection(oldBlocks, actualBlocks []string) (intersection []string) { intersection = append(intersection, e) } } - return + return intersection } // mockCompactorFailing creates a new empty block on every write and fails when reached the max allowed total. @@ -2741,7 +2741,7 @@ func TestDBReadOnly_Querier_NoAlteration(t *testing.T) { if runtime.GOOS != "windows" { hash = testutil.DirHash(t, dir) } - return + return hash } spinUpQuerierAndCheck := func(dir, sandboxDir string, chunksCount int) { diff --git a/tsdb/head_append.go b/tsdb/head_append.go index 6ad113b343..8740d2f5ad 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -2207,7 +2207,7 @@ func (s *memSeries) mmapCurrentOOOHeadChunk(chunkDiskMapper *chunks.ChunkDiskMap func (s *memSeries) mmapChunks(chunkDiskMapper *chunks.ChunkDiskMapper) (count int) { if s.headChunks == nil || s.headChunks.prev == nil { // There is none or only one head chunk, so nothing to m-map here. - return + return count } // Write chunks starting from the oldest one and stop before we get to current s.headChunks. diff --git a/tsdb/head_wal.go b/tsdb/head_wal.go index 3c5390cab4..eed68125d4 100644 --- a/tsdb/head_wal.go +++ b/tsdb/head_wal.go @@ -548,7 +548,7 @@ func (h *Head) resetSeriesWithMMappedChunks(mSeries *memSeries, mmc, oooMmc []*m mSeries.nextAt = 0 mSeries.headChunks = nil mSeries.app = nil - return + return overlapped } type walSubsetProcessor struct { @@ -1194,7 +1194,7 @@ func decodeSeriesFromChunkSnapshot(d *record.Decoder, b []byte) (csr chunkSnapsh _ = dec.Be64int64() // Was chunkRange but now unused. if dec.Uvarint() == 0 { - return + return csr, err } csr.mc = &memChunk{} @@ -1235,7 +1235,7 @@ func decodeSeriesFromChunkSnapshot(d *record.Decoder, b []byte) (csr chunkSnapsh err = fmt.Errorf("unexpected %d bytes left in entry", len(dec.B)) } - return + return csr, err } func encodeTombstonesToSnapshotRecord(tr tombstones.Reader) ([]byte, error) { diff --git a/tsdb/ooo_head.go b/tsdb/ooo_head.go index a3d6b3567b..b3f5e2b675 100644 --- a/tsdb/ooo_head.go +++ b/tsdb/ooo_head.go @@ -120,7 +120,7 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error } app, err = chunk.Appender() if err != nil { - return + return chks, err } } switch encoding { diff --git a/tsdb/record/record_test.go b/tsdb/record/record_test.go index 41580b0f00..bbbea04940 100644 --- a/tsdb/record/record_test.go +++ b/tsdb/record/record_test.go @@ -670,7 +670,7 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) { } delete(lbls, model.BucketLabel) } - return + return series, floatSamples, histSamples } initNHCBRefs := func(labelCount, histograms, buckets int) (series []RefSeries, floatSamples []RefSample, histSamples []RefHistogramSample) { @@ -703,7 +703,7 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) { }) ref++ } - return + return series, floatSamples, histSamples } for _, maker := range []recordsMaker{ diff --git a/tsdb/wlog/wlog.go b/tsdb/wlog/wlog.go index dec41ad2c7..176531c478 100644 --- a/tsdb/wlog/wlog.go +++ b/tsdb/wlog/wlog.go @@ -788,12 +788,12 @@ func (w *WL) LastSegmentAndOffset() (seg, offset int, err error) { _, seg, err = Segments(w.Dir()) if err != nil { - return + return seg, offset, err } offset = (w.donePages * pageSize) + w.page.alloc - return + return seg, offset, err } // Truncate drops all segments before i. diff --git a/util/annotations/annotations.go b/util/annotations/annotations.go index 6d6427e371..817f670b5e 100644 --- a/util/annotations/annotations.go +++ b/util/annotations/annotations.go @@ -107,7 +107,7 @@ func (a Annotations) AsStrings(query string, maxWarnings, maxInfos int) (warning if infoSkipped > 0 { infos = append(infos, fmt.Sprintf("%d more info annotations omitted", infoSkipped)) } - return + return warnings, infos } // CountWarningsAndInfo counts and returns the number of warnings and infos in the @@ -121,7 +121,7 @@ func (a Annotations) CountWarningsAndInfo() (countWarnings, countInfo int) { countInfo++ } } - return + return countWarnings, countInfo } //nolint:staticcheck,revive // error-naming. diff --git a/util/strutil/quote.go b/util/strutil/quote.go index 66d9c88ffc..0a78421fd4 100644 --- a/util/strutil/quote.go +++ b/util/strutil/quote.go @@ -129,7 +129,7 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, switch c := s[0]; { case c == quote && (quote == '\'' || quote == '"'): err = ErrSyntax - return + return value, multibyte, tail, err case c >= utf8.RuneSelf: r, size := utf8.DecodeRuneInString(s) return r, true, s[size:], nil @@ -140,7 +140,7 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, // Hard case: c is backslash. if len(s) <= 1 { err = ErrSyntax - return + return value, multibyte, tail, err } c := s[1] s = s[2:] @@ -173,13 +173,13 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, var v rune if len(s) < n { err = ErrSyntax - return + return value, multibyte, tail, err } for j := 0; j < n; j++ { x, ok := unhex(s[j]) if !ok { err = ErrSyntax - return + return value, multibyte, tail, err } v = v<<4 | x } @@ -191,7 +191,7 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, } if v > utf8.MaxRune { err = ErrSyntax - return + return value, multibyte, tail, err } value = v multibyte = true @@ -199,20 +199,20 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, v := rune(c) - '0' if len(s) < 2 { err = ErrSyntax - return + return value, multibyte, tail, err } for j := range 2 { // One digit already; two more. x := rune(s[j]) - '0' if x < 0 || x > 7 { err = ErrSyntax - return + return value, multibyte, tail, err } v = (v << 3) | x } s = s[2:] if v > 255 { err = ErrSyntax - return + return value, multibyte, tail, err } value = v case '\\': @@ -220,15 +220,15 @@ func unquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, case '\'', '"': if c != quote { err = ErrSyntax - return + return value, multibyte, tail, err } value = rune(c) default: err = ErrSyntax - return + return value, multibyte, tail, err } tail = s - return + return value, multibyte, tail, err } // contains reports whether the string contains the byte c. @@ -251,5 +251,5 @@ func unhex(b byte) (v rune, ok bool) { case 'A' <= c && c <= 'F': return c - 'A' + 10, true } - return + return v, ok } diff --git a/util/testutil/directory.go b/util/testutil/directory.go index d8c2f74bdb..176acb5dc1 100644 --- a/util/testutil/directory.go +++ b/util/testutil/directory.go @@ -127,7 +127,7 @@ func NewTemporaryDirectory(name string, t T) (handler TemporaryDirectory) { tester: t, } - return + return handler } // DirHash returns a hash of all files attributes and their content within a directory. diff --git a/web/ui/embed.go.tmpl b/web/ui/embed.go.tmpl index 1d7dbf5958..8d8d16a9b7 100644 --- a/web/ui/embed.go.tmpl +++ b/web/ui/embed.go.tmpl @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus Authors // 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build builtinassets -// +build builtinassets package ui