001package io.prometheus.metrics.exporter.opentelemetry.otelmodel;
002
003import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
004import io.opentelemetry.sdk.metrics.data.DoublePointData;
005import io.opentelemetry.sdk.metrics.data.MetricDataType;
006import io.opentelemetry.sdk.metrics.data.SumData;
007import io.prometheus.metrics.model.snapshots.InfoSnapshot;
008import java.util.Collection;
009import java.util.Collections;
010import java.util.List;
011import java.util.stream.Collectors;
012
013@SuppressWarnings("this-escape")
014public class PrometheusInfo extends PrometheusData<DoublePointData>
015    implements SumData<DoublePointData> {
016
017  private final List<DoublePointData> points;
018
019  public PrometheusInfo(InfoSnapshot snapshot, long currentTimeMillis) {
020    super(MetricDataType.DOUBLE_SUM);
021    this.points =
022        snapshot.getDataPoints().stream()
023            .map(dataPoint -> toOtelDataPoint(dataPoint, currentTimeMillis))
024            .collect(Collectors.toList());
025  }
026
027  @Override
028  public boolean isMonotonic() {
029    return false;
030  }
031
032  @Override
033  public AggregationTemporality getAggregationTemporality() {
034    return AggregationTemporality.CUMULATIVE;
035  }
036
037  @Override
038  public Collection<DoublePointData> getPoints() {
039    return points;
040  }
041
042  private DoublePointData toOtelDataPoint(
043      InfoSnapshot.InfoDataPointSnapshot dataPoint, long currentTimeMillis) {
044    return new DoublePointDataImpl(
045        1.0,
046        getStartEpochNanos(dataPoint),
047        getEpochNanos(dataPoint, currentTimeMillis),
048        labelsToAttributes(dataPoint.getLabels()),
049        Collections.emptyList());
050  }
051}