Skip to content

Commit

Permalink
address some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Aug 22, 2023
1 parent 53934e3 commit faf544f
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import io.opentelemetry.sdk.metrics.internal.data._
import io.opentelemetry.sdk.resources.Resource
import kamon.metric.Instrument.Snapshot
import kamon.metric.{Distribution, MeasurementUnit, MetricSnapshot, PeriodSnapshot}
import kamon.tag.Lookups
import kamon.trace.Span.TagKeys

import java.lang.{Double => JDouble, Long => JLong}
import java.time.Instant
Expand All @@ -34,16 +32,14 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
private val fromNs = from.toEpochMilli * 1000000
private val toNs = to.toEpochMilli * 1000000

private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo = {
// logic for looking up the component doesn't really seem to make sense - to be compliant we should probably be grouping the metrics by component before calling this
InstrumentationScopeInfo.create(snapshot.instruments.headOption.flatMap(_.tags.get(Lookups.option(TagKeys.Component))) getOrElse "kamon-instrumentation", kamonVersion, null)
}
private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo =
InstrumentationScopeInfo.create("kamon-metrics", kamonVersion, null)

private def toString(unit: MeasurementUnit): String = unit.magnitude.name

def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)
private def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)

def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava)
private def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava)

def convertGauge(gauge: MetricSnapshot.Values[Double]): MetricData =
ImmutableMetricData.createDoubleGauge(
Expand All @@ -54,7 +50,7 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
toString(gauge.settings.unit),
toGaugeData(gauge.instruments))

def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = {
private def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = {
val boundaries = ArrayBuffer.newBuilder[JDouble]
val counts = ArrayBuffer.newBuilder[JLong]
for (el <- s.value.bucketsIterator) {
Expand All @@ -73,10 +69,10 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
)
}

def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] =
private def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] =
distributions.filter(_.value.buckets.nonEmpty) match {
case Nil => None
case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.CUMULATIVE, nonEmpty.map(toHistogramDatum).asJava))
case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.DELTA, nonEmpty.map(toHistogramDatum).asJava))
}

def convertHistogram(histogram: MetricSnapshot.Distributions): Option[MetricData] =
Expand All @@ -89,11 +85,11 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
toString(histogram.settings.unit),
d))

def toCounterDatum(g: Snapshot[Long]): LongPointData =
private def toCounterDatum(g: Snapshot[Long]): LongPointData =
ImmutableLongPointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)

def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] =
ImmutableSumData.create(false, AggregationTemporality.CUMULATIVE, g.map(toCounterDatum).asJava)
private def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] =
ImmutableSumData.create(false, AggregationTemporality.DELTA, g.map(toCounterDatum).asJava)

def convertCounter(counter: MetricSnapshot.Values[Long]): MetricData =
ImmutableMetricData.createLongSum(
Expand Down

0 comments on commit faf544f

Please sign in to comment.