Skip to content

Commit

Permalink
Merge branch 'main' into gustavo.prom_with_namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Apr 5, 2023
2 parents 027c13c + 02fa1e2 commit 0976db2
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thumbs.db
*.iml
*.so
coverage.*
go.work

gen/

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `TracerProvider` allows calling `Tracer()` while it's shutting down.
It used to deadlock. (#3924)
- Use the SDK version for the Telemetry SDK resource detector in `go.opentelemetry.io/otel/sdk/resource`. (#3949)
- Automatically figure out the default aggregation with `aggregation.Default`. (#3967)

## [1.15.0-rc.2/0.38.0-rc.2] 2023-03-23

Expand Down
4 changes: 2 additions & 2 deletions attribute/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (l *Set) Len() int {

// Get returns the KeyValue at ordered position idx in this set.
func (l *Set) Get(idx int) (KeyValue, bool) {
if l == nil {
if l == nil || !l.equivalent.Valid() {
return KeyValue{}, false
}
value := l.equivalent.reflectValue()
Expand All @@ -114,7 +114,7 @@ func (l *Set) Get(idx int) (KeyValue, bool) {

// Value returns the value of a specified key in this set.
func (l *Set) Value(k Key) (Value, bool) {
if l == nil {
if l == nil || !l.equivalent.Valid() {
return Value{}, false
}
rValue := l.equivalent.reflectValue()
Expand Down
37 changes: 37 additions & 0 deletions attribute/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package attribute_test

import (
"reflect"
"regexp"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -188,3 +190,38 @@ func TestLookup(t *testing.T) {
_, has = set.Value("D")
require.False(t, has)
}

func TestZeroSetExportedMethodsNoPanic(t *testing.T) {
rType := reflect.TypeOf((*attribute.Set)(nil))
rVal := reflect.ValueOf(&attribute.Set{})
for n := 0; n < rType.NumMethod(); n++ {
mType := rType.Method(n)
if !mType.IsExported() {
t.Logf("ignoring unexported %s", mType.Name)
continue
}
t.Run(mType.Name, func(t *testing.T) {
m := rVal.MethodByName(mType.Name)
if !m.IsValid() {
t.Errorf("unknown method: %s", mType.Name)
}
assert.NotPanics(t, func() { _ = m.Call(args(mType)) })
})
}
}

func args(m reflect.Method) []reflect.Value {
numIn := m.Type.NumIn() - 1 // Do not include the receiver arg.
if numIn <= 0 {
return nil
}
if m.Type.IsVariadic() {
numIn--
}
out := make([]reflect.Value, numIn)
for i := range out {
aType := m.Type.In(i + 1) // Skip receiver arg.
out[i] = reflect.New(aType).Elem()
}
return out
}
4 changes: 4 additions & 0 deletions sdk/metric/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ func (i *inserter[N]) streamID(kind InstrumentKind, stream Stream) streamID {
// returned.
func (i *inserter[N]) aggregator(agg aggregation.Aggregation, kind InstrumentKind, temporality metricdata.Temporality, monotonic bool) (internal.Aggregator[N], error) {
switch a := agg.(type) {
case aggregation.Default:
return i.aggregator(DefaultAggregationSelector(kind), kind, temporality, monotonic)
case aggregation.Drop:
return nil, nil
case aggregation.LastValue:
Expand Down Expand Up @@ -444,6 +446,8 @@ func (i *inserter[N]) aggregator(agg aggregation.Aggregation, kind InstrumentKin
// | Observable Gauge | X | X | | | |.
func isAggregatorCompatible(kind InstrumentKind, agg aggregation.Aggregation) error {
switch agg.(type) {
case aggregation.Default:
return nil
case aggregation.ExplicitBucketHistogram:
if kind == InstrumentKindCounter || kind == InstrumentKindHistogram {
return nil
Expand Down
57 changes: 46 additions & 11 deletions sdk/metric/pipeline_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,52 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
wantLen: 2,
},
{
name: "reader with invalid aggregation should error",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindCounter],
wantErr: errCreatingAggregators,
name: "reader with default aggregation should figure out a Counter",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindCounter],
wantKind: internal.NewCumulativeSum[N](true),
wantLen: 1,
},
{
name: "reader with default aggregation should figure out an UpDownCounter",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindUpDownCounter],
wantKind: internal.NewCumulativeSum[N](true),
wantLen: 1,
},
{
name: "reader with default aggregation should figure out an Histogram",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindHistogram],
wantKind: internal.NewCumulativeHistogram[N](aggregation.ExplicitBucketHistogram{}),
wantLen: 1,
},
{
name: "reader with default aggregation should figure out an ObservableCounter",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindObservableCounter],
wantKind: internal.NewPrecomputedCumulativeSum[N](true),
wantLen: 1,
},
{
name: "reader with default aggregation should figure out an ObservableUpDownCounter",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindObservableUpDownCounter],
wantKind: internal.NewPrecomputedCumulativeSum[N](true),
wantLen: 1,
},
{
name: "reader with default aggregation should figure out an ObservableGauge",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) aggregation.Aggregation { return aggregation.Default{} })),
views: []View{defaultView},
inst: instruments[InstrumentKindObservableGauge],
wantKind: internal.NewLastValue[N](),
wantLen: 1,
},
{
name: "view with invalid aggregation should error",
Expand Down Expand Up @@ -594,12 +635,6 @@ func TestIsAggregatorCompatible(t *testing.T) {
agg: aggregation.ExplicitBucketHistogram{},
want: errIncompatibleAggregation,
},
{
name: "Default aggregation should error",
kind: InstrumentKindCounter,
agg: aggregation.Default{},
want: errUnknownAggregation,
},
{
name: "unknown kind with Sum should error",
kind: undefinedInstrument,
Expand Down

0 comments on commit 0976db2

Please sign in to comment.