Skip to content

Commit e0760b5

Browse files
fix(spanner): set gauge metric start time to match end time (#14289)
This commit fixes an InvalidArgument error ("One or more points were written more frequently than the maximum sampling period") when exporting gauge metrics like `open_connections` to Cloud Monitoring. Previously, the time interval for these gauge metrics started from the moment the application booted up. This created long, continuously overlapping time intervals. Cloud Monitoring strictly rejected these because it requires gauges to be exact, point-in-time measurements, not long durations. By simply setting the start time equal to the end time (`start = end`), we correctly format the data as instantaneous point-in-time snapshots. This satisfies Cloud Monitoring's requirements and allows the metrics to export successfully on every cycle.
1 parent 71df27f commit e0760b5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

spanner/metrics_monitoring_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func toNonemptyTimeIntervalpb(start, end time.Time, isGauge bool) (*monitoringpb
359359
// previous interval, for all non-gauge types.
360360
// https://cloud.google.com/monitoring/api/ref_v3/rpc/google.monitoring.v3#timeinterval
361361
if isGauge {
362-
end = start
362+
start = end
363363
} else if end.Sub(start).Milliseconds() <= 1 {
364364
end = start.Add(time.Millisecond)
365365
}

0 commit comments

Comments
 (0)