Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core-metrics: add varargs apply to the BucketBoundaries #714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ object BucketBoundaries {
Impl(boundaries)
}

/** Creates [[BucketBoundaries]] using the given `boundaries`.
*
* Throws an exception if any of the following rules is violated:
* - the boundary cannot be `Double.NaN`
* - the boundaries must be in increasing order
* - first boundary cannot be `Double.NegativeInfinity`
* - last boundary cannot be `Double.PositiveInfinity`
*
* @param boundaries
* the bucket boundaries
*/
def apply(boundaries: Double*): BucketBoundaries =
apply(boundaries.toVector)

implicit val bucketBoundariesHash: Hash[BucketBoundaries] =
Hash.by(_.boundaries)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ abstract class BaseMeterSuite extends CatsEffectSuite {
}

sdkTest("Histogram - use explicit bucket boundaries") { sdk =>
val boundaries = BucketBoundaries(Vector(1.0, 2.0, 3.0))
val boundaries = BucketBoundaries(1.0, 2.0, 3.0)
val expected = MetricData.histogram(
name = "histogram",
values = List(1.0),
Expand Down Expand Up @@ -348,10 +348,8 @@ object BaseMeterSuite {

object MetricData {
private val DefaultBoundaries = BucketBoundaries(
Vector(
0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0,
2500.0, 5000.0, 7500.0, 10000.0
)
0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0,
2500.0, 5000.0, 7500.0, 10000.0
)

def sum(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@ class BucketBoundariesSuite extends DisciplineSuite {
interceptMessage[IllegalArgumentException](
"requirement failed: bucket boundary cannot be NaN"
)(
BucketBoundaries(Vector(1.0, 2.0, Double.NaN, 3.0))
BucketBoundaries(1.0, 2.0, Double.NaN, 3.0)
)
}

test("fail when boundaries are not increasing") {
interceptMessage[IllegalArgumentException](
"requirement failed: bucket boundaries must be in increasing oder"
)(
BucketBoundaries(Vector(1.0, 1.2, 0.5, 3.0))
BucketBoundaries(1.0, 1.2, 0.5, 3.0)
)
}

test("fail when first boundary is -Inf") {
interceptMessage[IllegalArgumentException](
"requirement failed: first boundary cannot be -Inf"
)(
BucketBoundaries(Vector(Double.NegativeInfinity))
BucketBoundaries(Double.NegativeInfinity)
)
}

test("fail when last boundary is +Inf") {
interceptMessage[IllegalArgumentException](
"requirement failed: last boundary cannot be +Inf"
)(
BucketBoundaries(Vector(Double.PositiveInfinity))
BucketBoundaries(Double.PositiveInfinity)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ object Aggregation {
private[metrics] object Defaults {
// See https://opentelemetry.io/docs/specs/otel/metrics/sdk/#explicit-bucket-histogram-aggregation
val Boundaries: BucketBoundaries = BucketBoundaries(
Vector(
0d, 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 750d, 1000d, 2500d, 5000d,
7500d, 10000d
)
0d, 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 750d, 1000d, 2500d, 5000d,
7500d, 10000d
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ExemplarReservoirSuite
_.get(traceContextKey)

private val boundaries: BucketBoundaries =
BucketBoundaries(Vector(1.0, 5.0, 10.0))
BucketBoundaries(1.0, 5.0, 10.0)

//
// Fixed size
Expand Down