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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ linters:
- errorlint
- exptostd
- fatcontext
#- gocritic
- gocritic
- godot
- govet
- loggercheck
Expand Down
12 changes: 6 additions & 6 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}

t.mtx.RLock()
equal := bytes.Equal(caHash[:], t.hashCAData) &&
bytes.Equal(certHash[:], t.hashCertData) &&
bytes.Equal(keyHash[:], t.hashKeyData)
equal := bytes.Equal(caHash, t.hashCAData) &&
bytes.Equal(certHash, t.hashCertData) &&
bytes.Equal(keyHash, t.hashKeyData)
rt := t.rt
t.mtx.RUnlock()
if equal {
Expand All @@ -1387,9 +1387,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

t.mtx.Lock()
t.rt = rt
t.hashCAData = caHash[:]
t.hashCertData = certHash[:]
t.hashKeyData = keyHash[:]
t.hashCAData = caHash
t.hashCertData = certHash
t.hashKeyData = keyHash
t.mtx.Unlock()

return rt.RoundTrip(req)
Expand Down
9 changes: 5 additions & 4 deletions config/http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,14 @@ func TestNewClientFromConfig(t *testing.T) {
},
handler: func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok {
switch {
case !ok:
fmt.Fprintf(w, "The Authorization header wasn't set")
} else if ExpectedUsername != username {
case ExpectedUsername != username:
fmt.Fprintf(w, "The expected username (%s) differs from the obtained username (%s).", ExpectedUsername, username)
} else if ExpectedPassword != password {
case ExpectedPassword != password:
fmt.Fprintf(w, "The expected password (%s) differs from the obtained password (%s).", ExpectedPassword, password)
} else {
default:
fmt.Fprint(w, ExpectedMessage)
}
},
Expand Down
6 changes: 3 additions & 3 deletions expfmt/openmetrics_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E

// Finally the samples, one line for each.
if metricType == dto.MetricType_COUNTER && strings.HasSuffix(name, "_total") {
compliantName = compliantName + "_total"
compliantName += "_total"
}
for _, metric := range in.Metric {
switch metricType {
Expand Down Expand Up @@ -640,11 +640,11 @@ func writeExemplar(w enhancedWriter, e *dto.Exemplar) (int, error) {
if err != nil {
return written, err
}
err = (*e).Timestamp.CheckValid()
err = e.Timestamp.CheckValid()
if err != nil {
return written, err
}
ts := (*e).Timestamp.AsTime()
ts := e.Timestamp.AsTime()
// TODO(beorn7): Format this directly from components of ts to
// avoid overflow/underflow and precision issues of the float
// conversion.
Expand Down
7 changes: 4 additions & 3 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,24 @@ func (p *TextParser) readingValue() stateFn {
// When we are here, we have read all the labels, so for the
// special case of a summary/histogram, we can finally find out
// if the metric already exists.
if p.currentMF.GetType() == dto.MetricType_SUMMARY {
switch p.currentMF.GetType() {
case dto.MetricType_SUMMARY:
signature := model.LabelsToSignature(p.currentLabels)
if summary := p.summaries[signature]; summary != nil {
p.currentMetric = summary
} else {
p.summaries[signature] = p.currentMetric
p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
}
} else if p.currentMF.GetType() == dto.MetricType_HISTOGRAM {
case dto.MetricType_HISTOGRAM:
signature := model.LabelsToSignature(p.currentLabels)
if histogram := p.histograms[signature]; histogram != nil {
p.currentMetric = histogram
} else {
p.histograms[signature] = p.currentMetric
p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
}
} else {
default:
p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
}
if p.readTokenUntilWhitespace(); p.err != nil {
Expand Down
25 changes: 14 additions & 11 deletions model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,14 @@ func EscapeName(name string, scheme EscapingScheme) string {
case DotsEscaping:
// Do not early return for legacy valid names, we still escape underscores.
for i, b := range name {
if b == '_' {
switch {
case b == '_':
escaped.WriteString("__")
} else if b == '.' {
case b == '.':
escaped.WriteString("_dot_")
} else if isValidLegacyRune(b, i) {
case isValidLegacyRune(b, i):
escaped.WriteRune(b)
} else {
default:
escaped.WriteString("__")
}
}
Expand All @@ -452,13 +453,14 @@ func EscapeName(name string, scheme EscapingScheme) string {
}
escaped.WriteString("U__")
for i, b := range name {
if b == '_' {
switch {
case b == '_':
escaped.WriteString("__")
} else if isValidLegacyRune(b, i) {
case isValidLegacyRune(b, i):
escaped.WriteRune(b)
} else if !utf8.ValidRune(b) {
case !utf8.ValidRune(b):
escaped.WriteString("_FFFD_")
} else {
default:
escaped.WriteRune('_')
escaped.WriteString(strconv.FormatInt(int64(b), 16))
escaped.WriteRune('_')
Expand Down Expand Up @@ -534,11 +536,12 @@ func UnescapeName(name string, scheme EscapingScheme) string {
}
r := lower(escapedName[i])
utf8Val *= 16
if r >= '0' && r <= '9' {
switch {
case r >= '0' && r <= '9':
utf8Val += uint(r) - '0'
} else if r >= 'a' && r <= 'f' {
case r >= 'a' && r <= 'f':
utf8Val += uint(r) - 'a' + 10
} else {
default:
return name
}
i++
Expand Down
2 changes: 1 addition & 1 deletion model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (t *Time) UnmarshalJSON(b []byte) error {
if prec < 0 {
p[1] = p[1][:dotPrecision]
} else if prec > 0 {
p[1] = p[1] + strings.Repeat("0", prec)
p[1] += strings.Repeat("0", prec)
}

va, err := strconv.ParseInt(p[1], 10, 32)
Expand Down
7 changes: 4 additions & 3 deletions model/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ func (ss SampleStream) String() string {
}

func (ss SampleStream) MarshalJSON() ([]byte, error) {
if len(ss.Histograms) > 0 && len(ss.Values) > 0 {
switch {
case len(ss.Histograms) > 0 && len(ss.Values) > 0:
v := struct {
Metric Metric `json:"metric"`
Values []SamplePair `json:"values"`
Expand All @@ -202,7 +203,7 @@ func (ss SampleStream) MarshalJSON() ([]byte, error) {
Histograms: ss.Histograms,
}
return json.Marshal(&v)
} else if len(ss.Histograms) > 0 {
case len(ss.Histograms) > 0:
v := struct {
Metric Metric `json:"metric"`
Histograms []SampleHistogramPair `json:"histograms"`
Expand All @@ -211,7 +212,7 @@ func (ss SampleStream) MarshalJSON() ([]byte, error) {
Histograms: ss.Histograms,
}
return json.Marshal(&v)
} else {
default:
v := struct {
Metric Metric `json:"metric"`
Values []SamplePair `json:"values"`
Expand Down
Loading