Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ linters:
# Allow functions with test or bench signatures.
- allowTypesBefore: '*testing.T,testing.TB'
- name: context-keys-type
#- name: dot-imports
#- name: early-return
# arguments:
# - "preserveScope"
- name: dot-imports
- name: early-return
arguments:
- "preserveScope"
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
# See https://github.com/mgechev/revive/issues/386
- name: empty-block
Expand All @@ -133,27 +133,27 @@ linters:
- name: error-return
- name: error-strings
- name: errorf
#- name: exported
#- name: increment-decrement
#- name: indent-error-flow
# arguments:
# - "preserveScope"
- name: exported
- name: increment-decrement
- name: indent-error-flow
arguments:
- "preserveScope"
- name: package-comments
# TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them.
disabled: true
- name: range
#- name: receiver-naming
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming
#- name: unexported-return
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
#- name: unused-receiver
#- name: var-declaration
#- name: var-naming
- name: unused-receiver
- name: var-declaration
- name: var-naming
testifylint:
enable-all: true
disable:
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Secret string
// MarshalSecretValue if set to true will expose Secret type
// through the marshal interfaces. Useful for outside projects
// that load and marshal the Prometheus config.
var MarshalSecretValue bool = false
var MarshalSecretValue = false

// MarshalYAML implements the yaml.Marshaler interface for Secrets.
func (s Secret) MarshalYAML() (interface{}, error) {
Expand Down
18 changes: 12 additions & 6 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func nonZeroCount[T comparable](values ...T) int {
var zero T
for _, value := range values {
if value != zero {
count += 1
count++
}
}
return count
Expand Down Expand Up @@ -542,8 +542,14 @@ func (s *secretManagerOption) applyToTLSConfigOptions(opts *tlsConfigOptions) {
opts.secretManager = s.secretManager
}

// SecretManagerOption is an option for providing a SecretManager.
type SecretManagerOption interface {
TLSConfigOption
HTTPClientOption
}

// WithSecretManager allows setting the secret manager.
func WithSecretManager(manager SecretManager) *secretManagerOption {
func WithSecretManager(manager SecretManager) SecretManagerOption {
Comment thread
aknuds1 marked this conversation as resolved.
return &secretManagerOption{
secretManager: manager,
}
Expand Down Expand Up @@ -726,11 +732,11 @@ func (s *InlineSecret) Fetch(context.Context) (string, error) {
return s.text, nil
}

func (s *InlineSecret) Description() string {
func (*InlineSecret) Description() string {
return "inline"
}

func (s *InlineSecret) Immutable() bool {
func (*InlineSecret) Immutable() bool {
return true
}

Expand All @@ -754,7 +760,7 @@ func (s *FileSecret) Description() string {
return "file " + s.file
}

func (s *FileSecret) Immutable() bool {
func (*FileSecret) Immutable() bool {
return false
}

Expand All @@ -772,7 +778,7 @@ func (s *refSecret) Description() string {
return "ref " + s.ref
}

func (s *refSecret) Immutable() bool {
func (*refSecret) Immutable() bool {
return false
}

Expand Down
12 changes: 8 additions & 4 deletions expfmt/expfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const (
ProtoType = `application/vnd.google.protobuf`
ProtoProtocol = `io.prometheus.client.MetricFamily`
// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead.
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
OpenMetricsType = `application/openmetrics-text`
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
OpenMetricsType = `application/openmetrics-text`
//nolint:revive // Allow for underscores.
OpenMetricsVersion_0_0_1 = "0.0.1"
//nolint:revive // Allow for underscores.
OpenMetricsVersion_1_0_0 = "1.0.0"

// The Content-Type values for the different wire protocols. Do not do direct
Expand All @@ -54,8 +56,10 @@ const (
// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead.
FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text`
// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead.
//nolint:revive // Allow for underscores.
FmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead.
//nolint:revive // Allow for underscores.
FmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
)

Expand Down Expand Up @@ -188,8 +192,8 @@ func (f Format) FormatType() FormatType {
// Format contains a escaping=allow-utf-8 term, it will select NoEscaping. If a valid
// "escaping" term exists, that will be used. Otherwise, the global default will
// be returned.
func (format Format) ToEscapingScheme() model.EscapingScheme {
for _, p := range strings.Split(string(format), ";") {
func (f Format) ToEscapingScheme() model.EscapingScheme {
for _, p := range strings.Split(string(f), ";") {
toks := strings.Split(p, "=")
if len(toks) != 2 {
continue
Expand Down
5 changes: 2 additions & 3 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,12 @@ func (p *TextParser) startLabelName() stateFn {
labels := make(map[string]struct{})
for _, l := range p.currentLabelPairs {
lName := l.GetName()
if _, exists := labels[lName]; !exists {
labels[lName] = struct{}{}
} else {
if _, exists := labels[lName]; exists {
p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
p.currentLabelPairs = nil
return nil
}
labels[lName] = struct{}{}
}
return p.startLabelValue
}
Expand Down
10 changes: 5 additions & 5 deletions model/labelset.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func (ls LabelSet) Clone() LabelSet {
}

// Merge is a helper function to non-destructively merge two label sets.
func (l LabelSet) Merge(other LabelSet) LabelSet {
result := make(LabelSet, len(l))
func (ls LabelSet) Merge(other LabelSet) LabelSet {
result := make(LabelSet, len(ls))

for k, v := range l {
for k, v := range ls {
result[k] = v
}

Expand All @@ -140,7 +140,7 @@ func (ls LabelSet) FastFingerprint() Fingerprint {
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (l *LabelSet) UnmarshalJSON(b []byte) error {
func (ls *LabelSet) UnmarshalJSON(b []byte) error {
var m map[LabelName]LabelValue
if err := json.Unmarshal(b, &m); err != nil {
return err
Expand All @@ -153,6 +153,6 @@ func (l *LabelSet) UnmarshalJSON(b []byte) error {
return fmt.Errorf("%q is not a valid label name", ln)
}
}
*l = LabelSet(m)
*ls = LabelSet(m)
return nil
}
2 changes: 1 addition & 1 deletion model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s ValidationScheme) IsValidLabelName(labelName string) bool {
}

// Type implements the pflag.Value interface.
func (s ValidationScheme) Type() string {
func (ValidationScheme) Type() string {
return "validationScheme"
}

Expand Down
2 changes: 1 addition & 1 deletion model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (d *Duration) Set(s string) error {
}

// Type implements pflag.Value.
func (d *Duration) Type() string {
func (*Duration) Type() string {
return "duration"
}

Expand Down
6 changes: 3 additions & 3 deletions model/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ func (m Matrix) Len() int { return len(m) }
func (m Matrix) Less(i, j int) bool { return m[i].Metric.Before(m[j].Metric) }
func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func (mat Matrix) String() string {
matCp := make(Matrix, len(mat))
copy(matCp, mat)
func (m Matrix) String() string {
matCp := make(Matrix, len(m))
copy(matCp, m)
sort.Sort(matCp)

strs := make([]string, len(matCp))
Expand Down
10 changes: 5 additions & 5 deletions model/value_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ func (s *HistogramBucket) Equal(o *HistogramBucket) bool {
return s == o || (s.Boundaries == o.Boundaries && s.Lower == o.Lower && s.Upper == o.Upper && s.Count == o.Count)
}

func (b HistogramBucket) String() string {
func (s HistogramBucket) String() string {
var sb strings.Builder
lowerInclusive := b.Boundaries == 1 || b.Boundaries == 3
upperInclusive := b.Boundaries == 0 || b.Boundaries == 3
lowerInclusive := s.Boundaries == 1 || s.Boundaries == 3
upperInclusive := s.Boundaries == 0 || s.Boundaries == 3
if lowerInclusive {
sb.WriteRune('[')
} else {
sb.WriteRune('(')
}
fmt.Fprintf(&sb, "%g,%g", b.Lower, b.Upper)
fmt.Fprintf(&sb, "%g,%g", s.Lower, s.Upper)
if upperInclusive {
sb.WriteRune(']')
} else {
sb.WriteRune(')')
}
fmt.Fprintf(&sb, ":%v", b.Count)
fmt.Fprintf(&sb, ":%v", s.Count)
return sb.String()
}

Expand Down
4 changes: 2 additions & 2 deletions model/value_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (et *ValueType) UnmarshalJSON(b []byte) error {
return nil
}

func (e ValueType) String() string {
switch e {
func (et ValueType) String() string {
switch et {
case ValNone:
return "<ValNone>"
case ValScalar:
Expand Down
2 changes: 1 addition & 1 deletion server/static_file_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type dummyFileSystem struct{}

func (fs dummyFileSystem) Open(string) (http.File, error) {
func (dummyFileSystem) Open(string) (http.File, error) {
return http.Dir(".").Open(".")
}

Expand Down
Loading