Skip to content

Commit

Permalink
add support for periodic reader interval/timeout (#8096)
Browse files Browse the repository at this point in the history
This adds support for configuring `timeout` and `interval` options for
the periodic metric exporter.

Linked issue: #7641

Signed-off-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
Alex Boten committed Jul 17, 2023
1 parent 7996c45 commit 8949d1d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .chloggen/codeboten_add-periodic-internal-timeout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add support for `interval` and `timeout` configuration in periodic reader"

# One or more tracking issues or pull requests related to the change
issues: [7641]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
15 changes: 12 additions & 3 deletions service/internal/proctelemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/http"
"os"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -56,7 +57,15 @@ func InitMetricReader(ctx context.Context, reader telemetry.MetricReader, asyncE
return initPullExporter(reader.Pull.Exporter, asyncErrorChannel)
}
if reader.Periodic != nil {
return initPeriodicExporter(ctx, reader.Periodic.Exporter)
opts := []sdkmetric.PeriodicReaderOption{}
if reader.Periodic.Interval != nil {
opts = append(opts, sdkmetric.WithInterval(time.Duration(*reader.Periodic.Interval)*time.Millisecond))
}

if reader.Periodic.Timeout != nil {
opts = append(opts, sdkmetric.WithTimeout(time.Duration(*reader.Periodic.Timeout)*time.Millisecond))
}
return initPeriodicExporter(ctx, reader.Periodic.Exporter, opts...)
}
return nil, nil, fmt.Errorf("unsupported metric reader type %v", reader)
}
Expand Down Expand Up @@ -160,7 +169,7 @@ func initPullExporter(exporter telemetry.MetricExporter, asyncErrorChannel chan
}
return nil, nil, fmt.Errorf("no valid exporter")
}
func initPeriodicExporter(_ context.Context, exporter telemetry.MetricExporter) (sdkmetric.Reader, *http.Server, error) {
func initPeriodicExporter(_ context.Context, exporter telemetry.MetricExporter, opts ...sdkmetric.PeriodicReaderOption) (sdkmetric.Reader, *http.Server, error) {
if exporter.Console != nil {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
Expand All @@ -171,7 +180,7 @@ func initPeriodicExporter(_ context.Context, exporter telemetry.MetricExporter)
if err != nil {
return nil, nil, err
}
return sdkmetric.NewPeriodicReader(exp), nil, nil
return sdkmetric.NewPeriodicReader(exp, opts...), nil, nil
}
return nil, nil, fmt.Errorf("no valid exporter")
}
12 changes: 12 additions & 0 deletions service/internal/proctelemetry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ func TestMetricReader(t *testing.T) {
},
},
},
{
name: "periodic/console-exporter-with-timeout-interval",
reader: telemetry.MetricReader{
Periodic: &telemetry.PeriodicMetricReader{
Interval: intPtr(10),
Timeout: intPtr(5),
Exporter: telemetry.MetricExporter{
Console: telemetry.Console{},
},
},
},
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8949d1d

Please sign in to comment.