Skip to content

Commit

Permalink
Move export types into trace and metric-specific subdirs (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacd authored Nov 5, 2019
1 parent 17439d8 commit 68bd627
Show file tree
Hide file tree
Showing 35 changed files with 165 additions and 183 deletions.
2 changes: 1 addition & 1 deletion exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"go.opentelemetry.io/otel/api/core"
gen "go.opentelemetry.io/otel/exporter/trace/jaeger/internal/gen-go/jaeger"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

const defaultServiceName = "OpenTelemetry"
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

"go.opentelemetry.io/otel/api/core"
gen "go.opentelemetry.io/otel/exporter/trace/jaeger/internal/gen-go/jaeger"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

func TestNewExporter(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"google.golang.org/api/option"

"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

// Option is function type that is passed to the exporter initialization function.
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stackdriver/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
traceclient "cloud.google.com/go/trace/apiv2"
tracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"

"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

// traceExporter is an imeplementation of trace.Exporter and trace.BatchExporter
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stackdriver/trace_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

"go.opentelemetry.io/otel/api/core"
opentelemetry "go.opentelemetry.io/otel/sdk"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stdout/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"io"
"os"

"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

// Options are the options to be used when initializing a stdout export.
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stdout/stdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
)

func TestExporter_ExportSpan(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/clienttrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/global"
"go.opentelemetry.io/otel/plugin/httptrace"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

Expand Down
63 changes: 0 additions & 63 deletions sdk/export/exporter.go

This file was deleted.

57 changes: 40 additions & 17 deletions sdk/export/metric.go → sdk/export/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package export
package metric // import "go.opentelemetry.io/otel/sdk/export/metric"

import (
"context"
Expand All @@ -21,26 +21,49 @@ import (
"go.opentelemetry.io/otel/api/unit"
)

// MetricAggregator implements a specific aggregation behavior, e.g.,
// Batcher is responsible for deciding which kind of aggregation
// to use and gathering exported results from the SDK. The standard SDK
// supports binding only one of these interfaces, i.e., a single exporter.
//
// Multiple-exporters could be implemented by implementing this interface
// for a group of Batcher.
type Batcher interface {
// AggregatorFor should return the kind of aggregator
// suited to the requested export. Returning `nil`
// indicates to ignore the metric update.
//
// Note: This is context-free because the handle should not be
// bound to the incoming context. This call should not block.
AggregatorFor(Record) Aggregator

// Export receives pairs of records and aggregators
// during the SDK Collect(). Exporter implementations
// must access the specific aggregator to receive the
// exporter data, since the format of the data varies
// by aggregation.
Export(context.Context, Record, Aggregator)
}

// Aggregator implements a specific aggregation behavior, e.g.,
// a counter, a gauge, a histogram.
type MetricAggregator interface {
type Aggregator interface {
// Update receives a new measured value and incorporates it
// into the aggregation.
Update(context.Context, core.Number, MetricRecord)
Update(context.Context, core.Number, Record)

// Collect is called during the SDK Collect() to
// finish one period of aggregation. Collect() is
// called in a single-threaded context. Update()
// calls may arrive concurrently.
Collect(context.Context, MetricRecord, MetricBatcher)
Collect(context.Context, Record, Batcher)

// Merge combines state from two aggregators into one.
Merge(MetricAggregator, *Descriptor)
Merge(Aggregator, *Descriptor)
}

// MetricRecord is the unit of export, pairing a metric
// Record is the unit of export, pairing a metric
// instrument and set of labels.
type MetricRecord interface {
type Record interface {
// Descriptor() describes the metric instrument.
Descriptor() *Descriptor

Expand All @@ -49,19 +72,19 @@ type MetricRecord interface {
Labels() []core.KeyValue
}

// MetricKind describes the kind of instrument.
type MetricKind int8
// Kind describes the kind of instrument.
type Kind int8

const (
CounterMetricKind MetricKind = iota
GaugeMetricKind
MeasureMetricKind
CounterKind Kind = iota
GaugeKind
MeasureKind
)

// Descriptor describes a metric instrument to the exporter.
type Descriptor struct {
name string
metricKind MetricKind
metricKind Kind
keys []core.Key
description string
unit unit.Unit
Expand All @@ -70,10 +93,10 @@ type Descriptor struct {
}

// NewDescriptor builds a new descriptor, for use by `Meter`
// implementations.
// implementations to interface with a metric export pipeline.
func NewDescriptor(
name string,
metricKind MetricKind,
metricKind Kind,
keys []core.Key,
description string,
unit unit.Unit,
Expand All @@ -95,7 +118,7 @@ func (d *Descriptor) Name() string {
return d.name
}

func (d *Descriptor) MetricKind() MetricKind {
func (d *Descriptor) MetricKind() Kind {
return d.metricKind
}

Expand Down
24 changes: 23 additions & 1 deletion sdk/export/span.go → sdk/export/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package export
package trace // import "go.opentelemetry.io/otel/sdk/export/trace"

import (
"context"
"time"

"google.golang.org/grpc/codes"
Expand All @@ -23,6 +24,27 @@ import (
apitrace "go.opentelemetry.io/otel/api/trace"
)

// SpanSyncer is a type for functions that receive a single sampled trace span.
//
// The ExportSpan method is called synchronously. Therefore, it should not take
// forever to process the span.
//
// The SpanData should not be modified.
type SpanSyncer interface {
ExportSpan(context.Context, *SpanData)
}

// SpanBatcher is a type for functions that receive batched of sampled trace
// spans.
//
// The ExportSpans method is called asynchronously. However its should not take
// forever to process the spans.
//
// The SpanData should not be modified.
type SpanBatcher interface {
ExportSpans(context.Context, []*SpanData)
}

// SpanData contains all the information collected by a span.
type SpanData struct {
SpanContext core.SpanContext
Expand Down
10 changes: 5 additions & 5 deletions sdk/metric/aggregator/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"unsafe"

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

Expand All @@ -37,7 +37,7 @@ type (
Points []core.Number
)

var _ export.MetricAggregator = &Aggregator{}
var _ export.Aggregator = &Aggregator{}

func New() *Aggregator {
return &Aggregator{}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *Aggregator) Quantile(q float64) (core.Number, error) {
return c.checkpoint.Quantile(q)
}

func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) {
func (c *Aggregator) Collect(ctx context.Context, rec export.Record, exp export.Batcher) {
c.lock.Lock()
c.checkpoint, c.current = c.current, nil
c.lock.Unlock()
Expand All @@ -87,7 +87,7 @@ func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp e
exp.Export(ctx, rec, c)
}

func (c *Aggregator) Update(_ context.Context, number core.Number, rec export.MetricRecord) {
func (c *Aggregator) Update(_ context.Context, number core.Number, rec export.Record) {
desc := rec.Descriptor()
kind := desc.NumberKind()

Expand All @@ -107,7 +107,7 @@ func (c *Aggregator) Update(_ context.Context, number core.Number, rec export.Me
c.lock.Unlock()
}

func (c *Aggregator) Merge(oa export.MetricAggregator, desc *export.Descriptor) {
func (c *Aggregator) Merge(oa export.Aggregator, desc *export.Descriptor) {
o, _ := oa.(*Aggregator)
if o == nil {
// TODO warn
Expand Down
10 changes: 5 additions & 5 deletions sdk/metric/aggregator/array/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/sdk/export"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator"
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
)
Expand All @@ -36,7 +36,7 @@ type updateTest struct {
func (ut *updateTest) run(t *testing.T, profile test.Profile) {
ctx := context.Background()

batcher, record := test.NewAggregatorTest(export.MeasureMetricKind, profile.NumberKind, !ut.absolute)
batcher, record := test.NewAggregatorTest(export.MeasureKind, profile.NumberKind, !ut.absolute)

agg := New()

Expand Down Expand Up @@ -106,7 +106,7 @@ type mergeTest struct {
func (mt *mergeTest) run(t *testing.T, profile test.Profile) {
ctx := context.Background()

batcher, record := test.NewAggregatorTest(export.MeasureMetricKind, profile.NumberKind, !mt.absolute)
batcher, record := test.NewAggregatorTest(export.MeasureKind, profile.NumberKind, !mt.absolute)

agg1 := New()
agg2 := New()
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestArrayErrors(t *testing.T) {

ctx := context.Background()

batcher, record := test.NewAggregatorTest(export.MeasureMetricKind, profile.NumberKind, false)
batcher, record := test.NewAggregatorTest(export.MeasureKind, profile.NumberKind, false)

agg.Update(ctx, core.Number(0), record)

Expand Down Expand Up @@ -226,7 +226,7 @@ func TestArrayErrors(t *testing.T) {
func TestArrayFloat64(t *testing.T) {
for _, absolute := range []bool{false, true} {
t.Run(fmt.Sprint("Absolute=", absolute), func(t *testing.T) {
batcher, record := test.NewAggregatorTest(export.MeasureMetricKind, core.Float64NumberKind, !absolute)
batcher, record := test.NewAggregatorTest(export.MeasureKind, core.Float64NumberKind, !absolute)

fpsf := func(sign int) []float64 {
// Check behavior of a bunch of odd floating
Expand Down
Loading

0 comments on commit 68bd627

Please sign in to comment.