Skip to content

Commit eef9af4

Browse files
committed
lint and imports
Signed-off-by: Owen Williams <[email protected]>
1 parent eaeb81b commit eef9af4

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

expfmt/encode.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import (
1919
"net/http"
2020

2121
"google.golang.org/protobuf/encoding/protodelim"
22-
"github.com/prometheus/common/model"
2322
"google.golang.org/protobuf/encoding/prototext"
2423

24+
"github.com/prometheus/common/model"
25+
2526
"github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg"
2627

2728
dto "github.com/prometheus/client_model/go"
@@ -125,15 +126,15 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
125126
}
126127
if ac.Type+"/"+ac.SubType == OpenMetricsType && (ver == OpenMetricsVersion_0_0_1 || ver == OpenMetricsVersion_1_0_0 || ver == OpenMetricsVersion_2_0_0 || ver == "") {
127128
switch ver {
128-
case OpenMetricsVersion_2_0_0:
129-
if ac.Params["validchars"] == UTF8Valid {
130-
return FmtOpenMetrics_2_0_0 + FmtUTF8Param
131-
}
132-
return FmtOpenMetrics_2_0_0
133-
case OpenMetricsVersion_1_0_0:
134-
return FmtOpenMetrics_1_0_0
135-
default:
136-
return FmtOpenMetrics_0_0_1
129+
case OpenMetricsVersion_2_0_0:
130+
if ac.Params["validchars"] == UTF8Valid {
131+
return FmtOpenMetrics_2_0_0 + FmtUTF8Param
132+
}
133+
return FmtOpenMetrics_2_0_0
134+
case OpenMetricsVersion_1_0_0:
135+
return FmtOpenMetrics_1_0_0
136+
default:
137+
return FmtOpenMetrics_0_0_1
137138
}
138139
}
139140
}
@@ -154,19 +155,18 @@ func NewEncoder(w io.Writer, format Format) Encoder {
154155
escapingScheme = model.NoEscaping
155156
}
156157
switch format.FormatType() {
157-
case TypeProtoDelim:
158-
return encoderCloser{
159-
encode: func(v *dto.MetricFamily) error {
160-
_, err := pbutil.WriteDelimited(w, model.EscapeMetricFamily(v, escapingScheme))
161-
return err
162-
},
163-
close: func() error { return nil },
164-
}
158+
case TypeProtoDelim:
159+
return encoderCloser{
160+
encode: func(v *dto.MetricFamily) error {
161+
_, err := protodelim.MarshalTo(w, model.EscapeMetricFamily(v, escapingScheme))
162+
return err
163+
},
164+
close: func() error { return nil },
165+
}
165166
case TypeProtoCompact:
166167
return encoderCloser{
167168
encode: func(v *dto.MetricFamily) error {
168-
_, err := fmt.Fprintln(w, model.EscapeMetricFamily(v, escapingScheme).String())
169-
_, err := protodelim.MarshalTo(w, v)
169+
_, err := protodelim.MarshalTo(w, model.EscapeMetricFamily(v, escapingScheme))
170170
return err
171171
},
172172
close: func() error { return nil },

expfmt/encode_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import (
1818
"net/http"
1919
"testing"
2020

21-
dto "github.com/prometheus/client_model/go"
22-
"github.com/prometheus/common/model"
2321
"google.golang.org/protobuf/proto"
22+
23+
"github.com/prometheus/common/model"
24+
25+
dto "github.com/prometheus/client_model/go"
2426
)
2527

2628
func TestNegotiate(t *testing.T) {
@@ -294,7 +296,6 @@ func TestEncode(t *testing.T) {
294296
}
295297
}
296298

297-
298299
func TestEscapedEncode(t *testing.T) {
299300
var buff bytes.Buffer
300301
delimEncoder := NewEncoder(&buff, FmtProtoDelim+"; escaping=underscores")
@@ -310,7 +311,7 @@ func TestEscapedEncode(t *testing.T) {
310311
{
311312
Label: []*dto.LabelPair{
312313
{
313-
Name: proto.String("dotted.label.name"),
314+
Name: proto.String("dotted.label.name"),
314315
Value: proto.String("my.label.value"),
315316
},
316317
},
@@ -378,4 +379,4 @@ U__foo_2e_metric{U__dotted_2e_label_2e_name="my.label.value"} 8
378379
if string(out) != expected {
379380
t.Errorf("expected TextEncoder to return %s, but got %s instead", expected, string(out))
380381
}
381-
}
382+
}

expfmt/expfmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
FmtOpenMetrics_2_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_2_0_0 + `; charset=utf-8`
4848

4949
// UTF8 and Escaping Formats
50-
FmtUTF8Param Format = `; validchars=utf8`
50+
FmtUTF8Param Format = `; validchars=utf8`
5151
)
5252

5353
const (

expfmt/openmetrics_create_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"google.golang.org/protobuf/types/known/timestamppb"
2525

2626
dto "github.com/prometheus/client_model/go"
27+
2728
"github.com/prometheus/common/model"
2829
)
2930

expfmt/text_create_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"google.golang.org/protobuf/proto"
2323

2424
dto "github.com/prometheus/client_model/go"
25+
2526
"github.com/prometheus/common/model"
2627
)
2728

model/metric.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
// underscores are replaced with double underscores. This is the only escaping
5454
// format that is fully round-trippable.
5555
ValueEncodingEscaping
56-
56+
5757
// UnderscoreEscaping replaces all legacy-invalid characters with underscores.
5858
// This escaping cannot be reversed.
5959
UnderscoreEscaping
@@ -65,10 +65,10 @@ const (
6565
)
6666

6767
const (
68-
EscapeNone = "none"
69-
EscapeUnderscores = "underscores"
70-
EscapeDots = "dots"
71-
EscapeValues = "values"
68+
EscapeNone = "none"
69+
EscapeUnderscores = "underscores"
70+
EscapeDots = "dots"
71+
EscapeValues = "values"
7272
)
7373

7474
var (
@@ -85,7 +85,7 @@ var (
8585
// escaped when presented to systems that do not support UTF-8 names.
8686
NameEscapingScheme = ValueEncodingEscaping
8787

88-
// MetricNameRE is a regular expression matching valid metric
88+
// MetricNameRE is a regular expression matching valid metric
8989
// names. Note that the IsValidMetricName function performs the same
9090
// check but faster than a match with this regular expression.
9191
MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`)
@@ -448,6 +448,6 @@ func ToEscapingScheme(s string) (EscapingScheme, error) {
448448
case EscapeValues:
449449
return ValueEncodingEscaping, nil
450450
default:
451-
return NoEscaping, fmt.Errorf("unknown format scheme " + s)
451+
return NoEscaping, fmt.Errorf("unknown format scheme " + s)
452452
}
453453
}

0 commit comments

Comments
 (0)