fix(outputs.stackdriver): Regenerate time interval for unkown metrics (#13745)

This commit is contained in:
Joshua Powers 2023-08-11 03:14:13 -06:00 committed by GitHub
parent 61cf18c821
commit 1381513e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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)
}

View File

@ -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",