Skip to content

Commit

Permalink
Merge branch 'new_sdk/main' into mvg/new_sdk/move-temporality
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias authored Jul 14, 2022
2 parents 8fa7944 + 5f34247 commit 363de0e
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 126 deletions.
10 changes: 6 additions & 4 deletions sdk/metric/export/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ func (Sum) privateAggregation() {}

// DataPoint is a single data point in a timeseries.
type DataPoint struct {
// Attributes is the set of key value pairs that uniquely identify the timeseries.
Attributes []attribute.KeyValue
// Attributes is the set of key value pairs that uniquely identify the
// timeseries.
Attributes attribute.Set
// StartTime is when the timeseries was started. (optional)
StartTime time.Time
// Time is the time when the timeseries was recorded. (optional)
Expand Down Expand Up @@ -126,8 +127,9 @@ func (Histogram) privateAggregation() {}

// HistogramDataPoint is a single histogram data point in a timeseries.
type HistogramDataPoint struct {
// Attributes is the set of key value pairs that uniquely identify the timeseries.
Attributes []attribute.KeyValue
// Attributes is the set of key value pairs that uniquely identify the
// timeseries.
Attributes attribute.Set
// StartTime is when the timeseries was started.
StartTime time.Time
// Time is the time when the timeseries was recorded.
Expand Down
61 changes: 0 additions & 61 deletions sdk/metric/internal/aggregation.go

This file was deleted.

11 changes: 7 additions & 4 deletions sdk/metric/internal/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

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

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// Aggregator forms an aggregation from a collection of recorded measurements.
type Aggregator[N int64 | float64] interface {
// Aggregate records the measurement, scoped by attr, and aggregates it
// into an aggregation.
Aggregate(measurement N, attr attribute.Set)

// Aggregations returns a slice of Aggregation, one per each attribute set
// used to scope measurement aggregation, and ends an aggregation cycle.
Aggregations() []Aggregation
// Aggregation returns an Aggregation, for all the aggregated
// measurements made and ends an aggregation cycle.
Aggregation() export.Aggregation
}
12 changes: 6 additions & 6 deletions sdk/metric/internal/aggregator_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/export"
)

type meter struct {
// When a reader initiates a collection, the meter would collect
// aggregations from each of these functions. In this process they will
// progress the aggregation period of each instrument's aggregator.
aggregationFuncs []func() []Aggregation
// aggregations from each of these functions.
aggregations []export.Aggregation
}

func (m *meter) SyncInt64() syncint64.InstrumentProvider {
Expand All @@ -51,7 +51,7 @@ func (p *syncInt64Provider) Counter(string, ...instrument.Option) (syncint64.Cou
aggregator := NewCumulativeSum[int64]()
count := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for counter\n", aggregator)

Expand All @@ -69,7 +69,7 @@ func (p *syncInt64Provider) UpDownCounter(string, ...instrument.Option) (syncint
aggregator := NewLastValue[int64]()
upDownCount := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for up-down counter\n", aggregator)

Expand All @@ -89,7 +89,7 @@ func (p *syncInt64Provider) Histogram(string, ...instrument.Option) (syncint64.H
})
hist := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for histogram\n", aggregator)

Expand Down
5 changes: 3 additions & 2 deletions sdk/metric/internal/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// histogram summarizes a set of measurements as an histogram with
Expand Down Expand Up @@ -51,7 +52,7 @@ type deltaHistogram[N int64 | float64] struct {
// TODO(#2970): implement.
}

func (s *deltaHistogram[N]) Aggregations() []Aggregation {
func (s *deltaHistogram[N]) Aggregation() export.Aggregation {
// TODO(#2970): implement.
return nil
}
Expand All @@ -74,7 +75,7 @@ type cumulativeHistogram[N int64 | float64] struct {
// TODO(#2970): implement.
}

func (s *cumulativeHistogram[N]) Aggregations() []Aggregation {
func (s *cumulativeHistogram[N]) Aggregation() export.Aggregation {
// TODO(#2970): implement.
return nil
}
7 changes: 5 additions & 2 deletions sdk/metric/internal/lastvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

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

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// lastValue summarizes a set of measurements as the last one made.
type lastValue[N int64 | float64] struct {
Expand All @@ -34,7 +37,7 @@ func (s *lastValue[N]) Aggregate(value N, attr attribute.Set) {
// TODO(#2971): implement.
}

func (s *lastValue[N]) Aggregations() []Aggregation {
func (s *lastValue[N]) Aggregation() export.Aggregation {
// TODO(#2971): implement.
return nil
}
9 changes: 6 additions & 3 deletions sdk/metric/internal/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

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

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// sum summarizes a set of measurements as their arithmetic sum.
type sum[N int64 | float64] struct {
Expand Down Expand Up @@ -47,7 +50,7 @@ type deltaSum[N int64 | float64] struct {
// TODO(#2972): implement.
}

func (s *deltaSum[N]) Aggregations() []Aggregation {
func (s *deltaSum[N]) Aggregation() export.Aggregation {
// TODO(#2972): implement.
return nil
}
Expand All @@ -71,7 +74,7 @@ type cumulativeSum[N int64 | float64] struct {
// TODO(#2972): implement.
}

func (s *cumulativeSum[N]) Aggregations() []Aggregation {
func (s *cumulativeSum[N]) Aggregation() export.Aggregation {
// TODO(#2972): implement.
return nil
}
22 changes: 11 additions & 11 deletions sdk/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// meterRegistry keeps a record of initialized meters for instrumentation
// libraries. A meter is unique to an instrumentation library and if multiple
// scopes. A meter is unique to an instrumentation scope and if multiple
// requests for that meter are made a meterRegistry ensure the same instance
// is used.
//
Expand All @@ -43,31 +43,31 @@ import (
type meterRegistry struct {
sync.Mutex

meters map[instrumentation.Library]*meter
meters map[instrumentation.Scope]*meter
}

// Get returns a registered meter matching the instrumentation library if it
// Get returns a registered meter matching the instrumentation scope if it
// exists in the meterRegistry. Otherwise, a new meter configured for the
// instrumentation library is registered and then returned.
// instrumentation scope is registered and then returned.
//
// Get is safe to call concurrently.
func (r *meterRegistry) Get(l instrumentation.Library) *meter {
func (r *meterRegistry) Get(s instrumentation.Scope) *meter {
r.Lock()
defer r.Unlock()

if r.meters == nil {
m := &meter{Library: l}
r.meters = map[instrumentation.Library]*meter{l: m}
m := &meter{Scope: s}
r.meters = map[instrumentation.Scope]*meter{s: m}
return m
}

m, ok := r.meters[l]
m, ok := r.meters[s]
if ok {
return m
}

m = &meter{Library: l}
r.meters[l] = m
m = &meter{Scope: s}
r.meters[s] = m
return m
}

Expand All @@ -91,7 +91,7 @@ func (r *meterRegistry) Range(f func(*meter) bool) {
// produced by an instrumentation scope will use metric instruments from a
// single meter.
type meter struct {
instrumentation.Library
instrumentation.Scope

// TODO (#2815, 2814): implement.
}
Expand Down
16 changes: 8 additions & 8 deletions sdk/metric/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ import (
)

func TestMeterRegistry(t *testing.T) {
il0 := instrumentation.Library{Name: "zero"}
il1 := instrumentation.Library{Name: "one"}
is0 := instrumentation.Scope{Name: "zero"}
is1 := instrumentation.Scope{Name: "one"}

r := meterRegistry{}
var m0 *meter
t.Run("ZeroValueGetDoesNotPanic", func(t *testing.T) {
assert.NotPanics(t, func() { m0 = r.Get(il0) })
assert.Equal(t, il0, m0.Library, "uninitialized meter returned")
assert.NotPanics(t, func() { m0 = r.Get(is0) })
assert.Equal(t, is0, m0.Scope, "uninitialized meter returned")
})

m01 := r.Get(il0)
m01 := r.Get(is0)
t.Run("GetSameMeter", func(t *testing.T) {
assert.Samef(t, m0, m01, "returned different meters: %v", il0)
assert.Samef(t, m0, m01, "returned different meters: %v", is0)
})

m1 := r.Get(il1)
m1 := r.Get(is1)
t.Run("GetDifferentMeter", func(t *testing.T) {
assert.NotSamef(t, m0, m1, "returned same meters: %v", il1)
assert.NotSamef(t, m0, m1, "returned same meters: %v", is1)
})

t.Run("RangeComplete", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewMeterProvider(options ...Option) *MeterProvider {
// This method is safe to call concurrently.
func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metric.Meter {
c := metric.NewMeterConfig(options...)
return mp.meters.Get(instrumentation.Library{
return mp.meters.Get(instrumentation.Scope{
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/view/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// Instrument uniquely identifies an instrument within a meter.
type Instrument struct {
Scope instrumentation.Library
Scope instrumentation.Scope

Name string
Description string
Expand Down
Loading

0 comments on commit 363de0e

Please sign in to comment.