Skip to content

Commit

Permalink
fix: Replace counter with gauge cron tracker alert
Browse files Browse the repository at this point in the history
counter resetting on restarts was causing false alerts
  • Loading branch information
snarkychef committed Sep 11, 2024
1 parent f6271a0 commit 8fb3325
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions warehouse/router/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
// CronTracker Track the status of the staging file whether it has reached the terminal state or not for every warehouse
// we pick the staging file which is oldest within the range NOW() - 2 * syncFrequency and NOW() - 3 * syncFrequency
func (r *Router) CronTracker(ctx context.Context) error {
tick := r.statsFactory.NewTaggedStat("warehouse_cron_tracker_tick", stats.CountType, stats.Tags{
cronTrackerExecTimestamp := r.statsFactory.NewTaggedStat("warehouse_cron_tracker_timestamp_seconds", stats.GaugeType, stats.Tags{
"module": moduleName,
"destType": r.destType,
})
for {

tick.Count(1)
cronTrackerExecTimestamp.Gauge(time.Now().Unix())

r.configSubscriberLock.RLock()
warehouses := append([]model.Warehouse{}, r.warehouses...)
Expand Down
7 changes: 4 additions & 3 deletions warehouse/router/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,17 @@ func TestRouter_CronTracker(t *testing.T) {

mockLogger.EXPECT().Infon("context is cancelled, stopped running tracking").Times(1)

executionTime := time.Now().Unix()
err = r.CronTracker(ctx)
require.NoError(t, err)

m := statsStore.GetByName("warehouse_cron_tracker_tick")
m := statsStore.GetByName("warehouse_cron_tracker_timestamp_seconds")
require.Equal(t, len(m), 1)
require.Equal(t, m[0].Name, "warehouse_cron_tracker_tick")
require.Equal(t, m[0].Name, "warehouse_cron_tracker_timestamp_seconds")
require.Equal(t, m[0].Tags, stats.Tags{
"module": moduleName,
"destType": warehouseutils.POSTGRES,
})
require.GreaterOrEqual(t, m[0].Value, 1.0)
require.GreaterOrEqual(t, m[0].Value, float64(executionTime))
})
}

0 comments on commit 8fb3325

Please sign in to comment.