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

Commit 2f26a5d

Browse files
author
Ramon Nogueira
authored
Do not use zero defaults for bundle delays (#34)
We were previously not checking for unset (zero) values in Options before overriding the bundle delays in the bundler for the stats portion of the exporter. Change this to only set the delays if the values in the Options struct are non-zero, similar to what we do for the trace exporter.
1 parent f7f5758 commit 2f26a5d

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

stackdriver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func NewExporter(o Options) (*Exporter, error) {
207207
o.Resource = convertMonitoredResourceToPB(o.MonitoredResource)
208208
}
209209

210-
se, err := newStatsExporter(o, true)
210+
se, err := newStatsExporter(o)
211211
if err != nil {
212212
return nil, err
213213
}

stats.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var (
7272
// newStatsExporter returns an exporter that uploads stats data to Stackdriver Monitoring.
7373
// Only one Stackdriver exporter should be created per ProjectID per process, any subsequent
7474
// invocations of NewExporter with the same ProjectID will return an error.
75-
func newStatsExporter(o Options, enforceProjectUniqueness bool) (*statsExporter, error) {
75+
func newStatsExporter(o Options) (*statsExporter, error) {
7676
if strings.TrimSpace(o.ProjectID) == "" {
7777
return nil, errBlankProjectID
7878
}
@@ -98,8 +98,12 @@ func newStatsExporter(o Options, enforceProjectUniqueness bool) (*statsExporter,
9898
vds := bundle.([]*view.Data)
9999
e.handleUpload(vds...)
100100
})
101-
e.bundler.DelayThreshold = e.o.BundleDelayThreshold
102-
e.bundler.BundleCountThreshold = e.o.BundleCountThreshold
101+
if e.o.BundleDelayThreshold > 0 {
102+
e.bundler.DelayThreshold = e.o.BundleDelayThreshold
103+
}
104+
if e.o.BundleCountThreshold > 0 {
105+
e.bundler.BundleCountThreshold = e.o.BundleCountThreshold
106+
}
103107
return e, nil
104108
}
105109

@@ -113,8 +117,6 @@ func (e *statsExporter) ExportView(vd *view.Data) {
113117
switch err {
114118
case nil:
115119
return
116-
case bundler.ErrOversizedItem:
117-
go e.handleUpload(vd)
118120
case bundler.ErrOverflow:
119121
e.o.handleError(errors.New("failed to upload: buffer full"))
120122
default:

stats_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestRejectBlankProjectID(t *testing.T) {
4242
ids := []string{"", " ", " "}
4343
for _, projectID := range ids {
4444
opts := Options{ProjectID: projectID, MonitoringClientOptions: authOptions}
45-
exp, err := newStatsExporter(opts, false)
45+
exp, err := newStatsExporter(opts)
4646
if err == nil || exp != nil {
4747
t.Errorf("%q ProjectID must be rejected: NewExporter() = %v err = %q", projectID, exp, err)
4848
}
@@ -341,7 +341,7 @@ func TestExporter_makeReq(t *testing.T) {
341341
}
342342
for _, tt := range tests {
343343
t.Run(tt.name, func(t *testing.T) {
344-
e, err := newStatsExporter(Options{ProjectID: tt.projID, MonitoringClientOptions: authOptions}, false)
344+
e, err := newStatsExporter(Options{ProjectID: tt.projID, MonitoringClientOptions: authOptions})
345345
if err != nil {
346346
t.Fatal(err)
347347
}
@@ -568,7 +568,7 @@ func TestEqualAggWindowTagKeys(t *testing.T) {
568568
wantErr: false,
569569
},
570570
}
571-
e, err := newStatsExporter(Options{ProjectID: "opencensus-test", MonitoringClientOptions: authOptions}, false)
571+
e, err := newStatsExporter(Options{ProjectID: "opencensus-test", MonitoringClientOptions: authOptions})
572572
if err != nil {
573573
t.Fatal(err)
574574
}
@@ -634,7 +634,7 @@ func TestExporter_createMeasure(t *testing.T) {
634634
opts := tt.opts
635635
opts.MonitoringClientOptions = authOptions
636636
opts.ProjectID = "test_project"
637-
e, err := newStatsExporter(opts, false)
637+
e, err := newStatsExporter(opts)
638638
if err != nil {
639639
t.Fatal(err)
640640
}
@@ -997,7 +997,7 @@ func TestExporter_makeReq_withCustomMonitoredResource(t *testing.T) {
997997
opts := tt.opts
998998
opts.MonitoringClientOptions = authOptions
999999
opts.ProjectID = "proj-id"
1000-
e, err := newStatsExporter(opts, false)
1000+
e, err := newStatsExporter(opts)
10011001
if err != nil {
10021002
t.Fatal(err)
10031003
}

0 commit comments

Comments
 (0)