@@ -93,7 +93,34 @@ class PeriodSnapshotAccumulatorSpec extends WordSpec with Reconfigure with Instr
93
93
accumulator.add(fiveSecondsSeven) shouldBe empty // second 0:35
94
94
}
95
95
96
+ " not align snapshot when optimistic tick alignment is false" in {
97
+ // When the kamon.metric.optimistic-tick-alignment is false
98
+ // If accumulating over 11 seconds, the snapshots should be generated at 00:00:11, 00:00:22, 00:00:33 and so on.
99
+ // Thus the snapshot next tick is never aligned
100
+ applyConfig(" kamon.metric.optimistic-tick-alignment = no" )
101
+
102
+ val accumulator = newAccumulator(11 , 0 )
103
+ // as the first add snapshot.to determines the first ticker use zero second
104
+ // to send snapshot at the seconds that are multiples of the duration
105
+ accumulator.add(zeroSecond) shouldBe empty // second 0:0
106
+ accumulator.add(fiveSecondsOne) shouldBe empty // second 0:5
107
+ accumulator.add(fiveSecondsTwo) shouldBe empty // second 0:10
108
+
109
+ val s15 = accumulator.add(fiveSecondsThree).value // second 0:15
110
+ s15.from shouldBe(zeroSecond.from)
111
+ s15.to shouldBe(fiveSecondsThree.to)
112
+
113
+ accumulator.add(fiveSecondsFour) shouldBe empty // second 0:20
114
+ val s25 = accumulator.add(fiveSecondsFive).value // second 0:25
115
+ s25.from shouldBe(fiveSecondsFour.from)
116
+ s25.to shouldBe(fiveSecondsFive.to)
117
+
118
+ accumulator.add(fiveSecondsSix) shouldBe empty // second 0:30
119
+ }
120
+
96
121
" do best effort to align when snapshots themselves are not aligned" in {
122
+ applyConfig(" kamon.metric.optimistic-tick-alignment = yes" )
123
+
97
124
val accumulator = newAccumulator(30 , 0 )
98
125
accumulator.add(tenSecondsOne) shouldBe empty // second 0:13
99
126
accumulator.add(tenSecondsTwo) shouldBe empty // second 0:23
@@ -139,6 +166,8 @@ class PeriodSnapshotAccumulatorSpec extends WordSpec with Reconfigure with Instr
139
166
}
140
167
141
168
" produce a snapshot when enough data has been accumulated" in {
169
+ applyConfig(" kamon.metric.optimistic-tick-alignment = yes" )
170
+
142
171
val accumulator = newAccumulator(15 , 1 )
143
172
accumulator.add(fiveSecondsOne) shouldBe empty
144
173
accumulator.add(fiveSecondsTwo) shouldBe empty
@@ -167,6 +196,8 @@ class PeriodSnapshotAccumulatorSpec extends WordSpec with Reconfigure with Instr
167
196
val alignedZeroTime = Clock .nextAlignedInstant(Kamon .clock().instant(), Duration .ofSeconds(60 )).minusSeconds(60 )
168
197
val unAlignedZeroTime = alignedZeroTime.plusSeconds(3 )
169
198
199
+ val zeroSecond = createPeriodSnapshot(alignedZeroTime, alignedZeroTime, 13 )
200
+
170
201
// Aligned snapshots, every 5 seconds from second 00.
171
202
val fiveSecondsOne = createPeriodSnapshot(alignedZeroTime, alignedZeroTime.plusSeconds(5 ), 22 )
172
203
val fiveSecondsTwo = createPeriodSnapshot(alignedZeroTime.plusSeconds(5 ), alignedZeroTime.plusSeconds(10 ), 33 )
@@ -221,6 +252,7 @@ class PeriodSnapshotAccumulatorSpec extends WordSpec with Reconfigure with Instr
221
252
)
222
253
223
254
override protected def beforeAll (): Unit = {
255
+ applyConfig(" kamon.metric.optimistic-tick-alignment = yes" )
224
256
applyConfig(" kamon.metric.tick-interval = 10 seconds" )
225
257
}
226
258
}
0 commit comments