You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +02:00
Reuse memory in metric pipelines (#3760)
* Have pipelines reuse memory * truncate Metric slice * Apply suggestions from code review Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Use rm pool on periodic shutdown. * zero out RM on ctx error * Update sdk/metric/pipeline.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Peter Liu <lpfvip2008@gmail.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Fix lint --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Peter Liu <lpfvip2008@gmail.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
This commit is contained in:
@@ -103,10 +103,11 @@ func (ts *readerTestSuite) TestMultipleForceFlush() {
|
||||
|
||||
func (ts *readerTestSuite) TestMultipleRegister() {
|
||||
p0 := testSDKProducer{
|
||||
produceFunc: func(ctx context.Context) (metricdata.ResourceMetrics, error) {
|
||||
produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
||||
// Differentiate this producer from the second by returning an
|
||||
// error.
|
||||
return testResourceMetricsA, assert.AnError
|
||||
*rm = testResourceMetricsA
|
||||
return assert.AnError
|
||||
},
|
||||
}
|
||||
p1 := testSDKProducer{}
|
||||
@@ -144,8 +145,9 @@ func (ts *readerTestSuite) TestExternalProducerPartialSuccess() {
|
||||
|
||||
func (ts *readerTestSuite) TestSDKFailureBlocksExternalProducer() {
|
||||
ts.Reader.register(testSDKProducer{
|
||||
produceFunc: func(ctx context.Context) (metricdata.ResourceMetrics, error) {
|
||||
return metricdata.ResourceMetrics{}, assert.AnError
|
||||
produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
||||
*rm = metricdata.ResourceMetrics{}
|
||||
return assert.AnError
|
||||
}})
|
||||
ts.Reader.RegisterProducer(testExternalProducer{})
|
||||
|
||||
@@ -252,14 +254,15 @@ var testResourceMetricsAB = metricdata.ResourceMetrics{
|
||||
}
|
||||
|
||||
type testSDKProducer struct {
|
||||
produceFunc func(context.Context) (metricdata.ResourceMetrics, error)
|
||||
produceFunc func(context.Context, *metricdata.ResourceMetrics) error
|
||||
}
|
||||
|
||||
func (p testSDKProducer) produce(ctx context.Context) (metricdata.ResourceMetrics, error) {
|
||||
func (p testSDKProducer) produce(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
||||
if p.produceFunc != nil {
|
||||
return p.produceFunc(ctx)
|
||||
return p.produceFunc(ctx, rm)
|
||||
}
|
||||
return testResourceMetricsA, nil
|
||||
*rm = testResourceMetricsA
|
||||
return nil
|
||||
}
|
||||
|
||||
type testExternalProducer struct {
|
||||
|
||||
Reference in New Issue
Block a user