Skip to content

Commit

Permalink
Fix InfluxDB output mode and add CI for it
Browse files Browse the repository at this point in the history
- Escape spaces in tags using backslashes
- Add a simple Telegraf config that reproduces syntax errors

See: https://progress.opensuse.org/issues/121582
  • Loading branch information
kalikiana committed Mar 10, 2023
1 parent 03e81c6 commit 7e0cb74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- run: pytest -vv
- name: Install Telegraf
run: sudo apt-get install -y telegraf
- name: Test InfluxDB output
run: telegraf --test --config tests/slo.conf
8 changes: 4 additions & 4 deletions backlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def render_influxdb(data):
count = len(result[status]["leadTime"])
if status == "Resolved":
measure = "leadTime"
extra = " leadTime={leadTime} cycleTime={cycleTime}".format(
extra = ",leadTime={leadTime},cycleTime={cycleTime}".format(
leadTime=mean(result[status]["leadTime"]),
cycleTime=mean(result[status]["cycleTime"]),
)
Expand All @@ -187,9 +187,9 @@ def render_influxdb(data):
output.append(
'{measure},team="{team}",status="{status}",title="{title}" count={count}{extra}'.format(
measure=measure,
team=data["team"],
status=status,
title=conf["title"],
team="\\ ".join(data["team"].split(" ")),
status="\\ ".join(status.split(" ")),
title="\\ ".join(conf["title"].split(" ")),
count=count,
extra=extra,
)
Expand Down
5 changes: 5 additions & 0 deletions tests/slo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[inputs.exec]]
commands = [ "env REDMINE_API_KEY=abcdefgah0123456789 ./backlogger.py --output=influxdb" ]
interval = "1h"
timeout = "10s"
data_format = "influx"
4 changes: 2 additions & 2 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_influxdb(self):
self.assertEqual(
backlogger.render_influxdb(data),
[
'slo,team="Awesome Team",status="In Progress",title="Workable Backlog" count=2',
'leadTime,team="Awesome Team",status="Resolved",title="Workable Backlog" count=1 leadTime=383.2547222222222 cycleTime=48.0',
'slo,team="Awesome\\ Team",status="In\\ Progress",title="Workable\\ Backlog" count=2',
'leadTime,team="Awesome\\ Team",status="Resolved",title="Workable\\ Backlog" count=1,leadTime=383.2547222222222,cycleTime=48.0',
],
)

0 comments on commit 7e0cb74

Please sign in to comment.