Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an Inmemory Exporter for test #2776

Merged
merged 14 commits into from Apr 24, 2022
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -16,7 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Added an in-memory exporter to metrictest to aid testing with a full SDK (#2776)
- Added an in-memory exporter to metrictest to aid testing with a full SDK. (#2776)

## [0.29.0] - 2022-04-11

Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/metrictest/config.go
Expand Up @@ -43,8 +43,8 @@ func (f functionOption) apply(cfg config) config {

// WithTemporalitySelector allows for the use of either cumulative (default) or
// delta metrics.

// Warning the current SDK does not convert async instruments into delta
//
// Warning: the current SDK does not convert async instruments into delta
// temporality.
func WithTemporalitySelector(ts aggregation.TemporalitySelector) Option {
return functionOption(func(cfg config) config {
Expand Down
6 changes: 3 additions & 3 deletions sdk/metric/metrictest/exporter.go
Expand Up @@ -140,7 +140,7 @@ func (e *Exporter) Collect(ctx context.Context) error {

// GetRecords returns all Records found by the SDK.
func (e *Exporter) GetRecords() []ExportRecord {
return e.Records[:]
return e.Records
}

var errNotFound = fmt.Errorf("record not found")
Expand All @@ -155,7 +155,7 @@ func (e *Exporter) GetByName(name string) (ExportRecord, error) {
return ExportRecord{}, errNotFound
}

// GetByNameAndAttributes returns the first Record with a matching name and set of Attributes.
// GetByNameAndAttributes returns the first Record with a matching name and the sub-set of attributes.
func (e *Exporter) GetByNameAndAttributes(name string, attributes []attribute.KeyValue) (ExportRecord, error) {
for _, rec := range e.Records {
if rec.InstrumentName == name && subSet(attributes, rec.Attributes) {
Expand All @@ -165,7 +165,7 @@ func (e *Exporter) GetByNameAndAttributes(name string, attributes []attribute.Ke
return ExportRecord{}, errNotFound
}

// subSet returns true if A is a subset of B
// subSet returns true if attributesA is a subset of attributesB.
func subSet(attributesA, attributesB []attribute.KeyValue) bool {
b := attribute.NewSet(attributesB...)

Expand Down
5 changes: 2 additions & 3 deletions sdk/metric/metrictest/exporter_test.go
Expand Up @@ -40,10 +40,10 @@ func TestSyncInstruments(t *testing.T) {
fcnt.Add(ctx, 2)

err = exp.Collect(context.Background())
assert.NoError(t, err)
requrie.NoError(t, err)
MrAlias marked this conversation as resolved.
Show resolved Hide resolved

out, err := exp.GetByName("fCount")
assert.NoError(t, err)
require.NoError(t, err)
assert.InDelta(t, 2.0, out.Sum.AsFloat64(), 0.0001)
assert.Equal(t, aggregation.SumKind, out.AggregationKind)
})
Expand Down Expand Up @@ -421,5 +421,4 @@ func ExampleExporter_GetByNameAndAttributes() {

fmt.Println(out.Sum.AsFloat64())
// Output: 4

}