Skip to content

Commit

Permalink
Start transient Accum
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacd committed Sep 26, 2020
1 parent 0b348c3 commit 401bc7c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/global/internal/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func (inst *instrument) Descriptor() metric.Descriptor {
return inst.descriptor
}

func (inst *instrument) Unref() {
}

// MeterProvider interface and delegation

func newMeterProvider() *meterProvider {
Expand Down
3 changes: 3 additions & 0 deletions api/metric/metrictest/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (i Instrument) Descriptor() apimetric.Descriptor {
return i.descriptor
}

func (i Instrument) Unref() {
}

func (a *Async) Implementation() interface{} {
return a
}
Expand Down
3 changes: 3 additions & 0 deletions api/metric/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (noopInstrument) Implementation() interface{} {
return nil
}

func (noopInstrument) Unref() {
}

func (noopInstrument) Descriptor() Descriptor {
return Descriptor{}
}
Expand Down
3 changes: 3 additions & 0 deletions api/metric/sdkapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type InstrumentImpl interface {

// Descriptor returns a copy of the instrument's Descriptor.
Descriptor() Descriptor

// @@@
Unref()
}

// SyncImpl is the implementation-level interface to a generic
Expand Down
4 changes: 4 additions & 0 deletions sdk/metric/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func (inst *instrument) Descriptor() api.Descriptor {
return inst.descriptor
}

func (inst *instrument) Unref() {
// This is a no-op for the standard Accumulator.
}

func (a *asyncInstrument) Implementation() interface{} {
return a
}
Expand Down
60 changes: 60 additions & 0 deletions sdk/metric/transient/transient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 transient

import (
"context"
"fmt"

"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
sdk "go.opentelemetry.io/otel/sdk/metric"
)

type Accumulator struct {
standard *sdk.Accumulator
}

var (
ErrAsyncNotSupported = fmt.Errorf("transient asynchronous instruments not supported")

_ metric.MeterImpl = &Accumulator{}
)

func NewAccumulator(processor export.Processor, opts ...sdk.Option) *Accumulator {
return &Accumulator{
standard: sdk.NewAccumulator(processor, opts...),
}
}

func (a *Accumulator) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) {
a.standard.RecordBatch(ctx, labels, measurements...)
}

func (a *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) {
return a.standard.NewSyncInstrument(descriptor)
}

func (a *Accumulator) NewAsyncInstrument(
descriptor metric.Descriptor,
runner metric.AsyncRunner,
) (metric.AsyncImpl, error) {
return metric.NoopAsync{}, ErrAsyncNotSupported
}

func (m *Accumulator) Collect(ctx context.Context) int {
return 0
}

0 comments on commit 401bc7c

Please sign in to comment.