Skip to content

Commit

Permalink
last fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Sep 11, 2024
1 parent f9b2e33 commit 99c2721
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/cockpit/channels/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def convert_metric_description(self, context: 'pmapi.pmContext', metric: JsonObj
pm_units = pm_desc.units
if units:
try:
[pm_units, factor] = context.pmParseUnitsStr(units)
[parsed_units, factor] = context.pmParseUnitsStr(units)
except pmapi.pmErr as exc:
if exc.errno() == c_api.PM_ERR_NAME:
raise ChannelError('not-found', message=f'no such metric: {name}') from None
Expand All @@ -293,8 +293,8 @@ def convert_metric_description(self, context: 'pmapi.pmContext', metric: JsonObj

self.try_convert_unit(context, pm_desc, pm_units)

if units != pm_units or factor != 1.0:
units = pm_units
if units != parsed_units or factor != 1.0:
pm_units = parsed_units

return MetricInfo(pmid=pm_ids[0],
name=name,
Expand Down Expand Up @@ -373,8 +373,7 @@ def send_meta(self, results: 'pmapi.pmResult', context: 'pmapi.pmContext') -> No
instance_desc = context.pmNameInDom(metric_desc.desc, value.inst)
insts.append(instance_desc)

if len(insts) > 0:
desc['instances'] = insts
desc['instances'] = insts

metrics.append(desc)

Expand Down Expand Up @@ -441,9 +440,10 @@ def sample(self, context: 'pmapi.pmContext', archive_batch: int, limit: int, tot
self.send_meta(results, context)
else:
if self.needs_meta_update(results):
# Flush all metrics and send new meta
self.send_updates(fetched)
fetched.clear()
# Flush all metrics and send new meta, but only if there is data
if fetched:
self.send_updates(fetched)
fetched.clear()
self.send_meta(results, context)

fetched.append(self.parse_fetched_results(context, results))
Expand Down
3 changes: 1 addition & 2 deletions test/pytest/test_pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ async def test_pcp_disk_metrics(transport, disk_metrics_archive):
assert len(metrics) == 9
network_metric = metrics[8]
assert network_metric['name'] == 'network.interface.total.bytes'
assert 'instances' not in network_metric

_, data = await transport.next_frame()
data = json.loads(data)
Expand All @@ -586,7 +585,7 @@ async def test_pcp_disk_metrics(transport, disk_metrics_archive):
meta = json.loads(data)
network_metric = metrics[8]
assert network_metric['name'] == 'network.interface.total.bytes'
assert 'instances' not in network_metric
assert network_metric['instances'] == []

# Another meta
assert_metrics_meta(meta, str(disk_metrics_archive), 1597663540413, 1000)
Expand Down

0 comments on commit 99c2721

Please sign in to comment.