Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default aggregation for Counter, Observer and Recorder (#41)
* Change default aggregation for Counter, Observer and Recorder * Fixes #25 * Fixes #37 * Change metric exporter version 0.2.0 -> v0.2.1 * Change to pass make precommit * Add support for SumObserver and UpDownSumObserver. * Add support for SumObserver and UpDownSumObserver * Fix package name to call for consistency (metric -> apimetric) * Fix version to use in the metric example * Fix comments
- Loading branch information
1 parent
ec6b73c
commit 5fb47d1
Showing
6 changed files
with
153 additions
and
59 deletions.
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
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,51 @@ | ||
// Copyright 2020, Google Inc. | ||
// | ||
// 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 metric | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
apimetric "go.opentelemetry.io/otel/api/metric" | ||
export "go.opentelemetry.io/otel/sdk/export/metric" | ||
) | ||
|
||
var ( | ||
errBlankProjectID = errors.New("expecting a non-blank ProjectID") | ||
) | ||
|
||
type errUnsupportedAggregation struct { | ||
agg export.Aggregator | ||
} | ||
|
||
func (e errUnsupportedAggregation) Error() string { | ||
return fmt.Sprintf("currently the aggregator is not supported: %v", e.agg) | ||
} | ||
|
||
type errUnexpectedNumberKind struct { | ||
kind apimetric.NumberKind | ||
} | ||
|
||
func (e errUnexpectedNumberKind) Error() string { | ||
return fmt.Sprintf("the number kind is unexpected: %v", e.kind) | ||
} | ||
|
||
type errUnexpectedMetricKind struct { | ||
kind apimetric.Kind | ||
} | ||
|
||
func (e errUnexpectedMetricKind) Error() string { | ||
return fmt.Sprintf("the metric kind is unexpected: %v", e.kind) | ||
} |
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
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,54 @@ | ||
// Copyright 2020, Google Inc. | ||
// | ||
// 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 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" | ||
) | ||
|
||
type selectorCloudMonitoring struct{} | ||
|
||
var _ export.AggregationSelector = selectorCloudMonitoring{} | ||
|
||
// NewWithCloudMonitoringDistribution return a simple aggregation selector | ||
// that uses lastvalue, counter, array, and aggregator for three kinds of metric. | ||
// | ||
// NOTE: this selector is just to ensure that LastValue is used for | ||
// ValueObserverKind and ValueRecorderKind. | ||
// | ||
// TODO: Remove this once SDK implements such a | ||
// selector, otherwise Views API gives flexibility to set aggregation type on | ||
// configuring measurement. | ||
// c.f. https://github.com/open-telemetry/oteps/pull/89 | ||
func NewWithCloudMonitoringDistribution() export.AggregationSelector { | ||
return selectorCloudMonitoring{} | ||
} | ||
|
||
func (selectorCloudMonitoring) AggregatorFor(descriptor *apimetric.Descriptor) export.Aggregator { | ||
switch descriptor.MetricKind() { | ||
case apimetric.ValueObserverKind, apimetric.ValueRecorderKind: | ||
return lastvalue.New() | ||
// 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: | ||
return array.New() | ||
default: | ||
return sum.New() | ||
} | ||
} |