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 all 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
30 changes: 25 additions & 5 deletions sdk/metric/aggregator/exact/exact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type updateTest struct {
count int
}

func requireNotAfter(t *testing.T, t1, t2 time.Time) {
require.False(t, t1.After(t2), "expected %v ≤ %v", t1, t2)
}

func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) {
count, err := agg.Count()
require.NoError(t, err)
Expand Down Expand Up @@ -70,10 +74,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 +123,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 +136,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 +173,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))
requireNotAfter(t, pts[i-1].Time, pts[i].Time)
}
}

Expand Down Expand Up @@ -202,9 +216,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 +269,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 +300,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))
requireNotAfter(t, po[i-1].Time, po[i].Time)
}
}
require.False(t, po[0].Time.Before(startTime))
require.False(t, po[len(po)-1].Time.After(endTime))
requireNotAfter(t, startTime, po[0].Time)
requireNotAfter(t, po[len(po)-1].Time, endTime)
}

func TestSynchronizedMoveReset(t *testing.T) {
Expand All @@ -311,12 +329,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 All @@ -336,7 +356,7 @@ func TestMergeBehavior(t *testing.T) {
received.Append(s.Number)

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

Expand Down
18 changes: 12 additions & 6 deletions sdk/metric/processor/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
)

func requireNotAfter(t *testing.T, t1, t2 time.Time) {
require.False(t, t1.After(t2), "expected %v ≤ %v", t1, t2)
}

// TestProcessor tests all the non-error paths in this package.
func TestProcessor(t *testing.T) {
type exportCase struct {
Expand Down Expand Up @@ -316,7 +320,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 +341,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))
requireNotAfter(t, beforeNew, start1)
requireNotAfter(t, start1, afterNew)

for i := 0; i < 2; i++ {
b.StartCollection()
Expand All @@ -353,8 +359,8 @@ func TestBasicTimestamps(t *testing.T) {

// Subsequent intervals have their start and end aligned.
require.Equal(t, start2, end1)
require.True(t, start1.Before(end1))
require.True(t, start2.Before(end2))
requireNotAfter(t, start1, end1)
requireNotAfter(t, start2, end2)

start1 = start2
end1 = end2
Expand Down Expand Up @@ -514,6 +520,6 @@ func TestSumObserverEndToEnd(t *testing.T) {

require.Equal(t, startTime[0], startTime[1])
require.Equal(t, startTime[0], startTime[2])
require.True(t, endTime[0].Before(endTime[1]))
require.True(t, endTime[1].Before(endTime[2]))
requireNotAfter(t, endTime[0], endTime[1])
requireNotAfter(t, endTime[1], endTime[2])
}