TritonDataCenter / node-artedi

a library for measuring fish
2 stars 4 forks source link

node-artedi#16 label values not escaped properly #27

Closed bahamat closed 3 years ago

bahamat commented 3 years ago

This also brings in the change from #26.

bahamat commented 3 years ago

That's a good question. To demonstrate this, I mocked up an example that can be linted with promtool.

Here's the example bad text

> { printf '# HELP unescaped_total wtf\n'
printf '# TYPE unescaped_total counter\n'
printf 'unescaped_total{badquote=""quote",badnewline="newline\n",badbackslash="\backslash"} 1\n'
}
# HELP unescaped_total wtf
# TYPE unescaped_total counter
unescaped_total{badquote=""quote",badnewline="newline
",badbackslash=ackslash"} 1

When passing this to promtool, it fails linting

> { printf '# HELP unescaped_total wtf\n'
printf '# TYPE unescaped_total counter\n'
printf 'unescaped_total{badquote=""quote",badnewline="newline\n",badbackslash="\backslash"} 1\n'
} | promtool check metrics

error while linting: text format parsing error in line 3: unexpected end of label value ""
> echo $?
1

And here's the same text, but properly escaped.

> { printf '# HELP escaped_total wtf\n'
printf '# TYPE escaped_total counter\n'
printf 'escaped_total{badquote="\"quote",badnewline="newline\\n",badbackslash="\\\\backslash"} 1\n'
}
# HELP escaped_total wtf
# TYPE escaped_total counter
escaped_total{badquote="\"quote",badnewline="newline\n",badbackslash="\\backslash"} 1

When this is passed to promtool, linting validation succeeds.

> { printf '# HELP escaped_total wtf\n'
printf '# TYPE escaped_total counter\n'
printf 'escaped_total{badquote="\"quote",badnewline="newline\\n",badbackslash="\\\\backslash"} 1\n'
} | promtool check metrics

> echo $?
0