-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Global meter forwarding implementation #392
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0abb301
Initial skeleton
ad319fd
Revert noop provider removal
f5c4231
Checkpoint
d922887
Checkpoint
e6e77d3
Implement Bound instrument and LabelSet
a219f91
Add test
7656cae
Add a benchmark
a040c3c
Add a release test
81e9532
Document LabelSetDelegator
31ef9d3
Lint and comments
c401181
Add a second Meter test; fix typo; add a panic
8cf8fc4
Add a test for the builtin SDK
9b914f7
Upstream
e1ee73c
Address feedback
cc46d71
Upstream
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package internal_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"go.opentelemetry.io/otel/api/global" | ||
"go.opentelemetry.io/otel/api/global/internal" | ||
"go.opentelemetry.io/otel/api/key" | ||
"go.opentelemetry.io/otel/api/metric" | ||
export "go.opentelemetry.io/otel/sdk/export/metric" | ||
sdk "go.opentelemetry.io/otel/sdk/metric" | ||
"go.opentelemetry.io/otel/sdk/metric/aggregator/counter" | ||
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch" | ||
"go.opentelemetry.io/otel/sdk/metric/aggregator/gauge" | ||
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" | ||
) | ||
|
||
// benchFixture is copied from sdk/metric/benchmark_test.go. | ||
// TODO refactor to share this code. | ||
type benchFixture struct { | ||
sdk *sdk.SDK | ||
B *testing.B | ||
} | ||
|
||
var _ metric.Provider = &benchFixture{} | ||
|
||
func newFixture(b *testing.B) *benchFixture { | ||
b.ReportAllocs() | ||
bf := &benchFixture{ | ||
B: b, | ||
} | ||
bf.sdk = sdk.New(bf, sdk.NewDefaultLabelEncoder()) | ||
return bf | ||
} | ||
|
||
func (*benchFixture) AggregatorFor(descriptor *export.Descriptor) export.Aggregator { | ||
switch descriptor.MetricKind() { | ||
case export.CounterKind: | ||
return counter.New() | ||
case export.GaugeKind: | ||
return gauge.New() | ||
case export.MeasureKind: | ||
if strings.HasSuffix(descriptor.Name(), "minmaxsumcount") { | ||
return minmaxsumcount.New(descriptor) | ||
} else if strings.HasSuffix(descriptor.Name(), "ddsketch") { | ||
return ddsketch.New(ddsketch.NewDefaultConfig(), descriptor) | ||
} else if strings.HasSuffix(descriptor.Name(), "array") { | ||
return ddsketch.New(ddsketch.NewDefaultConfig(), descriptor) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (*benchFixture) Process(context.Context, export.Record) error { | ||
return nil | ||
} | ||
|
||
func (*benchFixture) CheckpointSet() export.CheckpointSet { | ||
return nil | ||
} | ||
|
||
func (*benchFixture) FinishedCollection() { | ||
} | ||
|
||
func (fix *benchFixture) Meter(name string) metric.Meter { | ||
return fix.sdk | ||
} | ||
|
||
func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { | ||
internal.ResetForTest() | ||
ctx := context.Background() | ||
sdk := global.MeterProvider().Meter("test") | ||
labs := sdk.Labels(key.String("A", "B")) | ||
cnt := sdk.NewInt64Counter("int64.counter") | ||
|
||
b.ResetTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
cnt.Add(ctx, 1, labs) | ||
} | ||
} | ||
|
||
func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { | ||
// Comapare with BenchmarkInt64CounterAdd() in ../../sdk/meter/benchmark_test.go | ||
ctx := context.Background() | ||
fix := newFixture(b) | ||
|
||
sdk := global.MeterProvider().Meter("test") | ||
|
||
global.SetMeterProvider(fix) | ||
|
||
labs := sdk.Labels(key.String("A", "B")) | ||
cnt := sdk.NewInt64Counter("int64.counter") | ||
|
||
b.ResetTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
cnt.Add(ctx, 1, labs) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:s/dewfault/default/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.