Skip to content

Commit f413959

Browse files
committed
fix: ensure collection timestamps are in UTC for immediate and periodic scrapes
1 parent eb474f6 commit f413959

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cmd/start.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func runAgent(cmd *cobra.Command, args []string) error {
126126
logger.String("prometheus_endpoint", cfg.Prometheus.Endpoint),
127127
logger.String("server_endpoint", cfg.Server.Endpoint))
128128

129-
// Scrape immediately on start with aligned timestamp
130-
collectionTime := time.Now().Truncate(cfg.Agent.Interval)
129+
// Scrape immediately on start with aligned timestamp (UTC)
130+
collectionTime := time.Now().UTC().Truncate(cfg.Agent.Interval)
131131
if err := scrapeAndSendWithTimestamp(scraper, sender, cfg.Agent.ServerID, collectionTime); err != nil {
132132
logger.Error("Initial scrape failed", logger.Err(err))
133133
}
@@ -138,8 +138,8 @@ func runAgent(cmd *cobra.Command, args []string) error {
138138
case <-ctx.Done():
139139
return nil
140140
case tickTime := <-ticker.C:
141-
// Align collection time to interval boundary
142-
collectionTime := tickTime.Truncate(cfg.Agent.Interval)
141+
// Align collection time to interval boundary (UTC)
142+
collectionTime := tickTime.UTC().Truncate(cfg.Agent.Interval)
143143
if err := scrapeAndSendWithTimestamp(scraper, sender, cfg.Agent.ServerID, collectionTime); err != nil {
144144
logger.Error("Scrape failed", logger.Err(err))
145145
}

0 commit comments

Comments
 (0)