Skip to content

Commit

Permalink
fix gnocchi stats logging
Browse files Browse the repository at this point in the history
don't bother with a running count to build stats

Change-Id: I6c40e49046115512d5858a6e1348629e10d6a42f

Conflicts:
	ceilometer/publisher/gnocchi.py
  • Loading branch information
chungg authored and dchavoll committed Aug 15, 2018
1 parent 7275dd5 commit c473be4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
19 changes: 7 additions & 12 deletions ceilometer/publisher/gnocchi.py
Expand Up @@ -299,20 +299,16 @@ def publish_samples(self, data):

gnocchi_data = {}
measures = {}
stats = dict(measures=0, resources=0, metrics=0)
for resource_id, samples_of_resource in resource_grouped_samples:
# NOTE(sileht): / is forbidden by Gnocchi
resource_id = resource_id.replace('/', '_')

stats['resources'] += 1
metric_grouped_samples = itertools.groupby(
list(samples_of_resource),
key=operator.attrgetter('name'))

res_info = {}
for metric_name, samples in metric_grouped_samples:
stats['metrics'] += 1

samples = list(samples)
rd = self.metric_map.get(metric_name)
if rd is None:
Expand Down Expand Up @@ -343,15 +339,13 @@ def publish_samples(self, data):
metric = sample.name
res_info['resource']['metrics'][metric]['unit'] = unit

stats['measures'] += len(measures[resource_id][metric_name])
res_info["resource"].update(res_info["resource_extra"])
if res_info:
gnocchi_data[resource_id] = res_info

try:
self.batch_measures(measures, gnocchi_data, stats)
except (gnocchi_exc.ClientException,
ka_exceptions.ConnectFailure) as e:
self.batch_measures(measures, gnocchi_data)
except gnocchi_exc.ClientException as e:
LOG.error(six.text_type(e))
except Exception as e:
LOG.error(six.text_type(e), exc_info=True)
Expand All @@ -378,7 +372,7 @@ def _extract_resources_from_error(e, resource_infos):
resource_infos[rid]['resource'])
for rid in resource_ids]

def batch_measures(self, measures, resource_infos, stats):
def batch_measures(self, measures, resource_infos):
# NOTE(sileht): We don't care about error here, we want
# resources metadata always been updated
try:
Expand Down Expand Up @@ -411,9 +405,10 @@ def batch_measures(self, measures, resource_infos, stats):
self._gnocchi.metric.batch_resources_metrics_measures(
measures, create_metrics=True)

# FIXME(sileht): take care of measures removed in stats
LOG.debug("%(measures)d measures posted against %(metrics)d "
"metrics through %(resources)d resources", stats)
LOG.debug(
"%d measures posted against %d metrics through %d resources",
sum(len(m) for rid in measures for m in measures[rid].values()),
sum(len(m) for m in measures.values()), len(resource_infos))

def _create_resource(self, resource_type, resource):
self._gnocchi.resource.create(resource_type, resource)
Expand Down
18 changes: 9 additions & 9 deletions ceilometer/tests/unit/publisher/test_gnocchi.py
Expand Up @@ -414,16 +414,18 @@ def test_broken_config_load(self, mylog):
self.assertEqual(0, len(d.resources_definition))

@mock.patch('ceilometer.publisher.gnocchi.GnocchiPublisher'
'._if_not_cached')
'._if_not_cached', mock.Mock())
@mock.patch('ceilometer.publisher.gnocchi.GnocchiPublisher'
'.batch_measures')
def _do_test_activity_filter(self, expected_measures, fake_batch, __):
def _do_test_activity_filter(self, expected_measures, fake_batch):
url = netutils.urlsplit("gnocchi://")
d = gnocchi.GnocchiPublisher(self.conf.conf, url)
d.publish_samples(self.samples)
fake_batch.assert_called_with(
mock.ANY, mock.ANY,
{'metrics': 1, 'resources': 1, 'measures': expected_measures})
self.assertEqual(1, len(fake_batch.mock_calls))
measures = fake_batch.mock_calls[0][1][0]
self.assertEqual(
expected_measures,
sum(len(m) for rid in measures for m in measures[rid].values()))

def test_activity_filter_match_project_id(self):
self.samples[0].project_id = (
Expand Down Expand Up @@ -742,10 +744,8 @@ def test_workflow(self, fakeclient_cls, logger):
if measures_posted:
batch_side_effect += [None]
expected_debug.append(
mock.call("%(measures)d measures posted against %(metrics)d "
"metrics through %(resources)d resources", dict(
measures=len(self.measures_attributes),
metrics=1, resources=1))
mock.call("%d measures posted against %d metrics through %d "
"resources", len(self.measures_attributes), 1, 1)
)

if self.patchable_attributes:
Expand Down

0 comments on commit c473be4

Please sign in to comment.