Skip to content

Commit

Permalink
Add timestamp in nanoseconds for influxdb output
Browse files Browse the repository at this point in the history
For the "Closed yesterday" query we can tell telegraf the exact timestamp
for the data.
This way we can execute the telegraf query more often per day to ensure
we get data, and also for the other queries there's no need to run this
only once a day.

Ticket: https://progress.opensuse.org/issues/121582#note-57
  • Loading branch information
perlpunk committed Mar 24, 2023
1 parent e98b189 commit 06b267d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def cycle_time(issue, status_ids):
return cycle_time


def _today_nanoseconds():
dt = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
epoch = datetime.utcfromtimestamp(0)
return int((dt-epoch).total_seconds()*1000000000)


def render_influxdb(data):
output = []

Expand Down Expand Up @@ -192,6 +198,8 @@ def render_influxdb(data):
extra=extra,
)
)
if status == "Resolved":
output[-1] += " " + str(_today_nanoseconds())
return output

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def test_influxdb(self):
},
]
)
backlogger._today_nanoseconds = MagicMock(side_effect=[23])
self.assertEqual(
backlogger.render_influxdb(backlogger.data),
[
'slo,team="Awesome\\ Team",status="In\\ Progress",title="Workable\\ Backlog" count=2',
'leadTime,team="Awesome\\ Team",status="Resolved",title="Workable\\ Backlog" count=2,leadTime=275.6273611111111,cycleTime=48.0,leadTimeSum=551.2547222222222,cycleTimeSum=96.0',
'leadTime,team="Awesome\\ Team",status="Resolved",title="Workable\\ Backlog" count=2,leadTime=275.6273611111111,cycleTime=48.0,leadTimeSum=551.2547222222222,cycleTimeSum=96.0 23',
],
)

Expand Down

0 comments on commit 06b267d

Please sign in to comment.