Skip to content

Commit

Permalink
Tidy up log messages in line parsing
Browse files Browse the repository at this point in the history
Use go-error-style colons to add more details. Un-capitalize.

Signed-off-by: Matthias Rampke <[email protected]>
  • Loading branch information
matthiasr committed Sep 15, 2024
1 parent 0c2c1d9 commit 1a5428f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/line/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (p *Parser) LineToEvents(line string, sampleErrors prometheus.CounterVec, s
elements := strings.SplitN(line, ":", 2)
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
sampleErrors.WithLabelValues("malformed_line").Inc()
level.Debug(logger).Log("msg", "Bad line", "line", line)
level.Debug(logger).Log("msg", "bad line", "line", line)
return events
}

Expand All @@ -223,15 +223,15 @@ func (p *Parser) LineToEvents(line string, sampleErrors prometheus.CounterVec, s

// don't allow mixed tagging styles
sampleErrors.WithLabelValues("mixed_tagging_styles").Inc()
level.Debug(logger).Log("msg", "Bad line (multiple tagging styles)", "line", line)
level.Debug(logger).Log("msg", "bad line: multiple tagging styles", "line", line)
return events
}

var samples []string
lineParts := strings.SplitN(elements[1], "|", 3)
if len(lineParts) < 2 {
sampleErrors.WithLabelValues("not_enough_parts_after_colon").Inc()
level.Debug(logger).Log("msg", "Bad line: not enough '|'-delimited parts after first ':'", "line", line)
level.Debug(logger).Log("msg", "bad line: not enough '|'-delimited parts after first ':'", "line", line)
return events
}
if strings.Contains(lineParts[0], ":") {
Expand All @@ -256,7 +256,7 @@ func (p *Parser) LineToEvents(line string, sampleErrors prometheus.CounterVec, s
samples = aggLines
} else {
sampleErrors.WithLabelValues("invalid_extended_aggregate_type").Inc()
level.Debug(logger).Log("msg", "Bad line (invalid extended aggregate type)", "line", line)
level.Debug(logger).Log("msg", "bad line: invalid extended aggregate type", "line", line)
return events
}
} else if usingDogStatsDTags {
Expand All @@ -272,7 +272,7 @@ samples:
components := strings.Split(sample, "|")
if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc()
level.Debug(logger).Log("msg", "Bad component", "line", line)
level.Debug(logger).Log("msg", "bad component", "line", line)
continue
}
valueStr, statType := components[0], components[1]
Expand All @@ -284,7 +284,7 @@ samples:

value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
level.Debug(logger).Log("msg", "Bad value", "value", valueStr, "line", line)
level.Debug(logger).Log("msg", "bad value", "value", valueStr, "line", line)
sampleErrors.WithLabelValues("malformed_value").Inc()
continue
}
Expand Down

0 comments on commit 1a5428f

Please sign in to comment.