mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-12 10:04:29 +02:00
9a2484c373
* Add tests for nonabsolute and varying sign values * Implement support for NonAbsolute Measurement MaxSumCount Previously, the MaxSumCount aggregator failed to work correctly with negative numbers (e.g. MeasureKind Alternate()==true). * Pass NumberKind to MaxSumCount New() function Allows it to set the initial state (current.max) to the correct value based on the NumberKind. * Revert extraneous local change * Pass full descriptor to msc New() This is analagous to the DDSketch New() constructor * Remember to run make precommit first * Add tests for empty checkpoint of MaxSumCount aggregator An empty checkpoint should have Sum() == 0, Count() == 0 and Max() still equal to the numberKind.Minimum() * Return ErrEmptyDataSet if no value set by the aggregator Remove TODO from stdout exporter to ensure that if a maxsumcount or ddsketch aggregator returns ErrEmptyDataSet from Max(), then the entire record will be skipped by the exporter. Added tests to ensure the exporter doesn't send any updates for EmptyDataSet checkpoints - for both ddsketch and maxsumcount. * Relayout Aggreggator struct to ensure int64s are 8-byte aligned On 32-bit architectures, Go only guarantees that primitive values are aligned to a 4 byte boundary. Atomic operations on 32-bit machines require 8-byte alignment. See https://github.com/golang/go/issues/599 * Addressing PR comments The use of Minimum() for the default uninitialized Maximum value means that in the unlikely condition that every recorded value for a measure is equal to the same NumberKind.Minimum(), then the aggregator's Max() will return ErrEmptyDataSet * Fix PR merge issue
101 lines
3.2 KiB
Go
101 lines
3.2 KiB
Go
// Copyright 2019, OpenTelemetry Authors
|
|
//
|
|
// 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 simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
|
|
|
import (
|
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/counter"
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch"
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/gauge"
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/maxsumcount"
|
|
)
|
|
|
|
type (
|
|
selectorInexpensive struct{}
|
|
selectorExact struct{}
|
|
selectorSketch struct {
|
|
config *ddsketch.Config
|
|
}
|
|
)
|
|
|
|
var (
|
|
_ export.AggregationSelector = selectorInexpensive{}
|
|
_ export.AggregationSelector = selectorSketch{}
|
|
_ export.AggregationSelector = selectorExact{}
|
|
)
|
|
|
|
// NewWithInexpensiveMeasure returns a simple aggregation selector
|
|
// that uses counter, gauge, and maxsumcount aggregators for the three
|
|
// kinds of metric. This selector is faster and uses less memory than
|
|
// the others because maxsumcount does not aggregate quantile
|
|
// information.
|
|
func NewWithInexpensiveMeasure() export.AggregationSelector {
|
|
return selectorInexpensive{}
|
|
}
|
|
|
|
// NewWithSketchMeasure returns a simple aggregation selector that
|
|
// uses counter, gauge, and ddsketch aggregators for the three kinds
|
|
// of metric. This selector uses more cpu and memory than the
|
|
// NewWithInexpensiveMeasure because it uses one DDSketch per distinct
|
|
// measure and labelset.
|
|
func NewWithSketchMeasure(config *ddsketch.Config) export.AggregationSelector {
|
|
return selectorSketch{
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
// NewWithExactMeasure returns a simple aggregation selector that uses
|
|
// counter, gauge, and array behavior for the three kinds of metric.
|
|
// This selector uses more memory than the NewWithSketchMeasure
|
|
// because it aggregates an array of all values, therefore is able to
|
|
// compute exact quantiles.
|
|
func NewWithExactMeasure() export.AggregationSelector {
|
|
return selectorExact{}
|
|
}
|
|
|
|
func (selectorInexpensive) AggregatorFor(descriptor *export.Descriptor) export.Aggregator {
|
|
switch descriptor.MetricKind() {
|
|
case export.GaugeKind:
|
|
return gauge.New()
|
|
case export.MeasureKind:
|
|
return maxsumcount.New(descriptor)
|
|
default:
|
|
return counter.New()
|
|
}
|
|
}
|
|
|
|
func (s selectorSketch) AggregatorFor(descriptor *export.Descriptor) export.Aggregator {
|
|
switch descriptor.MetricKind() {
|
|
case export.GaugeKind:
|
|
return gauge.New()
|
|
case export.MeasureKind:
|
|
return ddsketch.New(s.config, descriptor)
|
|
default:
|
|
return counter.New()
|
|
}
|
|
}
|
|
|
|
func (selectorExact) AggregatorFor(descriptor *export.Descriptor) export.Aggregator {
|
|
switch descriptor.MetricKind() {
|
|
case export.GaugeKind:
|
|
return gauge.New()
|
|
case export.MeasureKind:
|
|
return array.New()
|
|
default:
|
|
return counter.New()
|
|
}
|
|
}
|