Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ExportKind to Temporality #2272

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- NoopMeterProvider is now private and NewNoopMeterProvider must be used to obtain a noopMeterProvider. (#2237)
- Metric SDK `ExportKind`, `ExportKindSelector` types have been renamed `Temporality` and `TemporalitySelector` in line with current specification and protocol along with built-in selectors (e.g., `CumulativeTemporalitySelector`). (#xxxx)

## [1.0.0] - 2021-09-20

Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ export.Reader = &metricReader{}

// ForEach iterates through the metrics data, synthesizing an
// export.Record with the appropriate aggregation for the exporter.
func (d *metricReader) ForEach(exporter export.ExportKindSelector, f func(export.Record) error) error {
func (d *metricReader) ForEach(exporter export.TemporalitySelector, f func(export.Record) error) error {
for _, m := range d.metrics {
descriptor, err := convertDescriptor(m.Descriptor)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type fakeExporter struct {
}

func (f *fakeExporter) Export(ctx context.Context, res *resource.Resource, ilr exportmetric.InstrumentationLibraryReader) error {
return controllertest.ReadAll(ilr, export.StatelessExportKindSelector(),
return controllertest.ReadAll(ilr, export.StatelessTemporalitySelector(),
func(_ instrumentation.Library, record exportmetric.Record) error {
f.resource = res
f.records = append(f.records, record)
Expand Down
2 changes: 1 addition & 1 deletion example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func initMeter() {
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
export.CumulativeTemporalitySelector(),
processor.WithMemory(true),
),
)
Expand Down
16 changes: 8 additions & 8 deletions exporters/otlp/otlpmetric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var (

// Exporter exports metrics data in the OTLP wire format.
type Exporter struct {
client Client
exportKindSelector metricsdk.ExportKindSelector
client Client
temporalitySelector metricsdk.TemporalitySelector

mu sync.RWMutex
started bool
Expand Down Expand Up @@ -96,8 +96,8 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

func (e *Exporter) ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) metricsdk.ExportKind {
return e.exportKindSelector.ExportKindFor(descriptor, aggregatorKind)
func (e *Exporter) TemporalityFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) metricsdk.Temporality {
return e.temporalitySelector.TemporalityFor(descriptor, aggregatorKind)
}

var _ metricsdk.Exporter = (*Exporter)(nil)
Expand All @@ -114,19 +114,19 @@ func New(ctx context.Context, client Client, opts ...Option) (*Exporter, error)
// NewUnstarted constructs a new Exporter and does not start it.
func NewUnstarted(client Client, opts ...Option) *Exporter {
cfg := config{
// Note: the default ExportKindSelector is specified
// Note: the default TemporalitySelector is specified
// as Cumulative:
// https://github.com/open-telemetry/opentelemetry-specification/issues/731
exportKindSelector: metricsdk.CumulativeExportKindSelector(),
temporalitySelector: metricsdk.CumulativeTemporalitySelector(),
}

for _, opt := range opts {
opt.apply(&cfg)
}

e := &Exporter{
client: client,
exportKindSelector: cfg.exportKindSelector,
client: client,
temporalitySelector: cfg.temporalitySelector,
}

return e
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/otlpmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
)
}

func TestStatelessExportKind(t *testing.T) {
func TestStatelessTemporality(t *testing.T) {
type testcase struct {
name string
instrumentKind sdkapi.InstrumentKind
Expand All @@ -624,8 +624,8 @@ func TestStatelessExportKind(t *testing.T) {
runMetricExportTests(
t,
[]otlpmetric.Option{
otlpmetric.WithMetricExportKindSelector(
metricsdk.StatelessExportKindSelector(),
otlpmetric.WithMetricTemporalitySelector(
metricsdk.StatelessTemporalitySelector(),
),
},
testerAResource,
Expand Down
28 changes: 14 additions & 14 deletions exporters/otlp/otlpmetric/internal/metrictransform/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func toNanos(t time.Time) uint64 {

// InstrumentationLibraryReader transforms all records contained in a checkpoint into
// batched OTLP ResourceMetrics.
func InstrumentationLibraryReader(ctx context.Context, exportSelector export.ExportKindSelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) {
func InstrumentationLibraryReader(ctx context.Context, exportSelector export.TemporalitySelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) {
var ilms []*metricpb.InstrumentationLibraryMetrics

err := ilmr.ForEach(func(lib instrumentation.Library, mr export.Reader) error {
Expand Down Expand Up @@ -134,7 +134,7 @@ func InstrumentationLibraryReader(ctx context.Context, exportSelector export.Exp
// source starts a goroutine that sends each one of the Records yielded by
// the Reader on the returned chan. Any error encountered will be sent
// on the returned error chan after seeding is complete.
func source(ctx context.Context, exportSelector export.ExportKindSelector, mr export.Reader) (<-chan export.Record, <-chan error) {
func source(ctx context.Context, exportSelector export.TemporalitySelector, mr export.Reader) (<-chan export.Record, <-chan error) {
errc := make(chan error, 1)
out := make(chan export.Record)
// Seed records into process.
Expand All @@ -155,7 +155,7 @@ func source(ctx context.Context, exportSelector export.ExportKindSelector, mr ex

// transformer transforms records read from the passed in chan into
// OTLP Metrics which are sent on the out chan.
func transformer(ctx context.Context, exportSelector export.ExportKindSelector, in <-chan export.Record, out chan<- result) {
func transformer(ctx context.Context, exportSelector export.TemporalitySelector, in <-chan export.Record, out chan<- result) {
for r := range in {
m, err := Record(exportSelector, r)
// Propagate errors, but do not send empty results.
Expand Down Expand Up @@ -237,7 +237,7 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.Metric, error) {

// Record transforms a Record into an OTLP Metric. An ErrIncompatibleAgg
// error is returned if the Record Aggregator is not supported.
func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricpb.Metric, error) {
func Record(exportSelector export.TemporalitySelector, r export.Record) (*metricpb.Metric, error) {
agg := r.Aggregation()
switch agg.Kind() {
case aggregation.MinMaxSumCountKind:
Expand All @@ -252,7 +252,7 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp
if !ok {
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
}
return histogramPoint(r, exportSelector.ExportKindFor(r.Descriptor(), aggregation.HistogramKind), h)
return histogramPoint(r, exportSelector.TemporalityFor(r.Descriptor(), aggregation.HistogramKind), h)

case aggregation.SumKind:
s, ok := agg.(aggregation.Sum)
Expand All @@ -263,7 +263,7 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp
if err != nil {
return nil, err
}
return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.ExportKindFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic())
return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.TemporalityFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic())

case aggregation.LastValueKind:
lv, ok := agg.(aggregation.LastValue)
Expand Down Expand Up @@ -388,17 +388,17 @@ func gaugePoint(record export.Record, num number.Number, start, end time.Time) (
return m, nil
}

func exportKindToTemporality(ek export.ExportKind) metricpb.AggregationTemporality {
func sdkTemporalityToTemporality(ek export.Temporality) metricpb.AggregationTemporality {
switch ek {
case export.DeltaExportKind:
case export.DeltaTemporality:
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA
case export.CumulativeExportKind:
case export.CumulativeTemporality:
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
}
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED
}

func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.ExportKind, monotonic bool) (*metricpb.Metric, error) {
func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.Temporality, monotonic bool) (*metricpb.Metric, error) {
desc := record.Descriptor()
labels := record.Labels()

Expand All @@ -413,7 +413,7 @@ func sumPoint(record export.Record, num number.Number, start, end time.Time, ek
m.Data = &metricpb.Metric_Sum{
Sum: &metricpb.Sum{
IsMonotonic: monotonic,
AggregationTemporality: exportKindToTemporality(ek),
AggregationTemporality: sdkTemporalityToTemporality(ek),
DataPoints: []*metricpb.NumberDataPoint{
{
Value: &metricpb.NumberDataPoint_AsInt{
Expand All @@ -430,7 +430,7 @@ func sumPoint(record export.Record, num number.Number, start, end time.Time, ek
m.Data = &metricpb.Metric_Sum{
Sum: &metricpb.Sum{
IsMonotonic: monotonic,
AggregationTemporality: exportKindToTemporality(ek),
AggregationTemporality: sdkTemporalityToTemporality(ek),
DataPoints: []*metricpb.NumberDataPoint{
{
Value: &metricpb.NumberDataPoint_AsDouble{
Expand Down Expand Up @@ -522,7 +522,7 @@ func histogramValues(a aggregation.Histogram) (boundaries []float64, counts []ui
}

// histogram transforms a Histogram Aggregator into an OTLP Metric.
func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Histogram) (*metricpb.Metric, error) {
func histogramPoint(record export.Record, ek export.Temporality, a aggregation.Histogram) (*metricpb.Metric, error) {
desc := record.Descriptor()
labels := record.Labels()
boundaries, counts, err := histogramValues(a)
Expand All @@ -546,7 +546,7 @@ func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Hi
Unit: string(desc.Unit()),
Data: &metricpb.Metric_Histogram{
Histogram: &metricpb.Histogram{
AggregationTemporality: exportKindToTemporality(ek),
AggregationTemporality: sdkTemporalityToTemporality(ek),
DataPoints: []*metricpb.HistogramDataPoint{
{
Sum: sum.CoerceToFloat64(desc.NumberKind()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestSumIntDataPoints(t *testing.T) {
value, err := ckpt.Sum()
require.NoError(t, err)

if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeExportKind, true); assert.NoError(t, err) {
if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeTemporality, true); assert.NoError(t, err) {
assert.Nil(t, m.GetGauge())
assert.Equal(t, &metricpb.Sum{
AggregationTemporality: otelCumulative,
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestSumFloatDataPoints(t *testing.T) {
value, err := ckpt.Sum()
require.NoError(t, err)

if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.DeltaExportKind, false); assert.NoError(t, err) {
if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.DeltaTemporality, false); assert.NoError(t, err) {
assert.Nil(t, m.GetGauge())
assert.Equal(t, &metricpb.Sum{
IsMonotonic: false,
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestSumErrUnknownValueType(t *testing.T) {
value, err := s.Sum()
require.NoError(t, err)

_, err = sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeExportKind, true)
_, err = sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeTemporality, true)
assert.Error(t, err)
if !errors.Is(err, ErrUnknownValueType) {
t.Errorf("expected ErrUnknownValueType, got %v", err)
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
kind: kind,
agg: agg,
}
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, test, intervalStart, intervalEnd))
return Record(export.CumulativeTemporalitySelector(), export.NewRecord(&desc, &labels, test, intervalStart, intervalEnd))
}

mpb, err := makeMpb(aggregation.SumKind, &lastvalue.New(1)[0])
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestRecordAggregatorUnexpectedErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := metrictest.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind)
labels := attribute.NewSet()
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, agg, intervalStart, intervalEnd))
return Record(export.CumulativeTemporalitySelector(), export.NewRecord(&desc, &labels, agg, intervalStart, intervalEnd))
}

errEx := fmt.Errorf("timeout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
// themselves.
func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter, mcMetrics Collector) {
selector := simple.NewWithInexpensiveDistribution()
proc := processor.NewFactory(selector, exportmetric.StatelessExportKindSelector())
proc := processor.NewFactory(selector, exportmetric.StatelessTemporalitySelector())
cont := controller.New(proc, controller.WithExporter(exp))
require.NoError(t, cont.Start(ctx))

Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/otlpmetric/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func (fn exporterOptionFunc) apply(cfg *config) {
}

type config struct {
exportKindSelector metricsdk.ExportKindSelector
temporalitySelector metricsdk.TemporalitySelector
}

// WithMetricExportKindSelector defines the ExportKindSelector used
// WithMetricTemporalitySelector defines the TemporalitySelector used
// for selecting AggregationTemporality (i.e., Cumulative vs. Delta
// aggregation). If not specified otherwise, exporter will use a
// cumulative export kind selector.
func WithMetricExportKindSelector(selector metricsdk.ExportKindSelector) Option {
func WithMetricTemporalitySelector(selector metricsdk.TemporalitySelector) Option {
return exporterOptionFunc(func(cfg *config) {
cfg.exportKindSelector = selector
cfg.temporalitySelector = selector
})
}
6 changes: 3 additions & 3 deletions exporters/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func (e *Exporter) Controller() *controller.Controller {
return e.controller
}

// ExportKindFor implements ExportKindSelector.
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) export.ExportKind {
return export.CumulativeExportKindSelector().ExportKindFor(desc, kind)
// TemporalityFor implements TemporalitySelector.
func (e *Exporter) TemporalityFor(desc *metric.Descriptor, kind aggregation.Kind) export.Temporality {
return export.CumulativeTemporalitySelector().TemporalityFor(desc, kind)
}

// ServeHTTP implements http.Handler.
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newPipeline(config prometheus.Config, options ...controller.Option) (*prome
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
export.CumulativeTemporalitySelector(),
processor.WithMemory(true),
),
options...,
Expand Down
4 changes: 2 additions & 2 deletions exporters/stdout/stdoutmetric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type line struct {
Timestamp *time.Time `json:"Timestamp,omitempty"`
}

func (e *metricExporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.ExportKind {
return exportmetric.StatelessExportKindSelector().ExportKindFor(desc, kind)
func (e *metricExporter) TemporalityFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.Temporality {
return exportmetric.StatelessTemporalitySelector().TemporalityFor(desc, kind)
}

func (e *metricExporter) Export(_ context.Context, res *resource.Resource, reader exportmetric.InstrumentationLibraryReader) error {
Expand Down
4 changes: 2 additions & 2 deletions exporters/stdout/stdoutmetric/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newFixtureWithResource(t *testing.T, res *resource.Resource, opts ...stdout
t.Fatal("Error building fixture: ", err)
}
aggSel := processortest.AggregatorSelector()
proc := processor.NewFactory(aggSel, export.StatelessExportKindSelector())
proc := processor.NewFactory(aggSel, export.StatelessTemporalitySelector())
cont := controller.New(proc,
controller.WithExporter(exp),
controller.WithResource(res),
Expand All @@ -87,7 +87,7 @@ func (fix testFixture) Output() string {
func TestStdoutTimestamp(t *testing.T) {
var buf bytes.Buffer
aggSel := processortest.AggregatorSelector()
proc := processor.NewFactory(aggSel, export.CumulativeExportKindSelector())
proc := processor.NewFactory(aggSel, export.CumulativeTemporalitySelector())
exporter, err := stdoutmetric.New(
stdoutmetric.WithWriter(&buf),
)
Expand Down
25 changes: 0 additions & 25 deletions sdk/export/metric/exportkind_string.go

This file was deleted.

Loading