func addUntypedMetrics()

in exporter/collector/googlemanagedprometheus/extra_metrics.go [78:132]


func addUntypedMetrics(m pmetric.Metrics) {
	rms := m.ResourceMetrics()
	for i := 0; i < rms.Len(); i++ {
		rm := rms.At(i)
		sms := rm.ScopeMetrics()
		for j := 0; j < sms.Len(); j++ {
			sm := sms.At(j)
			mes := sm.Metrics()

			// only iterate up to the current length. new untyped sum metrics
			// will be added to this slice inline.
			mLen := mes.Len()
			for k := 0; k < mLen; k++ {
				metric := mes.At(k)

				// only applies to gauges
				if metric.Type() != pmetric.MetricTypeGauge {
					continue
				}

				if !isUnknown(metric) {
					continue
				}

				// attribute is set on the data point
				gauge := metric.Gauge()
				points := gauge.DataPoints()
				for l := 0; l < points.Len(); l++ {
					// Add the new Sum metric and copy values over from this Gauge
					point := points.At(l)
					newMetric := mes.AppendEmpty()
					newMetric.SetName(metric.Name())
					newMetric.SetDescription(metric.Description())
					newMetric.SetUnit(metric.Unit())
					newMetric.Metadata().PutStr(prometheusMetricMetadataTypeKey, string(model.MetricTypeUnknown))

					newSum := newMetric.SetEmptySum()
					newSum.SetIsMonotonic(true)
					newSum.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)

					newDataPoint := newSum.DataPoints().AppendEmpty()
					point.Attributes().CopyTo(newDataPoint.Attributes())
					if point.ValueType() == pmetric.NumberDataPointValueTypeInt {
						newDataPoint.SetIntValue(point.IntValue())
					} else if point.ValueType() == pmetric.NumberDataPointValueTypeDouble {
						newDataPoint.SetDoubleValue(point.DoubleValue())
					}
					newDataPoint.SetFlags(point.Flags())
					newDataPoint.SetTimestamp(point.Timestamp())
					newDataPoint.SetStartTimestamp(point.StartTimestamp())
				}
			}
		}
	}
}