From 039e88049b1f72d4eca10491acf33d710f28da2b Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Sun, 6 Sep 2020 20:57:38 -0700 Subject: [PATCH] Add option to control metrics bundling to speed up tests. --- ocagent.go | 10 ++++++++-- options.go | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ocagent.go b/ocagent.go index f08f8a4..aa0dd31 100644 --- a/ocagent.go +++ b/ocagent.go @@ -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 @@ -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) } @@ -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 { diff --git a/options.go b/options.go index ed53022..148a564 100644 --- a/options.go +++ b/options.go @@ -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 }