Skip to content

Commit 294a119

Browse files
raph5valyala
andauthored
Forbid metrics with line breaks (#87)
# The Issue Im using victoriametrics to monitor the usage of a sqlite database: `store_sqlite_request_total{query="DELETE FROM 'Order'",status="success"} 2` Though I had problem with particular queries being not present in victoriametrics. And It turns out that it was caused by me recording queries with not escaped line breaks. Here is a fragment of the resulting /metrics endpoint: ``` store_sqlite_request_total{query=" SELECT DISTINCT o.LocationId FROM \"Order\" o LEFT JOIN Location l ON o.LocationId = l.Id WHERE l.Id IS NULL AND o.LocationId >= 60000000 AND o.LocationId <= 64000000; ",status="success"} 2 store_sqlite_request_total{query="DELETE FROM `Order`",status="success"} 2 store_sqlite_request_total{query="INSERT OR REPLACE INTO History VALUES (?,?,?)",status="success"} 15300 ``` # A Proposed Solution Issue a warning or error when being handed a metrics with a line break. Im the PR I opted to simply error. --------- Co-authored-by: Aliaksandr Valialkin <[email protected]>
1 parent 4ab087d commit 294a119

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

validator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func ValidateMetric(s string) error {
1717
if len(s) == 0 {
1818
return fmt.Errorf("metric cannot be empty")
1919
}
20+
if strings.IndexByte(s, '\n') >= 0 {
21+
return fmt.Errorf("metric cannot contain line breaks")
22+
}
2023
n := strings.IndexByte(s, '{')
2124
if n < 0 {
2225
return validateIdent(s)

0 commit comments

Comments
 (0)