2020-08-13 15:47:17 -07:00
|
|
|
// Copyright The 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.
|
|
|
|
|
|
|
|
/*
|
2022-04-18 07:31:31 -07:00
|
|
|
Package reducer implements a metrics Processor component to reduce attributes.
|
2020-10-29 09:23:13 -07:00
|
|
|
|
|
|
|
This package is currently in a pre-GA phase. Backwards incompatible changes
|
|
|
|
may be introduced in subsequent minor version releases as we work to track the
|
|
|
|
evolving OpenTelemetry specification and user feedback.
|
|
|
|
|
2022-04-18 07:31:31 -07:00
|
|
|
The metrics Processor component this package implements applies an
|
|
|
|
attribute.Filter to each processed export.Accumulation to remove attributes
|
|
|
|
before passing the result to another Processor. This Processor can be used to
|
|
|
|
reduce inherent dimensionality in the data, as a way to control the cost of
|
2020-10-29 09:23:13 -07:00
|
|
|
collecting high cardinality metric data.
|
2020-08-13 15:47:17 -07:00
|
|
|
|
|
|
|
For example, to compose a push controller with a reducer and a basic
|
|
|
|
metric processor:
|
|
|
|
|
|
|
|
type someFilter struct{
|
|
|
|
// configuration for this filter
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
2022-04-18 07:31:31 -07:00
|
|
|
func (someFilter) AttributeFilterFor(_ *sdkapi.Descriptor) attribute.Filter {
|
|
|
|
return func(attr kv.KeyValue) bool {
|
|
|
|
// return true to keep this attr, false to drop this attr.
|
2020-08-13 15:47:17 -07:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupMetrics(exporter export.Exporter) (stop func()) {
|
2021-11-15 10:05:14 -08:00
|
|
|
basicProcessorFactory := basic.NewFactory(
|
|
|
|
simple.NewWithHistogramDistribution(),
|
2020-08-13 15:47:17 -07:00
|
|
|
exporter,
|
|
|
|
)
|
|
|
|
|
2021-11-15 10:05:14 -08:00
|
|
|
reducerProcessor := reducer.NewFactory(someFilter{...}, basicProcessorFactory)
|
2020-08-13 15:47:17 -07:00
|
|
|
|
2021-11-15 10:05:14 -08:00
|
|
|
controller := controller.New(
|
2020-08-13 15:47:17 -07:00
|
|
|
reducerProcessor,
|
|
|
|
exporter,
|
2021-11-15 10:05:14 -08:00
|
|
|
opts...,
|
2020-08-13 15:47:17 -07:00
|
|
|
)
|
2021-11-15 10:05:14 -08:00
|
|
|
controller.Start()
|
|
|
|
global.SetMeterProvider(controller.Provider())
|
|
|
|
return controller.Stop
|
2020-08-13 15:47:17 -07:00
|
|
|
*/
|
|
|
|
package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
|