mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
Enable default revive rules (#13068)
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
This commit is contained in:
parent
f216ddadbc
commit
2a75604f8e
|
@ -81,8 +81,39 @@ linters-settings:
|
||||||
gofumpt:
|
gofumpt:
|
||||||
extra-rules: true
|
extra-rules: true
|
||||||
revive:
|
revive:
|
||||||
|
# By default, revive will enable only the linting rules that are named in the configuration file.
|
||||||
|
# So, it's needed to explicitly set in configuration all required rules.
|
||||||
|
# The following configuration enables all the rules from the defaults.toml
|
||||||
|
# https://github.com/mgechev/revive/blob/master/defaults.toml
|
||||||
rules:
|
rules:
|
||||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
|
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
||||||
- name: unused-parameter
|
- name: blank-imports
|
||||||
severity: warning
|
- name: context-as-argument
|
||||||
|
arguments:
|
||||||
|
# allow functions with test or bench signatures
|
||||||
|
- allowTypesBefore: "*testing.T,testing.TB"
|
||||||
|
- name: context-keys-type
|
||||||
|
- name: dot-imports
|
||||||
|
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
|
||||||
|
# See https://github.com/mgechev/revive/issues/386
|
||||||
|
- name: empty-block
|
||||||
disabled: true
|
disabled: true
|
||||||
|
- name: error-naming
|
||||||
|
- name: error-return
|
||||||
|
- name: error-strings
|
||||||
|
- name: errorf
|
||||||
|
- name: exported
|
||||||
|
- name: increment-decrement
|
||||||
|
- name: indent-error-flow
|
||||||
|
- name: package-comments
|
||||||
|
- name: range
|
||||||
|
- name: receiver-naming
|
||||||
|
- name: redefines-builtin-id
|
||||||
|
- name: superfluous-else
|
||||||
|
- name: time-naming
|
||||||
|
- name: unexported-return
|
||||||
|
- name: unreachable-code
|
||||||
|
- name: unused-parameter
|
||||||
|
disabled: true
|
||||||
|
- name: var-declaration
|
||||||
|
- name: var-naming
|
||||||
|
|
|
@ -411,7 +411,7 @@ func checkExperimental(f bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lintError = fmt.Errorf("lint error")
|
var errLint = fmt.Errorf("lint error")
|
||||||
|
|
||||||
type lintConfig struct {
|
type lintConfig struct {
|
||||||
all bool
|
all bool
|
||||||
|
@ -763,7 +763,7 @@ func checkRulesFromStdin(ls lintConfig) (bool, bool) {
|
||||||
fmt.Fprintln(os.Stderr, " FAILED:")
|
fmt.Fprintln(os.Stderr, " FAILED:")
|
||||||
for _, e := range errs {
|
for _, e := range errs {
|
||||||
fmt.Fprintln(os.Stderr, e.Error())
|
fmt.Fprintln(os.Stderr, e.Error())
|
||||||
hasErrors = hasErrors || !errors.Is(e, lintError)
|
hasErrors = hasErrors || !errors.Is(e, errLint)
|
||||||
}
|
}
|
||||||
if hasErrors {
|
if hasErrors {
|
||||||
return failed, hasErrors
|
return failed, hasErrors
|
||||||
|
@ -776,7 +776,7 @@ func checkRulesFromStdin(ls lintConfig) (bool, bool) {
|
||||||
}
|
}
|
||||||
failed = true
|
failed = true
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
hasErrors = hasErrors || !errors.Is(err, lintError)
|
hasErrors = hasErrors || !errors.Is(err, errLint)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" SUCCESS: %d rules found\n", n)
|
fmt.Printf(" SUCCESS: %d rules found\n", n)
|
||||||
|
@ -797,7 +797,7 @@ func checkRules(files []string, ls lintConfig) (bool, bool) {
|
||||||
fmt.Fprintln(os.Stderr, " FAILED:")
|
fmt.Fprintln(os.Stderr, " FAILED:")
|
||||||
for _, e := range errs {
|
for _, e := range errs {
|
||||||
fmt.Fprintln(os.Stderr, e.Error())
|
fmt.Fprintln(os.Stderr, e.Error())
|
||||||
hasErrors = hasErrors || !errors.Is(e, lintError)
|
hasErrors = hasErrors || !errors.Is(e, errLint)
|
||||||
}
|
}
|
||||||
if hasErrors {
|
if hasErrors {
|
||||||
continue
|
continue
|
||||||
|
@ -810,7 +810,7 @@ func checkRules(files []string, ls lintConfig) (bool, bool) {
|
||||||
}
|
}
|
||||||
failed = true
|
failed = true
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
hasErrors = hasErrors || !errors.Is(err, lintError)
|
hasErrors = hasErrors || !errors.Is(err, errLint)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" SUCCESS: %d rules found\n", n)
|
fmt.Printf(" SUCCESS: %d rules found\n", n)
|
||||||
|
@ -837,7 +837,7 @@ func checkRuleGroups(rgs *rulefmt.RuleGroups, lintSettings lintConfig) (int, []e
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
errMessage += "Might cause inconsistency while recording expressions"
|
errMessage += "Might cause inconsistency while recording expressions"
|
||||||
return 0, []error{fmt.Errorf("%w %s", lintError, errMessage)}
|
return 0, []error{fmt.Errorf("%w %s", errLint, errMessage)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,16 +145,16 @@ func (i *InstanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group,
|
||||||
openstackLabelUserID: model.LabelValue(s.UserID),
|
openstackLabelUserID: model.LabelValue(s.UserID),
|
||||||
}
|
}
|
||||||
|
|
||||||
flavorId, ok := s.Flavor["id"].(string)
|
flavorID, ok := s.Flavor["id"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
level.Warn(i.logger).Log("msg", "Invalid type for flavor id, expected string")
|
level.Warn(i.logger).Log("msg", "Invalid type for flavor id, expected string")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
labels[openstackLabelInstanceFlavor] = model.LabelValue(flavorId)
|
labels[openstackLabelInstanceFlavor] = model.LabelValue(flavorID)
|
||||||
|
|
||||||
imageId, ok := s.Image["id"].(string)
|
imageID, ok := s.Image["id"].(string)
|
||||||
if ok {
|
if ok {
|
||||||
labels[openstackLabelInstanceImage] = model.LabelValue(imageId)
|
labels[openstackLabelInstanceImage] = model.LabelValue(imageID)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range s.Metadata {
|
for k, v := range s.Metadata {
|
||||||
|
|
|
@ -353,12 +353,12 @@ func (h *FloatHistogram) Equals(h2 *FloatHistogram) bool {
|
||||||
// Size returns the total size of the FloatHistogram, which includes the size of the pointer
|
// Size returns the total size of the FloatHistogram, which includes the size of the pointer
|
||||||
// to FloatHistogram, all its fields, and all elements contained in slices.
|
// to FloatHistogram, all its fields, and all elements contained in slices.
|
||||||
// NOTE: this is only valid for 64 bit architectures.
|
// NOTE: this is only valid for 64 bit architectures.
|
||||||
func (fh *FloatHistogram) Size() int {
|
func (h *FloatHistogram) Size() int {
|
||||||
// Size of each slice separately.
|
// Size of each slice separately.
|
||||||
posSpanSize := len(fh.PositiveSpans) * 8 // 8 bytes (int32 + uint32).
|
posSpanSize := len(h.PositiveSpans) * 8 // 8 bytes (int32 + uint32).
|
||||||
negSpanSize := len(fh.NegativeSpans) * 8 // 8 bytes (int32 + uint32).
|
negSpanSize := len(h.NegativeSpans) * 8 // 8 bytes (int32 + uint32).
|
||||||
posBucketSize := len(fh.PositiveBuckets) * 8 // 8 bytes (float64).
|
posBucketSize := len(h.PositiveBuckets) * 8 // 8 bytes (float64).
|
||||||
negBucketSize := len(fh.NegativeBuckets) * 8 // 8 bytes (float64).
|
negBucketSize := len(h.NegativeBuckets) * 8 // 8 bytes (float64).
|
||||||
|
|
||||||
// Total size of the struct.
|
// Total size of the struct.
|
||||||
|
|
||||||
|
@ -1000,8 +1000,8 @@ func addBuckets(
|
||||||
spansB []Span, bucketsB []float64,
|
spansB []Span, bucketsB []float64,
|
||||||
) ([]Span, []float64) {
|
) ([]Span, []float64) {
|
||||||
var (
|
var (
|
||||||
iSpan int = -1
|
iSpan = -1
|
||||||
iBucket int = -1
|
iBucket = -1
|
||||||
iInSpan int32
|
iInSpan int32
|
||||||
indexA int32
|
indexA int32
|
||||||
indexB int32
|
indexB int32
|
||||||
|
@ -1034,7 +1034,7 @@ func addBuckets(
|
||||||
spansA[0].Length++
|
spansA[0].Length++
|
||||||
spansA[0].Offset--
|
spansA[0].Offset--
|
||||||
goto nextLoop
|
goto nextLoop
|
||||||
} else {
|
}
|
||||||
spansA = append(spansA, Span{})
|
spansA = append(spansA, Span{})
|
||||||
copy(spansA[1:], spansA)
|
copy(spansA[1:], spansA)
|
||||||
spansA[0] = Span{Offset: indexB, Length: 1}
|
spansA[0] = Span{Offset: indexB, Length: 1}
|
||||||
|
@ -1044,7 +1044,6 @@ func addBuckets(
|
||||||
spansA[1].Offset -= indexB + 1
|
spansA[1].Offset -= indexB + 1
|
||||||
}
|
}
|
||||||
goto nextLoop
|
goto nextLoop
|
||||||
}
|
|
||||||
} else if spansA[0].Offset == indexB {
|
} else if spansA[0].Offset == indexB {
|
||||||
// Just add to first bucket.
|
// Just add to first bucket.
|
||||||
bucketsA[0] += bucketB
|
bucketsA[0] += bucketB
|
||||||
|
@ -1062,7 +1061,7 @@ func addBuckets(
|
||||||
iInSpan += deltaIndex
|
iInSpan += deltaIndex
|
||||||
bucketsA[iBucket] += bucketB
|
bucketsA[iBucket] += bucketB
|
||||||
break
|
break
|
||||||
} else {
|
}
|
||||||
deltaIndex -= remainingInSpan
|
deltaIndex -= remainingInSpan
|
||||||
iBucket += int(remainingInSpan)
|
iBucket += int(remainingInSpan)
|
||||||
iSpan++
|
iSpan++
|
||||||
|
@ -1105,7 +1104,6 @@ func addBuckets(
|
||||||
iInSpan = 0
|
iInSpan = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
nextLoop:
|
nextLoop:
|
||||||
indexA = indexB
|
indexA = indexB
|
||||||
|
|
|
@ -566,9 +566,8 @@ Loop:
|
||||||
if l.peek() == ':' {
|
if l.peek() == ':' {
|
||||||
l.emit(desc)
|
l.emit(desc)
|
||||||
return lexHistogram
|
return lexHistogram
|
||||||
} else {
|
|
||||||
l.errorf("missing `:` for histogram descriptor")
|
|
||||||
}
|
}
|
||||||
|
l.errorf("missing `:` for histogram descriptor")
|
||||||
} else {
|
} else {
|
||||||
l.errorf("bad histogram descriptor found: %q", word)
|
l.errorf("bad histogram descriptor found: %q", word)
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ func WithFunctions(functions map[string]*Function) Opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParser returns a new parser.
|
// NewParser returns a new parser.
|
||||||
func NewParser(input string, opts ...Opt) *parser {
|
func NewParser(input string, opts ...Opt) *parser { //nolint:revive // unexported-return.
|
||||||
p := parserPool.Get().(*parser)
|
p := parserPool.Get().(*parser)
|
||||||
|
|
||||||
p.functions = Functions
|
p.functions = Functions
|
||||||
|
|
|
@ -62,7 +62,7 @@ type OAuthConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AzureADConfig is used to store the config values.
|
// AzureADConfig is used to store the config values.
|
||||||
type AzureADConfig struct {
|
type AzureADConfig struct { //nolint:revive // exported.
|
||||||
// ManagedIdentity is the managed identity that is being used to authenticate.
|
// ManagedIdentity is the managed identity that is being used to authenticate.
|
||||||
ManagedIdentity *ManagedIdentityConfig `yaml:"managed_identity,omitempty"`
|
ManagedIdentity *ManagedIdentityConfig `yaml:"managed_identity,omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ func (s *TokenProviderTestSuite) TestNewTokenProvider() {
|
||||||
s.Assert().NotNil(actualTokenProvider.getAccessToken(context.Background()))
|
s.Assert().NotNil(actualTokenProvider.getAccessToken(context.Background()))
|
||||||
|
|
||||||
s.mockCredential.AssertNumberOfCalls(s.T(), "GetToken", 2*mockGetTokenCallCounter)
|
s.mockCredential.AssertNumberOfCalls(s.T(), "GetToken", 2*mockGetTokenCallCounter)
|
||||||
mockGetTokenCallCounter += 1
|
mockGetTokenCallCounter++
|
||||||
accessToken, err := actualTokenProvider.getAccessToken(context.Background())
|
accessToken, err := actualTokenProvider.getAccessToken(context.Background())
|
||||||
s.Assert().Nil(err)
|
s.Assert().Nil(err)
|
||||||
s.Assert().NotEqual(accessToken, testTokenString)
|
s.Assert().NotEqual(accessToken, testTokenString)
|
||||||
|
|
|
@ -25,7 +25,6 @@ var dropSanitizationGate = featuregate.GlobalRegistry().MustRegister(
|
||||||
//
|
//
|
||||||
// Exception is made for double-underscores which are allowed
|
// Exception is made for double-underscores which are allowed
|
||||||
func NormalizeLabel(label string) string {
|
func NormalizeLabel(label string) string {
|
||||||
|
|
||||||
// Trivial case
|
// Trivial case
|
||||||
if len(label) == 0 {
|
if len(label) == 0 {
|
||||||
return label
|
return label
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
type multiError []error
|
type multiError []error
|
||||||
|
|
||||||
// NewMulti returns multiError with provided errors added if not nil.
|
// NewMulti returns multiError with provided errors added if not nil.
|
||||||
func NewMulti(errs ...error) multiError {
|
func NewMulti(errs ...error) multiError { //nolint:revive // unexported-return.
|
||||||
m := multiError{}
|
m := multiError{}
|
||||||
m.Add(errs...)
|
m.Add(errs...)
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -970,7 +970,7 @@ type segmentBufReader struct {
|
||||||
off int // Offset of read data into current segment.
|
off int // Offset of read data into current segment.
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSegmentBufReader(segs ...*Segment) *segmentBufReader {
|
func NewSegmentBufReader(segs ...*Segment) io.ReadCloser {
|
||||||
if len(segs) == 0 {
|
if len(segs) == 0 {
|
||||||
return &segmentBufReader{}
|
return &segmentBufReader{}
|
||||||
}
|
}
|
||||||
|
@ -981,15 +981,16 @@ func NewSegmentBufReader(segs ...*Segment) *segmentBufReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSegmentBufReaderWithOffset(offset int, segs ...*Segment) (sbr *segmentBufReader, err error) {
|
func NewSegmentBufReaderWithOffset(offset int, segs ...*Segment) (io.ReadCloser, error) {
|
||||||
if offset == 0 || len(segs) == 0 {
|
if offset == 0 || len(segs) == 0 {
|
||||||
return NewSegmentBufReader(segs...), nil
|
return NewSegmentBufReader(segs...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sbr = &segmentBufReader{
|
sbr := &segmentBufReader{
|
||||||
buf: bufio.NewReaderSize(segs[0], 16*pageSize),
|
buf: bufio.NewReaderSize(segs[0], 16*pageSize),
|
||||||
segs: segs,
|
segs: segs,
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
_, err = sbr.buf.Discard(offset)
|
_, err = sbr.buf.Discard(offset)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ func (a Annotations) AsStrings(query string, maxAnnos int) []string {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:revive // error-naming.
|
||||||
var (
|
var (
|
||||||
// Currently there are only 2 types, warnings and info.
|
// Currently there are only 2 types, warnings and info.
|
||||||
// For now, info are visually identical with warnings as we have not updated
|
// For now, info are visually identical with warnings as we have not updated
|
||||||
|
@ -130,7 +131,7 @@ func (e annoErr) Unwrap() error {
|
||||||
|
|
||||||
// NewInvalidQuantileWarning is used when the user specifies an invalid quantile
|
// NewInvalidQuantileWarning is used when the user specifies an invalid quantile
|
||||||
// value, i.e. a float that is outside the range [0, 1] or NaN.
|
// value, i.e. a float that is outside the range [0, 1] or NaN.
|
||||||
func NewInvalidQuantileWarning(q float64, pos posrange.PositionRange) annoErr {
|
func NewInvalidQuantileWarning(q float64, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w, got %g", InvalidQuantileWarning, q),
|
Err: fmt.Errorf("%w, got %g", InvalidQuantileWarning, q),
|
||||||
|
@ -139,7 +140,7 @@ func NewInvalidQuantileWarning(q float64, pos posrange.PositionRange) annoErr {
|
||||||
|
|
||||||
// NewBadBucketLabelWarning is used when there is an error parsing the bucket label
|
// NewBadBucketLabelWarning is used when there is an error parsing the bucket label
|
||||||
// of a classic histogram.
|
// of a classic histogram.
|
||||||
func NewBadBucketLabelWarning(metricName, label string, pos posrange.PositionRange) annoErr {
|
func NewBadBucketLabelWarning(metricName, label string, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w of %q for metric name %q", BadBucketLabelWarning, label, metricName),
|
Err: fmt.Errorf("%w of %q for metric name %q", BadBucketLabelWarning, label, metricName),
|
||||||
|
@ -149,7 +150,7 @@ func NewBadBucketLabelWarning(metricName, label string, pos posrange.PositionRan
|
||||||
// NewMixedFloatsHistogramsWarning is used when the queried series includes both
|
// NewMixedFloatsHistogramsWarning is used when the queried series includes both
|
||||||
// float samples and histogram samples for functions that do not support mixed
|
// float samples and histogram samples for functions that do not support mixed
|
||||||
// samples.
|
// samples.
|
||||||
func NewMixedFloatsHistogramsWarning(metricName string, pos posrange.PositionRange) annoErr {
|
func NewMixedFloatsHistogramsWarning(metricName string, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w %q", MixedFloatsHistogramsWarning, metricName),
|
Err: fmt.Errorf("%w %q", MixedFloatsHistogramsWarning, metricName),
|
||||||
|
@ -158,7 +159,7 @@ func NewMixedFloatsHistogramsWarning(metricName string, pos posrange.PositionRan
|
||||||
|
|
||||||
// NewMixedClassicNativeHistogramsWarning is used when the queried series includes
|
// NewMixedClassicNativeHistogramsWarning is used when the queried series includes
|
||||||
// both classic and native histograms.
|
// both classic and native histograms.
|
||||||
func NewMixedClassicNativeHistogramsWarning(metricName string, pos posrange.PositionRange) annoErr {
|
func NewMixedClassicNativeHistogramsWarning(metricName string, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w %q", MixedClassicNativeHistogramsWarning, metricName),
|
Err: fmt.Errorf("%w %q", MixedClassicNativeHistogramsWarning, metricName),
|
||||||
|
@ -167,7 +168,7 @@ func NewMixedClassicNativeHistogramsWarning(metricName string, pos posrange.Posi
|
||||||
|
|
||||||
// NewPossibleNonCounterInfo is used when a named counter metric with only float samples does not
|
// NewPossibleNonCounterInfo is used when a named counter metric with only float samples does not
|
||||||
// have the suffixes _total, _sum, _count, or _bucket.
|
// have the suffixes _total, _sum, _count, or _bucket.
|
||||||
func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) annoErr {
|
func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w %q", PossibleNonCounterInfo, metricName),
|
Err: fmt.Errorf("%w %q", PossibleNonCounterInfo, metricName),
|
||||||
|
@ -176,7 +177,7 @@ func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) an
|
||||||
|
|
||||||
// NewHistogramQuantileForcedMonotonicityInfo is used when the input (classic histograms) to
|
// NewHistogramQuantileForcedMonotonicityInfo is used when the input (classic histograms) to
|
||||||
// histogram_quantile needs to be forced to be monotonic.
|
// histogram_quantile needs to be forced to be monotonic.
|
||||||
func NewHistogramQuantileForcedMonotonicityInfo(metricName string, pos posrange.PositionRange) annoErr {
|
func NewHistogramQuantileForcedMonotonicityInfo(metricName string, pos posrange.PositionRange) error {
|
||||||
return annoErr{
|
return annoErr{
|
||||||
PositionRange: pos,
|
PositionRange: pos,
|
||||||
Err: fmt.Errorf("%w %q", HistogramQuantileForcedMonotonicityInfo, metricName),
|
Err: fmt.Errorf("%w %q", HistogramQuantileForcedMonotonicityInfo, metricName),
|
||||||
|
|
Loading…
Reference in a new issue