mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-04-07 07:00:13 +02:00
* Refactor golangci-lint conf Order settings alphabetically. * Add revive settings to golangci conf * Check blank imports * Check bool-literal-in-expr * Check constant-logical-expr * Check context-as-argument * Check context-key-type * Check deep-exit * Check defer * Check dot-imports * Check duplicated-imports * Check early-return * Check empty-block * Check empty-lines * Check error-naming * Check error-return * Check error-strings * Check errorf * Stop ignoring context first arg in tests * Check exported comments * Check flag-parameter * Check identical branches * Check if-return * Check increment-decrement * Check indent-error-flow * Check deny list of go imports * Check import shadowing * Check package comments * Check range * Check range val in closure * Check range val address * Check redefines builtin id * Check string-format * Check struct tag * Check superfluous else * Check time equal * Check var naming * Check var declaration * Check unconditional recursion * Check unexported return * Check unhandled errors * Check unnecessary stmt * Check unnecessary break * Check waitgroup by value * Exclude deep-exit check in example*_test.go files
120 lines
3.5 KiB
Go
120 lines
3.5 KiB
Go
// 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.
|
|
|
|
package aggregation // import "go.opentelemetry.io/otel/sdk/metric/export/aggregation"
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/number"
|
|
)
|
|
|
|
// These interfaces describe the various ways to access state from an
|
|
// Aggregation.
|
|
|
|
type (
|
|
// Aggregation is an interface returned by the Aggregator
|
|
// containing an interval of metric data.
|
|
Aggregation interface {
|
|
// Kind returns a short identifying string to identify
|
|
// the Aggregator that was used to produce the
|
|
// Aggregation (e.g., "Sum").
|
|
Kind() Kind
|
|
}
|
|
|
|
// Sum returns an aggregated sum.
|
|
Sum interface {
|
|
Aggregation
|
|
Sum() (number.Number, error)
|
|
}
|
|
|
|
// Count returns the number of values that were aggregated.
|
|
Count interface {
|
|
Aggregation
|
|
Count() (uint64, error)
|
|
}
|
|
|
|
// LastValue returns the latest value that was aggregated.
|
|
LastValue interface {
|
|
Aggregation
|
|
LastValue() (number.Number, time.Time, error)
|
|
}
|
|
|
|
// Buckets represents histogram buckets boundaries and counts.
|
|
//
|
|
// For a Histogram with N defined boundaries, e.g, [x, y, z].
|
|
// There are N+1 counts: [-inf, x), [x, y), [y, z), [z, +inf].
|
|
Buckets struct {
|
|
// Boundaries are floating point numbers, even when
|
|
// aggregating integers.
|
|
Boundaries []float64
|
|
|
|
// Counts holds the count in each bucket.
|
|
Counts []uint64
|
|
}
|
|
|
|
// Histogram returns the count of events in pre-determined buckets.
|
|
Histogram interface {
|
|
Aggregation
|
|
Count() (uint64, error)
|
|
Sum() (number.Number, error)
|
|
Histogram() (Buckets, error)
|
|
}
|
|
)
|
|
|
|
type (
|
|
// Kind is a short name for the Aggregator that produces an
|
|
// Aggregation, used for descriptive purpose only. Kind is a
|
|
// string to allow user-defined Aggregators.
|
|
//
|
|
// When deciding how to handle an Aggregation, Exporters are
|
|
// encouraged to decide based on conversion to the above
|
|
// interfaces based on strength, not on Kind value, when
|
|
// deciding how to expose metric data. This enables
|
|
// user-supplied Aggregators to replace builtin Aggregators.
|
|
//
|
|
// For example, test for a Histogram before testing for a
|
|
// Sum, and so on.
|
|
Kind string
|
|
)
|
|
|
|
// Kind description constants.
|
|
const (
|
|
SumKind Kind = "Sum"
|
|
HistogramKind Kind = "Histogram"
|
|
LastValueKind Kind = "Lastvalue"
|
|
)
|
|
|
|
// Sentinel errors for Aggregation interface.
|
|
var (
|
|
ErrNegativeInput = fmt.Errorf("negative value is out of range for this instrument")
|
|
ErrNaNInput = fmt.Errorf("invalid input value: NaN")
|
|
ErrInconsistentType = fmt.Errorf("inconsistent aggregator types")
|
|
|
|
// ErrNoCumulativeToDelta is returned when requesting delta
|
|
// export kind for a precomputed sum instrument.
|
|
ErrNoCumulativeToDelta = fmt.Errorf("cumulative to delta not implemented")
|
|
|
|
// ErrNoData is returned when (due to a race with collection)
|
|
// the Aggregator is check-pointed before the first value is set.
|
|
// The aggregator should simply be skipped in this case.
|
|
ErrNoData = fmt.Errorf("no data collected by this aggregator")
|
|
)
|
|
|
|
// String returns the string value of Kind.
|
|
func (k Kind) String() string {
|
|
return string(k)
|
|
}
|