Skip to content

Commit

Permalink
update code for review comment
Browse files Browse the repository at this point in the history
Signed-off-by: jyz0309 <[email protected]>
  • Loading branch information
jyz0309 committed Jul 31, 2024
1 parent 43bf97d commit 9dbda3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
14 changes: 7 additions & 7 deletions expfmt/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewDecoder(r io.Reader, format Format) Decoder {
case TypeProtoDelim:
return &protoDecoder{r: bufio.NewReader(r)}
case TypeOpenMetrics:
return &openMetricsDecoder{}
return &openMetricsDecoder{r: r}
}
return &textDecoder{r: r}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ type openMetricsDecoder struct {
}

// Decode implements Decoder.
func (d *openMetricsDecoder) Decode(v *dto.MetricFamily) error {
func (d *openMetricsDecoder) Decode(mf *dto.MetricFamily) error {
if d.err == nil {
// Read all metrics in one shot.
var p OpenMetricsParser
Expand All @@ -136,11 +136,11 @@ func (d *openMetricsDecoder) Decode(v *dto.MetricFamily) error {
}
// Pick off one MetricFamily per Decode until there's nothing left.
for key, fam := range d.fams {
v.Name = fam.Name
v.Help = fam.Help
v.Type = fam.Type
v.Unit = fam.Unit
v.Metric = fam.Metric
mf.Name = fam.Name
mf.Help = fam.Help
mf.Type = fam.Type
mf.Unit = fam.Unit
mf.Metric = fam.Metric
delete(d.fams, key)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion expfmt/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ metric1_total 4
)

dec := &SampleDecoder{
Dec: &openMetricsDecoder{r: strings.NewReader(in)},
Dec: NewDecoder(strings.NewReader(in), fmtOpenMetrics_1_0_0),

Check failure on line 154 in expfmt/decode_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: fmtOpenMetrics_1_0_0 (typecheck)
Opts: &DecodeOptions{
Timestamp: ts,
},
Expand Down
2 changes: 1 addition & 1 deletion expfmt/openmetrics_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (p *OpenMetricsParser) readingMetricName() stateFn {
return nil
}
}
// metric is not new metric if the metrics is end with "_created".
// metric is not new if the metric ends with "_created".
if !p.currentIsMetricCreated {
p.currentMetric = &dto.Metric{}
}
Expand Down
12 changes: 2 additions & 10 deletions expfmt/openmetrics_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1621,16 +1621,8 @@ func testOpenMetricParseError(t testing.TB) {
`,
err: `openmetrics format parsing error in line 3: expected unit as metric name suffix, found metric "metric"`,
},
// 38: metrics ends without unit
{
in: `
# TYPE metric counter
# UNIT metric seconds
`,
err: `openmetrics format parsing error in line 3: expected unit as metric name suffix, found metric "metric"`,
},

// 39: metrics ends without EOF
// 38: metrics ends without EOF
{
in: `
# TYPE metric_seconds counter
Expand All @@ -1639,7 +1631,7 @@ func testOpenMetricParseError(t testing.TB) {
err: `openmetrics format parsing error in line 4: expected EOF keyword at the end`,
},

// 40: line after EOF
// 39: line after EOF
{
in: `
# EOF
Expand Down

0 comments on commit 9dbda3d

Please sign in to comment.