Skip to content

Commit

Permalink
Fix chaining labels in metrics (#38)
Browse files Browse the repository at this point in the history
JIRA: RHELWF-6624
  • Loading branch information
hluk committed May 19, 2022
1 parent 29bd1ea commit 41440a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion greenwave/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def inc(self):
client.incr(str(self))

def labels(self, **labeldict):
return Counter(self.name, labeldict=labeldict)
new_labeldict = dict(self.labeldict)
new_labeldict.update(labeldict)
return Counter(self.name, labeldict=new_labeldict)

def count_exceptions(self):
"""Returns function decorator to increase counter on exception."""
Expand Down
3 changes: 3 additions & 0 deletions greenwave/tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def test_counter_to_str_with_labels():
counter = Counter('total_decisions').labels(handler='test')
assert str(counter) == 'total_decisions[handler=test]'

counter2 = counter.labels(decision_context='context')
assert str(counter2) == 'total_decisions[handler=test,decision_context=context]'


def test_counter_no_host_set(monkeypatch):
with patch('greenwave.monitor.StatsClient') as client:
Expand Down

0 comments on commit 41440a0

Please sign in to comment.