Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Add option to control metrics bundling #89

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ocagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type Exporter struct {
// Please do not confuse it with metricsBundler!
viewDataBundler *bundler.Bundler

// Bundler configuration options managed by viewDataBundler
viewDataDelay time.Duration
viewDataBundleCount int

clientTransportCredentials credentials.TransportCredentials

grpcDialOptions []grpc.DialOption
Expand All @@ -112,6 +116,8 @@ const spanDataBufferSize = 300

func NewUnstartedExporter(opts ...ExporterOption) (*Exporter, error) {
e := new(Exporter)
e.viewDataDelay = 2 * time.Second
e.viewDataBundleCount = 500
for _, opt := range opts {
opt.withExporter(e)
}
Expand All @@ -125,8 +131,8 @@ func NewUnstartedExporter(opts ...ExporterOption) (*Exporter, error) {
viewDataBundler := bundler.NewBundler((*view.Data)(nil), func(bundle interface{}) {
e.uploadViewData(bundle.([]*view.Data))
})
viewDataBundler.DelayThreshold = 2 * time.Second
viewDataBundler.BundleCountThreshold = 500 // TODO: (@odeke-em) make this configurable.
viewDataBundler.DelayThreshold = e.viewDataDelay
viewDataBundler.BundleCountThreshold = e.viewDataBundleCount
e.viewDataBundler = viewDataBundler
e.nodeInfo = NodeWithStartTime(e.serviceName)
if e.resourceDetector != nil {
Expand Down
21 changes: 21 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ func WithMetricNamePrefix(prefix string) ExporterOption {
return metricNamePrefixSetter(prefix)
}

type dataBundlerOptions struct {
delay time.Duration
count int
}

var _ ExporterOption = (*dataBundlerOptions)(nil)

func (b dataBundlerOptions) withExporter(e *Exporter) {
if b.delay > 0 {
e.viewDataDelay = b.delay
}
if b.count > 0 {
e.viewDataBundleCount = b.count
}
}

// WithDataBundlerOptions provides an option for the caller to configure the metrics data bundler.
func WithDataBundlerOptions(delay time.Duration, count int) ExporterOption {
return dataBundlerOptions{delay, count}
}

func (spanConfig SpanConfig) withExporter(e *Exporter) {
e.spanConfig = spanConfig
}
Expand Down