Skip to content

Commit

Permalink
fix: handle delayed resets by forcefully recording 0s for unreceived …
Browse files Browse the repository at this point in the history
…events (#144)
  • Loading branch information
Elfo404 authored Sep 23, 2024
1 parent ff3ad58 commit 0d34954
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions receiver/githubactionsreceiver/metric_event_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ func (m *metricsHandler) eventToMetrics(event *github.WorkflowJobEvent, config *
labels = "no labels"
}

now := pcommon.NewTimestampFromTime(time.Now())

if status, ok := metadata.MapAttributeCiGithubWorkflowJobStatus[event.GetAction()]; ok {
curVal, _ := loadFromCache(repo, labels, status)
storeInCache(repo, labels, status, curVal+1)
curVal, found := loadFromCache(repo, labels, status)

// If the value was not found in the cache, we record a 0 value for all other possible statuses
// so that counter resets are properly handled.
if !found {
for _, s := range metadata.MapAttributeCiGithubWorkflowJobStatus {
if s == status {
continue
}

m.mb.RecordWorkflowJobsTotalDataPoint(pcommon.NewTimestampFromTime(time.Now()), curVal+1, repo, labels, status)
storeInCache(repo, labels, s, 0)
m.mb.RecordWorkflowJobsTotalDataPoint(now, 0, repo, labels, s)
}
}

storeInCache(repo, labels, status, curVal+1)
m.mb.RecordWorkflowJobsTotalDataPoint(now, curVal+1, repo, labels, status)
}

return m.mb.Emit()
Expand Down

0 comments on commit 0d34954

Please sign in to comment.