From 75d9c4428f9479fd0373ce98ee9bf28319aecf77 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Wed, 9 Aug 2023 14:59:18 -0600 Subject: [PATCH 1/3] fix(outputs.stackdriver): regenerate time interval for unkown metrics fixes: #13725 --- plugins/outputs/stackdriver/stackdriver.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index aee56ccb30274..dbbd6c78ac21e 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", @@ -358,7 +370,10 @@ func getStackdriverIntervalEndpoints( f *telegraf.Field, cc *counterCache, ) (*timestamppb.Timestamp, *timestamppb.Timestamp) { + fmt.Println(kind) + fmt.Printf("metric timestamp: %s\n", m.Time()) endTime := timestamppb.New(m.Time()) + fmt.Printf("generated end time: %s\n", endTime.String()) var startTime *timestamppb.Timestamp if kind == metricpb.MetricDescriptor_CUMULATIVE { // Interval starts for stackdriver CUMULATIVE metrics must reset any time @@ -366,6 +381,10 @@ func getStackdriverIntervalEndpoints( // observed values for each counter in the batch. startTime = cc.GetStartTime(GetCounterCacheKey(m, f), value, endTime) } + + fmt.Printf("startTime: %s\n", startTime.String()) + fmt.Printf("endTime: %s\n", endTime.String()) + fmt.Println() return startTime, endTime } From 6e83451a7555d91fb8c844ded4711395984b7495 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Wed, 9 Aug 2023 15:00:51 -0600 Subject: [PATCH 2/3] remove debug code --- plugins/outputs/stackdriver/stackdriver.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index dbbd6c78ac21e..f630f458faa0d 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -370,10 +370,7 @@ func getStackdriverIntervalEndpoints( f *telegraf.Field, cc *counterCache, ) (*timestamppb.Timestamp, *timestamppb.Timestamp) { - fmt.Println(kind) - fmt.Printf("metric timestamp: %s\n", m.Time()) endTime := timestamppb.New(m.Time()) - fmt.Printf("generated end time: %s\n", endTime.String()) var startTime *timestamppb.Timestamp if kind == metricpb.MetricDescriptor_CUMULATIVE { // Interval starts for stackdriver CUMULATIVE metrics must reset any time @@ -381,10 +378,6 @@ func getStackdriverIntervalEndpoints( // observed values for each counter in the batch. startTime = cc.GetStartTime(GetCounterCacheKey(m, f), value, endTime) } - - fmt.Printf("startTime: %s\n", startTime.String()) - fmt.Printf("endTime: %s\n", endTime.String()) - fmt.Println() return startTime, endTime } From 7434d2ce3717b4379fca25cb233e4b483e040e6d Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Thu, 10 Aug 2023 09:11:15 -0600 Subject: [PATCH 3/3] remove debug statement --- plugins/outputs/stackdriver/counter_cache.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/outputs/stackdriver/counter_cache.go b/plugins/outputs/stackdriver/counter_cache.go index d59fc39a4641a..d350bba8ebd63 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) }