Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Making stackdriver exporter options configurable in env var #990

Merged
merged 5 commits into from
Sep 16, 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
14 changes: 14 additions & 0 deletions pkg/observability/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// Package observability sets up and configures observability tools.
package observability

import "time"

// ExporterType represents a type of observability exporter.
type ExporterType string

Expand Down Expand Up @@ -60,4 +62,16 @@ type StackdriverConfig struct {
// Allows for providing a real Google Cloud location when running locally for development.
// This is ignored if a real location was found during discovery.
LocationOverride string `env:"DEV_STACKDRIVER_LOCATION"`

// The following options are mostly for tuning the metrics reporting
// behavior. You normally should not change these values.
// ReportingInterval: should be >=60s as stackdriver enforces 60s minimal
// interval.
// BundleDelayThreshold / BundleCountThreshold: the stackdriver exporter
// uses https://google.golang.org/api/support/bundler, these two options
// control the max delay/count for batching the data points into one
// stackdriver request.
ReportingInterval time.Duration `env:"STACKDRIVER_REPORTING_INTERVAL, default=2m"`
BundleDelayThreshold time.Duration `env:"STACKDRIVER_BUNDLE_DELAY_THRESHOLD, default=2s"`
BundleCountThreshold uint `env:"STACKDRIVER_BUNDLE_COUNT_THRESHOLD, default=50"`
}
12 changes: 4 additions & 8 deletions pkg/observability/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package observability
import (
"context"
"fmt"
"time"

"github.com/google/exposure-notifications-server/pkg/logging"

Expand All @@ -27,11 +26,7 @@ import (
"go.opencensus.io/trace"
)

var (
_ Exporter = (*stackdriverExporter)(nil)

SDExportFrequency = time.Minute * 2
)
var _ Exporter = (*stackdriverExporter)(nil)

type stackdriverExporter struct {
exporter *stackdriver.Exporter
Expand All @@ -53,7 +48,9 @@ func NewStackdriver(ctx context.Context, config *StackdriverConfig) (Exporter, e
exporter, err := stackdriver.NewExporter(stackdriver.Options{
Context: ctx,
ProjectID: projectID,
ReportingInterval: SDExportFrequency,
ReportingInterval: config.ReportingInterval,
BundleDelayThreshold: config.BundleDelayThreshold,
BundleCountThreshold: int(config.BundleCountThreshold),
MonitoredResource: monitoredResource,
DefaultMonitoringLabels: &stackdriver.Labels{},
OnError: func(err error) {
Expand Down Expand Up @@ -83,7 +80,6 @@ func (e *stackdriverExporter) StartExporter() error {
trace.RegisterExporter(e.exporter)

view.RegisterExporter(e.exporter)
view.SetReportingPeriod(SDExportFrequency)

return nil
}
Expand Down