Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Aggmetrics: track how long a GC() run takes and how many series deleted #1746

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mdata/aggmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func NewAggMetrics(store Store, cachePusher cache.CachePusher, dropFirstChunk bo
// periodically scan chunks and close any that have not received data in a while
func (ms *AggMetrics) GC() {
for {
var purged int

unix := time.Duration(time.Now().UnixNano())
diff := ms.gcInterval - (unix % ms.gcInterval)
time.Sleep(diff + time.Minute)
log.Info("checking for stale chunks that need persisting.")
now := uint32(time.Now().Unix())
log.Info("Aggmetrics: checking for stale chunks that need persisting.")
nowTime := time.Now()
now := uint32(nowTime.Unix())
chunkMinTs := now - uint32(ms.chunkMaxStale)
metricMinTs := now - uint32(ms.metricMaxStale)

Expand Down Expand Up @@ -84,6 +87,7 @@ func (ms *AggMetrics) GC() {
if stale {
log.Debugf("metric %s is stale. Purging data from memory.", key)
ms.Lock()
purged++
delete(ms.Metrics[org], key)
orgActiveMetrics.Set(float64(len(ms.Metrics[org])))
// note: this is racey. if a metric has just become unstale, it may have created a new chunk,
Expand Down Expand Up @@ -118,6 +122,8 @@ func (ms *AggMetrics) GC() {
}
ms.RUnlock()
metricsActive.Set(totalActive)

log.Infof("Aggmetrics: finished GC %s. number of purged (deleted) metrics from tank: %d", time.Since(nowTime), purged)
}
}

Expand Down