Skip to content

Commit

Permalink
chore: expose ability to switch distribution mode for top-level consu…
Browse files Browse the repository at this point in the history
…mers creating a ConfiguredMetrics object (#40)
  • Loading branch information
tylerburdsall authored Mar 20, 2024
1 parent 81b1520 commit f9b0a62
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kotlin/goodmetrics/src/main/kotlin/goodmetrics/MetricsSetups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MetricsSetups private constructor() {
* So I'll default the special lightstep configuration to use gzip compression. You can disable this if you want.
*/
compressionMode: CompressionMode = CompressionMode.Gzip,
distributionMode: DistributionMode = DistributionMode.Histogram,
): ConfiguredMetrics {
val client = opentelemetryClient(
lightstepAccessToken,
Expand All @@ -119,7 +120,8 @@ class MetricsSetups private constructor() {
preaggregatedBatchMaxMetricsCount,
preaggregatedBatchMaxAge,
onSendUnary,
onSendPreaggregated
onSendPreaggregated,
distributionMode,
)
}

Expand Down Expand Up @@ -196,6 +198,7 @@ class MetricsSetups private constructor() {
*/
logRawPayload: (ResourceMetrics) -> Unit = {},
compressionMode: CompressionMode = CompressionMode.Gzip,
distributionMode: DistributionMode = DistributionMode.Histogram,
): ConfiguredMetrics {
val client = opentelemetryClient(
accessToken,
Expand All @@ -219,7 +222,8 @@ class MetricsSetups private constructor() {
preaggregatedBatchMaxMetricsCount,
preaggregatedBatchMaxAge,
onSendUnary,
onSendPreaggregated
onSendPreaggregated,
distributionMode,
)
}

Expand Down Expand Up @@ -276,10 +280,11 @@ class MetricsSetups private constructor() {
preaggregatedBatchMaxMetricsCount: Int,
preaggregatedBatchMaxAge: Duration,
onSendUnary: (List<Metrics>) -> Unit,
onSendPreaggregated: (List<AggregatedBatch>) -> Unit
onSendPreaggregated: (List<AggregatedBatch>) -> Unit,
distributionMode: DistributionMode,
): ConfiguredMetrics {
val unarySink = configureBatchedUnaryOtlpSink(unaryBatchSizeMaxMetricsCount, unaryBatchMaxAge, client, logError, onSendUnary)
val preaggregatedSink = configureBatchedPreaggregatedOtlpSink(aggregationWidth, preaggregatedBatchMaxMetricsCount, preaggregatedBatchMaxAge, client, logError, onSendPreaggregated)
val preaggregatedSink = configureBatchedPreaggregatedOtlpSink(aggregationWidth, preaggregatedBatchMaxMetricsCount, preaggregatedBatchMaxAge, client, logError, onSendPreaggregated, distributionMode)

val unaryFactory = MetricsFactory(
sink = unarySink,
Expand Down Expand Up @@ -363,8 +368,7 @@ class MetricsSetups private constructor() {
client: OpentelemetryClient,
logError: (message: String, exception: Exception) -> Unit,
onSendPreaggregated: (List<AggregatedBatch>) -> Unit,
// By default, use Histogram distribution mode since ExponentialHistograms are not frequently used
distributionMode: DistributionMode = DistributionMode.Histogram,
distributionMode: DistributionMode,
): Aggregator {
val sink = Aggregator(aggregationWidth = aggregationWidth, distributionMode = distributionMode)
val batcher = Batcher(
Expand Down

0 comments on commit f9b0a62

Please sign in to comment.