Skip to content

Commit

Permalink
fix: replace counter with gauge cron tracker alert (#5084)
Browse files Browse the repository at this point in the history
  • Loading branch information
snarkychef authored Sep 16, 2024
1 parent 7d74183 commit dc7d6ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions warehouse/router/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ 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)
execTime := time.Now()
cronTrackerExecTimestamp.Gauge(execTime.Unix())

r.configSubscriberLock.RLock()
warehouses := append([]model.Warehouse{}, r.warehouses...)
Expand All @@ -51,11 +52,12 @@ func (r *Router) CronTracker(ctx context.Context) error {
}
}

nextExecTime := execTime.Add(r.config.uploadStatusTrackFrequency)
select {
case <-ctx.Done():
r.logger.Infon("context is cancelled, stopped running tracking")
return nil
case <-time.After(r.config.uploadStatusTrackFrequency):
case <-time.After(time.Until(nextExecTime)):
}
}
}
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 dc7d6ef

Please sign in to comment.