Skip to content

Commit

Permalink
Async metrics (#92)
Browse files Browse the repository at this point in the history
* Set metric kind for SumObserver and UpDownSumObserver #89

* Cast to array aggregator instead of sum aggregator

* Add TODO to handle UpDdownCounters and UpDownObservers

* Update metrics exporter to otel v0.11.0 (#91)

* Update metrics exporter: kv -> label

* Update metrics exporter to otel v0.11.0

* Update metrics example to v0.11.0

* Update dependency on deprecated cloud monitoring package

* Update otel SDK dependency to v0.11.0

* Prepare for releasing v0.11.0 (#93)

* Modify default aggregation in the custom selector

Co-authored-by: Nail Islamov <nilebox@users.noreply.github.com>
  • Loading branch information
liiling and nilebox committed Sep 10, 2020
1 parent 84f7c39 commit ef5e24b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions exporter/metric/metric.go
Expand Up @@ -421,12 +421,12 @@ func recordToMdpbKindType(r *export.Record) (googlemetricpb.MetricDescriptor_Met

var kind googlemetricpb.MetricDescriptor_MetricKind
switch mkind {
case apimetric.CounterKind, apimetric.UpDownCounterKind:
// TODO: Decide how UpDownCounterKind and UpDownSumObserverKind should be handled.
// CUMULATIVE might not be correct as it assumes the metric always goes up.
case apimetric.CounterKind, apimetric.UpDownCounterKind, apimetric.SumObserverKind, apimetric.UpDownSumObserverKind:
kind = googlemetricpb.MetricDescriptor_CUMULATIVE
case apimetric.ValueObserverKind, apimetric.ValueRecorderKind:
kind = googlemetricpb.MetricDescriptor_GAUGE
// TODO: Add support for SumObserverKind and UpDownSumObserverKind.
// https://pkg.go.dev/go.opentelemetry.io/otel@v0.6.0/api/metric?tab=doc#Kind
default:
kind = googlemetricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED
}
Expand Down
10 changes: 2 additions & 8 deletions exporter/metric/selector.go
Expand Up @@ -17,7 +17,6 @@ package metric
import (
apimetric "go.opentelemetry.io/otel/api/metric"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
)
Expand All @@ -31,6 +30,8 @@ var _ export.AggregatorSelector = selectorCloudMonitoring{}
//
// NOTE: this selector is just to ensure that LastValue is used for
// ValueObserverKind and ValueRecorderKind.
// All other metric kinds have Sum default aggregation
// c.f. https://github.com/open-telemetry/opentelemetry-go/blob/master/sdk/metric/selector/simple/simple.go
//
// TODO: Remove this once SDK implements such a
// selector, otherwise Views API gives flexibility to set aggregation type on
Expand All @@ -47,13 +48,6 @@ func (selectorCloudMonitoring) AggregatorFor(descriptor *apimetric.Descriptor, a
for i := range aggPtrs {
*aggPtrs[i] = &aggs[i]
}
// NOTE: `array` gives the option to use Sum, Count, Max, Min, Quantile and Points (most flexible),
// so chosen for future implementations rather than `sum`.
case apimetric.CounterKind, apimetric.UpDownCounterKind, apimetric.SumObserverKind, apimetric.UpDownSumObserverKind:
aggs := array.New(len(aggPtrs))
for i := range aggPtrs {
*aggPtrs[i] = &aggs[i]
}
default:
aggs := sum.New(len(aggPtrs))
for i := range aggPtrs {
Expand Down

0 comments on commit ef5e24b

Please sign in to comment.