Skip to content

Commit

Permalink
Tidy up code
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Torres <[email protected]>
  • Loading branch information
fedetorres93 committed Jul 31, 2024
1 parent f66fb3f commit fce3f3d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
35 changes: 0 additions & 35 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ func (p *TextParser) startLabelName() stateFn {
p.parseError(fmt.Sprintf("invalid label name for metric %q", p.currentMF.GetName()))
return nil
}
// TODO(fedetorres93): check for metric name inside braces before other labels.
if p.skipBlankTabIfCurrentBlankTab(); p.err != nil {
return nil // Unexpected end of input.
}
Expand All @@ -306,10 +305,6 @@ func (p *TextParser) startLabelName() stateFn {
p.currentMetric = &dto.Metric{}
return p.startLabelName
case '}':
/* if p.currentMF == nil {
p.parseError("invalid metric name")
return nil
}*/
p.setOrCreateCurrentMF()
p.currentMetric = &dto.Metric{}
p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabel...)
Expand Down Expand Up @@ -337,16 +332,8 @@ func (p *TextParser) startLabelName() stateFn {
// labels to 'real' labels.
if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) &&
!(p.currentMF.GetType() == dto.MetricType_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) {
//p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPair)
p.currentLabel = append(p.currentLabel, p.currentLabelPair)
}
//if p.skipBlankTabIfCurrentBlankTab(); p.err != nil {
// return nil // Unexpected end of input.
//}
//if p.currentByte != '=' {
// p.parseError(fmt.Sprintf("expected '=' after label name, found %q", p.currentByte))
// return nil
//}
// Check for duplicate label names.
labels := make(map[string]struct{})
for _, l := range p.currentLabel {
Expand Down Expand Up @@ -637,7 +624,6 @@ func (p *TextParser) readTokenUntilNewline(recognizeEscapeSequence bool) {
case 'n':
p.currentToken.WriteByte('\n')
case '"':
//p.currentToken.WriteByte('\\')
p.currentToken.WriteByte('"')
default:
p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte))
Expand Down Expand Up @@ -685,32 +671,21 @@ func (p *TextParser) readTokenAsMetricName() {
return
}
escaped = false
/* p.currentByte, p.err = p.buf.ReadByte()
continue*/
} else {
switch p.currentByte {
case '"':
//p.currentToken.WriteByte(p.currentByte)
//p.currentByte, p.err = p.buf.ReadByte()
quoted = !quoted
if !quoted {
p.currentByte, p.err = p.buf.ReadByte()
return
}
/* if p.err != nil || !isValidMetricNameContinuation(p.currentByte, quoted) {
return
}*/
case '\n':
p.parseError(fmt.Sprintf("metric name %q contains unescaped new-line", p.currentToken.String()))
return
case '\\':
escaped = true
default:
p.currentToken.WriteByte(p.currentByte)
/* p.currentByte, p.err = p.buf.ReadByte()
if p.err != nil || !isValidMetricNameContinuation(p.currentByte, quoted) || (!quoted && p.currentByte == ' ') {
return
}*/
}
}
p.currentByte, p.err = p.buf.ReadByte()
Expand Down Expand Up @@ -747,31 +722,21 @@ func (p *TextParser) readTokenAsLabelName() {
return
}
escaped = false
//continue
} else {
switch p.currentByte {
case '"':
//p.currentToken.WriteByte(p.currentByte)
//p.currentByte, p.err = p.buf.ReadByte()
quoted = !quoted
if !quoted {
p.currentByte, p.err = p.buf.ReadByte()
return
}
/* if p.err != nil || !isValidLabelNameContinuation(p.currentByte, quoted) {
return
}*/
case '\n':
p.parseError(fmt.Sprintf("label name %q contains unescaped new-line", p.currentToken.String()))
return
case '\\':
escaped = true
default:
p.currentToken.WriteByte(p.currentByte)
/* p.currentByte, p.err = p.buf.ReadByte()
if p.err != nil || !isValidLabelNameContinuation(p.currentByte, quoted) || (!quoted && p.currentByte == '=') {
return
}*/
}
}
p.currentByte, p.err = p.buf.ReadByte()
Expand Down
6 changes: 2 additions & 4 deletions expfmt/text_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ request_duration_microseconds_count 2693
got, ok := out[expected.GetName()]
if !ok {
t.Errorf(
"%d. expected MetricFamily %q, found none. got %q",
i, expected.GetName(), got.GetName(),
"%d. expected MetricFamily %q, found none",
i, expected.GetName(),
)
continue
}
Expand Down Expand Up @@ -700,7 +700,6 @@ metric 4.12
in: `@invalidmetric{label="bla"} 3.14 2`,
err: "text format parsing error in line 1: invalid metric name",
},
// TODO(fedetorres93): this test is failing because the metric starts with braces but has no metric name in it. Fix logic to take this into account (add another stateFn?)
// 17:
{
in: `{label="bla"} 3.14 2`,
Expand All @@ -714,7 +713,6 @@ metric_bucket{le="bla"} 3.14
`,
err: "text format parsing error in line 3: expected float as value for 'le' label",
},
// TODO(fedetorres93): check if this test should now pass (it's testing a label value, so I think it's ok)
// 19: Invalid UTF-8 in label value.
{
in: "metric{l=\"\xbd\"} 3.14\n",
Expand Down

0 comments on commit fce3f3d

Please sign in to comment.