Skip to content

Commit

Permalink
Adds tests to test longer lines
Browse files Browse the repository at this point in the history
  • Loading branch information
possibull committed Feb 10, 2025
1 parent cfcc9fc commit b5cd8af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion prettifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,21 @@ func appendPrettifiedExpr(dst []byte, e Expr, indent int, needParens bool) []byt
lfss := t.labelFilterss
offset := 0
metricName := getMetricNameFromLabelFilterss(lfss)
metricNamehasEscapedChars := hasEscapedChars(metricName)

if metricName != "" {
offset = 1
}
dst = appendIndent(dst, indent)
dst = appendEscapedIdent(dst, metricName)
if !metricNamehasEscapedChars {
dst = appendEscapedIdent(dst, metricName)
}
if !isOnlyMetricNameInLabelFilterss(lfss) {
dst = append(dst, "{\n"...)
if metricNamehasEscapedChars {
dst = ifEscapedCharsAppendQuotedIdent(dst, metricName)
dst = append(dst, ',', ' ', '\n')
}
for i, lfs := range lfss {
lfs = lfs[offset:]
if len(lfs) == 0 {
Expand Down
13 changes: 13 additions & 0 deletions prettifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func TestPrettifySuccess(t *testing.T) {
another(`process_cpu_seconds_total{foo="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"}`,
`process_cpu_seconds_total{
foo="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"
}`)
another(`process_cpu_seconds_total{"3foo"="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"}`,
`process_cpu_seconds_total{
"3foo"="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"
}`)
another(`{"process_cpu_seconds_total", "foo"="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"}`,
`process_cpu_seconds_total{
foo="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"
}`)
another(`{"3process_cpu_seconds_total", "foo"="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"}`,
`{
"3process_cpu_seconds_total",
foo="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk"
}`)
another(`process_cpu_seconds_total{foo="bar",xjljljlkjopiwererrewre="asdfdsfdsfsdfdsfjkljlk",very_long_label_aaaaaaaaaaaaaaa="fdsfdsffdsfs"}`,
`process_cpu_seconds_total{
Expand Down

0 comments on commit b5cd8af

Please sign in to comment.