-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from iRevive/sdk-metrics/aggregation-temporality
sdk-metrics: add `AggregationTemporality`
- Loading branch information
Showing
4 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...metrics/src/main/scala/org/typelevel/otel4s/sdk/metrics/data/AggregationTemporality.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.metrics.data | ||
|
||
import cats.Hash | ||
import cats.Show | ||
|
||
/** The time period over which the measurements are aggregated. | ||
* | ||
* @see | ||
* [[https://opentelemetry.io/docs/specs/otel/metrics/data-model/#temporality]] | ||
*/ | ||
sealed trait AggregationTemporality | ||
|
||
object AggregationTemporality { | ||
|
||
/** Measurements are aggregated since the previous collection. | ||
*/ | ||
case object Delta extends AggregationTemporality | ||
|
||
/** Measurements are aggregated over the lifetime of the instrument. | ||
*/ | ||
case object Cumulative extends AggregationTemporality | ||
|
||
implicit val aggregationTemporalityHash: Hash[AggregationTemporality] = | ||
Hash.fromUniversalHashCode | ||
|
||
implicit val aggregationTemporalityShow: Show[AggregationTemporality] = | ||
Show.fromToString | ||
} |
55 changes: 55 additions & 0 deletions
55
...cs/src/test/scala/org/typelevel/otel4s/sdk/metrics/data/AggregationTemporalitySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2024 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s | ||
package sdk.metrics | ||
package data | ||
|
||
import cats.Show | ||
import cats.kernel.laws.discipline.HashTests | ||
import munit.DisciplineSuite | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Cogen | ||
import org.scalacheck.Gen | ||
import org.scalacheck.Prop | ||
|
||
class AggregationTemporalitySuite extends DisciplineSuite { | ||
|
||
implicit val aggregationTemporalityArb: Arbitrary[AggregationTemporality] = | ||
Arbitrary( | ||
Gen.oneOf(AggregationTemporality.Delta, AggregationTemporality.Cumulative) | ||
) | ||
|
||
implicit val aggregationTemporalityCogen: Cogen[AggregationTemporality] = | ||
Cogen[String].contramap(_.toString) | ||
|
||
checkAll( | ||
"AggregationTemporality.HashLaws", | ||
HashTests[AggregationTemporality].hash | ||
) | ||
|
||
test("Show[AggregationTemporality]") { | ||
Prop.forAll(aggregationTemporalityArb.arbitrary) { temporality => | ||
val expected = temporality match { | ||
case AggregationTemporality.Delta => "Delta" | ||
case AggregationTemporality.Cumulative => "Cumulative" | ||
} | ||
|
||
assertEquals(Show[AggregationTemporality].show(temporality), expected) | ||
} | ||
} | ||
|
||
} |