mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-08 03:15:09 -04:00
Escape label values in prometheus metrics
This commit is contained in:
parent
a8d8bf92e0
commit
32015e1109
2 changed files with 40 additions and 3 deletions
|
@ -16,7 +16,8 @@
|
|||
from tests import unittest
|
||||
|
||||
from synapse.metrics.metric import (
|
||||
CounterMetric, CallbackMetric, DistributionMetric, CacheMetric
|
||||
CounterMetric, CallbackMetric, DistributionMetric, CacheMetric,
|
||||
_escape_label_value,
|
||||
)
|
||||
|
||||
|
||||
|
@ -171,3 +172,21 @@ class CacheMetricTestCase(unittest.TestCase):
|
|||
'cache:size{name="cache_name"} 1',
|
||||
'cache:evicted_size{name="cache_name"} 2',
|
||||
])
|
||||
|
||||
|
||||
class LabelValueEscapeTestCase(unittest.TestCase):
|
||||
def test_simple(self):
|
||||
string = "safjhsdlifhyskljfksdfh"
|
||||
self.assertEqual(string, _escape_label_value(string))
|
||||
|
||||
def test_escape(self):
|
||||
self.assertEqual(
|
||||
"abc\\\"def\\nghi\\\\",
|
||||
_escape_label_value("abc\"def\nghi\\"),
|
||||
)
|
||||
|
||||
def test_sequence_of_escapes(self):
|
||||
self.assertEqual(
|
||||
"abc\\\"def\\nghi\\\\\\n",
|
||||
_escape_label_value("abc\"def\nghi\\\n"),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue