Skip to content

Commit

Permalink
Improve readers Collect docs (#4361)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Jul 26, 2023
1 parent d423bd4 commit e557e74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
4 changes: 2 additions & 2 deletions sdk/metric/manual_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (mr *ManualReader) Shutdown(context.Context) error {
return err
}

// Collect gathers all metrics from the SDK and other Producers, calling any
// callbacks necessary and stores the result in rm.
// Collect gathers all metric data related to the Reader from
// the SDK and other Producers and stores the result in rm.
//
// Collect will return an error if called after shutdown.
// Collect will return an error if rm is a nil ResourceMetrics.
Expand Down
24 changes: 9 additions & 15 deletions sdk/metric/manual_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,18 @@ func TestManualReaderCollect(t *testing.T) {
defer cancel()

tests := []struct {
name string

ctx context.Context
resourceMetrics *metricdata.ResourceMetrics

name string
ctx context.Context
expectedErr error
}{
{
name: "with a valid context",

ctx: context.Background(),
resourceMetrics: &metricdata.ResourceMetrics{},
name: "with a valid context",
ctx: context.Background(),
expectedErr: nil,
},
{
name: "with an expired context",

ctx: expiredCtx,
resourceMetrics: &metricdata.ResourceMetrics{},

name: "with an expired context",
ctx: expiredCtx,
expectedErr: context.DeadlineExceeded,
},
}
Expand All @@ -117,7 +110,8 @@ func TestManualReaderCollect(t *testing.T) {
}, testM)
assert.NoError(t, err)

assert.Equal(t, tt.expectedErr, rdr.Collect(tt.ctx, tt.resourceMetrics))
rm := &metricdata.ResourceMetrics{}
assert.Equal(t, tt.expectedErr, rdr.Collect(tt.ctx, rm))
})
}
}
4 changes: 2 additions & 2 deletions sdk/metric/periodic_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ func (r *PeriodicReader) collectAndExport(ctx context.Context) error {
return err
}

// Collect gathers and returns all metric data related to the Reader from
// the SDK and other Producers and stores the result in rm. The returned metric
// Collect gathers all metric data related to the Reader from
// the SDK and other Producers and stores the result in rm. The metric
// data is not exported to the configured exporter, it is left to the caller to
// handle that if desired.
//
Expand Down
24 changes: 9 additions & 15 deletions sdk/metric/periodic_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,25 +424,18 @@ func TestPeriodicReaderCollect(t *testing.T) {
defer cancel()

tests := []struct {
name string

ctx context.Context
resourceMetrics *metricdata.ResourceMetrics

name string
ctx context.Context
expectedErr error
}{
{
name: "with a valid context",

ctx: context.Background(),
resourceMetrics: &metricdata.ResourceMetrics{},
name: "with a valid context",
ctx: context.Background(),
expectedErr: nil,
},
{
name: "with an expired context",

ctx: expiredCtx,
resourceMetrics: &metricdata.ResourceMetrics{},

name: "with an expired context",
ctx: expiredCtx,
expectedErr: context.DeadlineExceeded,
},
}
Expand All @@ -461,7 +454,8 @@ func TestPeriodicReaderCollect(t *testing.T) {
}, testM)
assert.NoError(t, err)

assert.Equal(t, tt.expectedErr, rdr.Collect(tt.ctx, tt.resourceMetrics))
rm := &metricdata.ResourceMetrics{}
assert.Equal(t, tt.expectedErr, rdr.Collect(tt.ctx, rm))
})
}
}

0 comments on commit e557e74

Please sign in to comment.