Browse Source

Merge "Fix samples with dots in sample name" into stable/rocky

changes/12/700212/1
Zuul 2 months ago
parent
commit
d5a45b4297
2 changed files with 24 additions and 7 deletions
  1. +7
    -5
      ceilometer/publisher/prometheus.py
  2. +17
    -2
      ceilometer/tests/unit/publisher/test_prometheus.py

+ 7
- 5
ceilometer/publisher/prometheus.py View File

@@ -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

+ 17
- 2
ceilometer/tests/unit/publisher/test_prometheus.py View File

@@ -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…
Cancel
Save