Skip to content

Commit c1693bc

Browse files
t-loervcz
andauthored
Update backend/pkg/api/instances.go
Co-authored-by: Ervin Racz <39372002+ervcz@users.noreply.github.com>
1 parent be6cdb8 commit c1693bc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

backend/pkg/api/instances.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,14 @@ func (api *API) GetDefaultInterval() time.Duration {
649649
return defaultStatsInterval
650650
}
651651

652-
// instanceStatsQuery returns a SelectDataset prepared to return all active instances within a time period.
652+
// instanceStatsQuery returns a SelectDataset to estimate the active fleet size at a given point in time.
653+
// It answers "how many instances were part of the active fleet on day X",
654+
// not "how many instances specifically checked in on day X".
653655
//
654-
// This is somewhat complicated by the fact that an instance created _before_ or _during_ our window
655-
// can have checked in _after_ the window we're supposed to check. last_check_for_updates gets updated every
656-
// time an instance checks for an update. Hence we filter for instances that:
657-
// 1. have been created before timestamp 't'
658-
// 2. have checked in _during_ or _after_ the time period
656+
// Since last_check_for_updates gets overwritten on every check-in, we cannot determine
657+
// whether an instance was active on a specific past day. Instead, we count instances that:
658+
// 1. existed at the time (created_ts <= timestamp)
659+
// 2. are still alive (last_check_for_updates > timestamp - duration)
659660
func (api *API) instanceStatsQuery(t *time.Time, duration *time.Duration) *goqu.SelectDataset {
660661
if t == nil {
661662
now := time.Now().UTC()

0 commit comments

Comments
 (0)