Skip to content

Commit

Permalink
Merge branch 'main' into dep-otlp-internal
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 8, 2023
2 parents ca2e3bb + 6631519 commit 4c7e314
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
12 changes: 5 additions & 7 deletions exporters/otlp/otlpmetric/internal/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
ctx := context.Background()

done := make(chan struct{})
first := make(chan struct{}, goroutines)
var wg sync.WaitGroup
var wg, someWork sync.WaitGroup
for i := 0; i < goroutines; i++ {
wg.Add(1)
someWork.Add(1)
go func() {
defer wg.Done()
assert.NoError(t, exp.Export(ctx, rm))
assert.NoError(t, exp.ForceFlush(ctx))

// Ensure some work is done before shutting down.
first <- struct{}{}
someWork.Done()

for {
_ = exp.Export(ctx, rm)
Expand All @@ -88,10 +89,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
}()
}

for i := 0; i < goroutines; i++ {
<-first
}
close(first)
someWork.Wait()
assert.NoError(t, exp.Shutdown(ctx))
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)

Expand Down
12 changes: 5 additions & 7 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
rm := new(metricdata.ResourceMetrics)

done := make(chan struct{})
first := make(chan struct{}, goroutines)
var wg sync.WaitGroup
var wg, someWork sync.WaitGroup
for i := 0; i < goroutines; i++ {
wg.Add(1)
someWork.Add(1)
go func() {
defer wg.Done()
assert.NoError(t, exp.Export(ctx, rm))
assert.NoError(t, exp.ForceFlush(ctx))

// Ensure some work is done before shutting down.
first <- struct{}{}
someWork.Done()

for {
_ = exp.Export(ctx, rm)
Expand All @@ -71,10 +72,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
}()
}

for i := 0; i < goroutines; i++ {
<-first
}
close(first)
someWork.Wait()
assert.NoError(t, exp.Shutdown(ctx))
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)

Expand Down
12 changes: 5 additions & 7 deletions exporters/otlp/otlpmetric/otlpmetrichttp/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
rm := new(metricdata.ResourceMetrics)

done := make(chan struct{})
first := make(chan struct{}, goroutines)
var wg sync.WaitGroup
var wg, someWork sync.WaitGroup
for i := 0; i < goroutines; i++ {
wg.Add(1)
someWork.Add(1)
go func() {
defer wg.Done()
assert.NoError(t, exp.Export(ctx, rm))
assert.NoError(t, exp.ForceFlush(ctx))

// Ensure some work is done before shutting down.
first <- struct{}{}
someWork.Done()

for {
_ = exp.Export(ctx, rm)
Expand All @@ -71,10 +72,7 @@ func TestExporterClientConcurrentSafe(t *testing.T) {
}()
}

for i := 0; i < goroutines; i++ {
<-first
}
close(first)
someWork.Wait()
assert.NoError(t, exp.Shutdown(ctx))
assert.ErrorIs(t, exp.Shutdown(ctx), errShutdown)

Expand Down
2 changes: 2 additions & 0 deletions metric/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (o unitOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64Ob
}

// WithUnit sets the instrument unit.
//
// The unit u should be defined using the appropriate [UCUM](https://ucum.org) case-sensitive code.
func WithUnit(u string) InstrumentOption { return unitOpt(u) }

// AddOption applies options to an addition measurement. See
Expand Down
8 changes: 4 additions & 4 deletions sdk/metric/periodic_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
return nil
}})
r.RegisterProducer(testExternalProducer{})
assert.Equal(t, context.DeadlineExceeded, r.ForceFlush(context.Background()), "timeout error not returned")
assert.ErrorIs(t, r.ForceFlush(context.Background()), context.DeadlineExceeded)
assert.False(t, *called, "exporter Export method called when it should have failed before export")

// Ensure Reader is allowed clean up attempt.
Expand All @@ -368,7 +368,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
return []metricdata.ScopeMetrics{testScopeMetricsA}, nil
},
})
assert.Equal(t, context.DeadlineExceeded, r.ForceFlush(context.Background()), "timeout error not returned")
assert.ErrorIs(t, r.ForceFlush(context.Background()), context.DeadlineExceeded)
assert.False(t, *called, "exporter Export method called when it should have failed before export")

// Ensure Reader is allowed clean up attempt.
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
return nil
}})
r.RegisterProducer(testExternalProducer{})
assert.Equal(t, context.DeadlineExceeded, r.Shutdown(context.Background()), "timeout error not returned")
assert.ErrorIs(t, r.Shutdown(context.Background()), context.DeadlineExceeded)
assert.False(t, *called, "exporter Export method called when it should have failed before export")
})

Expand All @@ -420,7 +420,7 @@ func TestPeriodicReaderFlushesPending(t *testing.T) {
return []metricdata.ScopeMetrics{testScopeMetricsA}, nil
},
})
assert.Equal(t, context.DeadlineExceeded, r.Shutdown(context.Background()), "timeout error not returned")
assert.ErrorIs(t, r.Shutdown(context.Background()), context.DeadlineExceeded)
assert.False(t, *called, "exporter Export method called when it should have failed before export")
})
}
Expand Down

0 comments on commit 4c7e314

Please sign in to comment.