From 1381513e61c765911f1f0e488410c0b01560c228 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Fri, 11 Aug 2023 03:14:13 -0600 Subject: [PATCH] fix(outputs.stackdriver): Regenerate time interval for unkown metrics (#13745) --- plugins/outputs/stackdriver/counter_cache.go | 1 - plugins/outputs/stackdriver/stackdriver.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/stackdriver/counter_cache.go b/plugins/outputs/stackdriver/counter_cache.go index d59fc39a4..d350bba8e 100644 --- a/plugins/outputs/stackdriver/counter_cache.go +++ b/plugins/outputs/stackdriver/counter_cache.go @@ -62,7 +62,6 @@ func (cc *counterCache) GetStartTime(key string, value *monpb.TypedValue, endTim // ...but... // start times cannot be over 25 hours old; reset after 1 day to be safe age := endTime.GetSeconds() - lastObserved.StartTime.GetSeconds() - cc.log.Debugf("age: %d", age) if age > 86400 { lastObserved.Reset(endTime) } diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index aee56ccb3..f630f458f 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -257,6 +257,18 @@ func (s *Stackdriver) sendBatch(batch []telegraf.Metric) error { // do some heuristics to know which one to use for queries. This // only occurs when using the official name format. if s.MetricNameFormat == "official" && strings.HasSuffix(timeSeries.Metric.Type, "unknown") { + metricKind := metricpb.MetricDescriptor_CUMULATIVE + startTime, endTime := getStackdriverIntervalEndpoints(metricKind, value, m, f, s.counterCache) + timeInterval, err := getStackdriverTimeInterval(metricKind, startTime, endTime) + if err != nil { + s.Log.Errorf("Get time interval failed: %s", err) + continue + } + dataPoint := &monitoringpb.Point{ + Interval: timeInterval, + Value: value, + } + counterTimeSeries := &monitoringpb.TimeSeries{ Metric: &metricpb.Metric{ Type: s.generateMetricName(m, f.Key) + ":counter",