Skip to content

Commit

Permalink
config: Add support to configure periodic reader interval and timeout (
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandrutu authored May 28, 2024
1 parent cc2e3c0 commit 6e36a40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- The `go.opentelemetry.io/contrib/config` add support to configure periodic reader interval and timeout. (#5661)

### Deprecated

- The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` package is deprecated.
Expand Down
10 changes: 9 additions & 1 deletion config/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ func metricReader(ctx context.Context, r MetricReader) (sdkmetric.Reader, error)
}

if r.Periodic != nil {
return periodicExporter(ctx, r.Periodic.Exporter)
var opts []sdkmetric.PeriodicReaderOption
if r.Periodic.Interval != nil {
opts = append(opts, sdkmetric.WithInterval(time.Duration(*r.Periodic.Interval)*time.Millisecond))
}

if r.Periodic.Timeout != nil {
opts = append(opts, sdkmetric.WithTimeout(time.Duration(*r.Periodic.Timeout)*time.Millisecond))
}
return periodicExporter(ctx, r.Periodic.Exporter, opts...)
}

if r.Pull != nil {
Expand Down
22 changes: 22 additions & 0 deletions config/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -450,6 +451,23 @@ func TestReader(t *testing.T) {
},
wantReader: sdkmetric.NewPeriodicReader(consoleExporter),
},
{
name: "periodic/console-exporter-with-extra-options",
reader: MetricReader{
Periodic: &PeriodicMetricReader{
Interval: newIntPtr(30_000),
Timeout: newIntPtr(5_000),
Exporter: MetricExporter{
Console: Console{},
},
},
},
wantReader: sdkmetric.NewPeriodicReader(
consoleExporter,
sdkmetric.WithInterval(30_000*time.Millisecond),
sdkmetric.WithTimeout(5_000*time.Millisecond),
),
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -476,3 +494,7 @@ func TestReader(t *testing.T) {
})
}
}

func newIntPtr(i int) *int {
return &i
}

0 comments on commit 6e36a40

Please sign in to comment.