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

Stagger timestamps in exact aggregator tests #1569

Merged
merged 7 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Rename MaxEventsPerSpan, MaxAttributesPerSpan and MaxLinksPerSpan to EventCountLimit, AttributeCountLimit and LinkCountLimit, and move these fieds into SpanLimits. (#1535)
- Renamed the `otel/label` package to `otel/attribute`. (#1541)
- Vendor the Jaeger exporter's dependency on Apache Thrift. (#1551)
- Stagger timestamps in exact aggregator tests. (#1569)

### Added

Expand Down
24 changes: 20 additions & 4 deletions sdk/metric/aggregator/exact/exact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) {
for i := 0; i < ut.count; i++ {
x := profile.Random(+1)
all.Append(x)
advance()
aggregatortest.CheckedUpdate(t, agg, x, descriptor)

y := profile.Random(-1)
all.Append(y)
advance()
aggregatortest.CheckedUpdate(t, agg, y, descriptor)
}

Expand Down Expand Up @@ -117,6 +119,10 @@ type mergeTest struct {
absolute bool
}

func advance() {
time.Sleep(time.Nanosecond)
}

func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
agg1, agg2, ckpt1, ckpt2 := new4()
Expand All @@ -126,19 +132,23 @@ func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) {
for i := 0; i < mt.count; i++ {
x1 := profile.Random(+1)
all.Append(x1)
advance()
aggregatortest.CheckedUpdate(t, agg1, x1, descriptor)

x2 := profile.Random(+1)
all.Append(x2)
advance()
aggregatortest.CheckedUpdate(t, agg2, x2, descriptor)

if !mt.absolute {
y1 := profile.Random(-1)
all.Append(y1)
advance()
aggregatortest.CheckedUpdate(t, agg1, y1, descriptor)

y2 := profile.Random(-1)
all.Append(y2)
advance()
aggregatortest.CheckedUpdate(t, agg2, y2, descriptor)
}
}
Expand All @@ -159,7 +169,7 @@ func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) {
received.Append(s.Number)

if i > 0 {
require.False(t, pts[i-1].Time.After(pts[i].Time))
require.True(t, pts[i-1].Time.Before(pts[i].Time))
}
}

Expand Down Expand Up @@ -202,9 +212,11 @@ func TestExactErrors(t *testing.T) {

descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)

advance()
aggregatortest.CheckedUpdate(t, agg, number.Number(0), descriptor)

if profile.NumberKind == number.Float64Kind {
advance()
aggregatortest.CheckedUpdate(t, agg, number.NewFloat64Number(math.NaN()), descriptor)
}
require.NoError(t, agg.SynchronizedMove(ckpt, descriptor))
Expand Down Expand Up @@ -253,11 +265,13 @@ func TestExactFloat64(t *testing.T) {

for _, f := range fpsf(1) {
all.Append(number.NewFloat64Number(f))
advance()
aggregatortest.CheckedUpdate(t, agg, number.NewFloat64Number(f), descriptor)
}

for _, f := range fpsf(-1) {
all.Append(number.NewFloat64Number(f))
advance()
aggregatortest.CheckedUpdate(t, agg, number.NewFloat64Number(f), descriptor)
}

Expand All @@ -282,11 +296,11 @@ func TestExactFloat64(t *testing.T) {
for i := 0; i < len(po); i++ {
require.Equal(t, all.Points()[i], po[i].Number, "Wrong point at position %d", i)
if i > 0 {
require.False(t, po[i-1].Time.After(po[i].Time))
require.True(t, po[i-1].Time.Before(po[i].Time))
}
}
require.False(t, po[0].Time.Before(startTime))
require.False(t, po[len(po)-1].Time.After(endTime))
require.True(t, po[0].Time.After(startTime))
require.True(t, po[len(po)-1].Time.Before(endTime))
}

func TestSynchronizedMoveReset(t *testing.T) {
Expand All @@ -311,12 +325,14 @@ func TestMergeBehavior(t *testing.T) {
for i := 0; i < 100; i++ {
x1 := profile.Random(+1)
all.Append(x1)
advance()
aggregatortest.CheckedUpdate(t, agg1, x1, descriptor)
}

for i := 0; i < 100; i++ {
x2 := profile.Random(+1)
all.Append(x2)
advance()
aggregatortest.CheckedUpdate(t, agg2, x2, descriptor)
}

Expand Down
6 changes: 4 additions & 2 deletions sdk/metric/processor/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ func TestBasicInconsistent(t *testing.T) {

func TestBasicTimestamps(t *testing.T) {
beforeNew := time.Now()
time.Sleep(time.Nanosecond)
b := basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector())
time.Sleep(time.Nanosecond)
afterNew := time.Now()

desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind)
Expand All @@ -335,8 +337,8 @@ func TestBasicTimestamps(t *testing.T) {
}))

// The first start time is set in the constructor.
require.False(t, beforeNew.After(start1))
require.False(t, afterNew.Before(start1))
require.True(t, beforeNew.Before(start1))
require.True(t, afterNew.After(start1))

for i := 0; i < 2; i++ {
b.StartCollection()
Expand Down