6767 metricLabelKeyGRPCLBPickResult : true ,
6868 metricLabelKeyGRPCLBDataPlaneTarget : true ,
6969 metricLabelKeyGRPCXDSResourceType : true ,
70+ metricLabelKeyGRPCLBLocality : true ,
71+ metricLabelKeyGRPCLBBackendService : true ,
72+ metricLabelKeyGRPCDisconnectError : true ,
7073 metricLabelKeyClientUID : true ,
7174 metricLabelKeyClientName : true ,
7275 metricLabelKeyDatabase : true ,
@@ -290,7 +293,10 @@ func (me *monitoringExporter) recordToTimeSeriesPb(m otelmetricdata.Metrics) ([]
290293 metric , mr := me .recordToMetricAndMonitoredResourcePbs (m , point .Attributes )
291294 var ts * monitoringpb.TimeSeries
292295 var err error
293- ts , err = sumToTimeSeries [int64 ](point , m , mr )
296+ // Int64UpDownCounter contains Sum data with IsMonotonic = false.
297+ // See https://tinyurl.com/yzks9ene.
298+ isGauge := ! a .IsMonotonic
299+ ts , err = sumToTimeSeries [int64 ](point , m , mr , isGauge )
294300 if err != nil {
295301 errs = append (errs , err )
296302 continue
@@ -304,16 +310,20 @@ func (me *monitoringExporter) recordToTimeSeriesPb(m otelmetricdata.Metrics) ([]
304310 return tss , errors .Join (errs ... )
305311}
306312
307- func sumToTimeSeries [N int64 | float64 ](point otelmetricdata.DataPoint [N ], metrics otelmetricdata.Metrics , mr * monitoredrespb.MonitoredResource ) (* monitoringpb.TimeSeries , error ) {
308- interval , err := toNonemptyTimeIntervalpb (point .StartTime , point .Time )
313+ func sumToTimeSeries [N int64 | float64 ](point otelmetricdata.DataPoint [N ], metrics otelmetricdata.Metrics , mr * monitoredrespb.MonitoredResource , isGauge bool ) (* monitoringpb.TimeSeries , error ) {
314+ interval , err := toNonemptyTimeIntervalpb (point .StartTime , point .Time , isGauge )
309315 if err != nil {
310316 return nil , err
311317 }
312318 value , valueType := numberDataPointToValue [N ](point )
319+ metricKind := googlemetricpb .MetricDescriptor_CUMULATIVE
320+ if isGauge {
321+ metricKind = googlemetricpb .MetricDescriptor_GAUGE
322+ }
313323 return & monitoringpb.TimeSeries {
314324 Resource : mr ,
315325 Unit : string (metrics .Unit ),
316- MetricKind : googlemetricpb . MetricDescriptor_CUMULATIVE ,
326+ MetricKind : metricKind ,
317327 ValueType : valueType ,
318328 Points : []* monitoringpb.Point {{
319329 Interval : interval ,
@@ -323,7 +333,7 @@ func sumToTimeSeries[N int64 | float64](point otelmetricdata.DataPoint[N], metri
323333}
324334
325335func histogramToTimeSeries [N int64 | float64 ](point otelmetricdata.HistogramDataPoint [N ], metrics otelmetricdata.Metrics , mr * monitoredrespb.MonitoredResource ) (* monitoringpb.TimeSeries , error ) {
326- interval , err := toNonemptyTimeIntervalpb (point .StartTime , point .Time )
336+ interval , err := toNonemptyTimeIntervalpb (point .StartTime , point .Time , false )
327337 if err != nil {
328338 return nil , err
329339 }
@@ -344,11 +354,13 @@ func histogramToTimeSeries[N int64 | float64](point otelmetricdata.HistogramData
344354 }, nil
345355}
346356
347- func toNonemptyTimeIntervalpb (start , end time.Time ) (* monitoringpb.TimeInterval , error ) {
357+ func toNonemptyTimeIntervalpb (start , end time.Time , isGauge bool ) (* monitoringpb.TimeInterval , error ) {
348358 // The end time of a new interval must be at least a millisecond after the end time of the
349359 // previous interval, for all non-gauge types.
350360 // https://cloud.google.com/monitoring/api/ref_v3/rpc/google.monitoring.v3#timeinterval
351- if end .Sub (start ).Milliseconds () <= 1 {
361+ if isGauge {
362+ end = start
363+ } else if end .Sub (start ).Milliseconds () <= 1 {
352364 end = start .Add (time .Millisecond )
353365 }
354366 startpb := timestamppb .New (start )
0 commit comments