Skip to content

Commit

Permalink
fix: update conversion into OTLP StatisticSet type such that min/max …
Browse files Browse the repository at this point in the history
…are gauges and sum/count are monotonic counters
  • Loading branch information
tylerburdsall committed Mar 7, 2024
1 parent 862ec86 commit 8b27c0b
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ class OpentelemetryClient(
aggregationWidth: Duration,
dimensions: Iterable<KeyValue>,
): Sequence<Metric> = sequence {
yield(statisticSetDataPoint(metric, measurementName, "min", min, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPoint(metric, measurementName, "max", max, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPoint(metric, measurementName, "sum", sum, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPoint(metric, measurementName, "count", count, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPointGauge(metric, measurementName, "min", min, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPointGauge(metric, measurementName, "max", max, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPointCounter(metric, measurementName, "sum", sum, timestampNanos, aggregationWidth, dimensions))
yield(statisticSetDataPointCounter(metric, measurementName, "count", count, timestampNanos, aggregationWidth, dimensions))
}

private fun statisticSetDataPoint(
private fun statisticSetDataPointCounter(
metricName: String,
measurementName: String,
statisticSetComponent: String,
Expand All @@ -213,13 +213,30 @@ class OpentelemetryClient(
name = "${metricName}_${measurementName}_$statisticSetComponent"
unit = "1"
sum = sum {
isMonotonic = false
isMonotonic = true
// because cumulative is bullshit
aggregationTemporality = AggregationTemporality.AGGREGATION_TEMPORALITY_DELTA
dataPoints.add(newNumberDataPoint(value, timestampNanos, aggregationWidth, dimensions))
}
}

private fun statisticSetDataPointGauge(
metricName: String,
measurementName: String,
statisticSetComponent: String,
value: Number,
timestampNanos: Long,
aggregationWidth: Duration,
dimensions: Iterable<KeyValue>,
): Metric = metric {
name = "${metricName}_${measurementName}_$statisticSetComponent"
unit = "1"
gauge = gauge {
dataPoints.add(newNumberDataPoint(value, timestampNanos, aggregationWidth, dimensions))
}
}


private fun Metrics.asGoofyOtlpMetricSequence(): Sequence<Metric> {
val otlpDimensions = metricDimensions.values.map { it.asOtlpKeyValue() }
return sequence {
Expand Down

0 comments on commit 8b27c0b

Please sign in to comment.