Fix samples with dots in sample name
This patch fixes Prometheus publisher behavior when Ceilometer metric names contain dots by replacing them with underscores. Prometheus does not accept metrics with dots. Change-Id: If4799a1b17001c0535413a26ec5d2f427e52f168 Signed-off-by: Yanos Angelopoulos <yanos@admin.grnet.gr>
This commit is contained in:
parent
8288ad511c
commit
ab4b87bfc2
|
@ -55,9 +55,11 @@ class PrometheusPublisher(http.HttpPublisher):
|
|||
elif s.type == sample.TYPE_GAUGE:
|
||||
metric_type = "gauge"
|
||||
|
||||
if metric_type and s.name not in doc_done:
|
||||
data += "# TYPE %s %s\n" % (s.name, metric_type)
|
||||
doc_done.add(s.name)
|
||||
curated_sname = s.name.replace(".", "_")
|
||||
|
||||
if metric_type and curated_sname not in doc_done:
|
||||
data += "# TYPE %s %s\n" % (curated_sname, metric_type)
|
||||
doc_done.add(curated_sname)
|
||||
|
||||
# NOTE(sileht): prometheus pushgateway doesn't allow to push
|
||||
# timestamp_ms
|
||||
|
@ -67,10 +69,10 @@ class PrometheusPublisher(http.HttpPublisher):
|
|||
# datetime.utcfromtimestamp(0)
|
||||
# ).total_seconds() * 1000
|
||||
# data += '%s{resource_id="%s"} %s %d\n' % (
|
||||
# s.name, s.resource_id, s.volume, timestamp_ms)
|
||||
# curated_sname, s.resource_id, s.volume, timestamp_ms)
|
||||
|
||||
data += '%s{resource_id="%s"} %s\n' % (
|
||||
s.name, s.resource_id, s.volume)
|
||||
curated_sname, s.resource_id, s.volume)
|
||||
self._do_post(data)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -65,6 +65,17 @@ class TestPrometheusPublisher(base.BaseTestCase):
|
|||
timestamp=datetime.datetime.now().isoformat(),
|
||||
resource_metadata={'name': 'TestPublish'},
|
||||
),
|
||||
sample.Sample(
|
||||
name='delta.epsilon',
|
||||
type=sample.TYPE_GAUGE,
|
||||
unit='',
|
||||
volume=7,
|
||||
user_id='test',
|
||||
project_id='test',
|
||||
resource_id=resource_id,
|
||||
timestamp=datetime.datetime.now().isoformat(),
|
||||
resource_metadata={'name': 'TestPublish'},
|
||||
),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -88,7 +99,9 @@ alpha{resource_id="%s"} 1
|
|||
beta{resource_id="%s"} 3
|
||||
# TYPE gamma gauge
|
||||
gamma{resource_id="%s"} 5
|
||||
""" % (self.resource_id, self.resource_id, self.resource_id)
|
||||
# TYPE delta_epsilon gauge
|
||||
delta_epsilon{resource_id="%s"} 7
|
||||
""" % (self.resource_id, self.resource_id, self.resource_id, self.resource_id)
|
||||
|
||||
expected = [
|
||||
mock.call('http://localhost:90/metrics/job/os',
|
||||
|
@ -118,7 +131,9 @@ alpha{resource_id="%s"} 1
|
|||
beta{resource_id="%s"} 3
|
||||
# TYPE gamma gauge
|
||||
gamma{resource_id="%s"} 5
|
||||
""" % (self.resource_id, self.resource_id, self.resource_id)
|
||||
# TYPE delta_epsilon gauge
|
||||
delta_epsilon{resource_id="%s"} 7
|
||||
""" % (self.resource_id, self.resource_id, self.resource_id, self.resource_id)
|
||||
|
||||
expected = [
|
||||
mock.call('https://localhost:90/metrics/job/os',
|
||||
|
|
Loading…
Reference in New Issue