Skip to content

Commit 208460a

Browse files
authored
[POA-3519] Report telemetry observation window start and duration (#111)
These changes will report the observation window start and duration. The observation window resets every time we send a telemetry report. These new values will help us calculate averages more precisely without flattening them over a long observation session. Additionally the window start time will help us build better rollup windows. TODO: - [x] pull in `api_schema` changes in postmanlabs/observability-shared-libs#232
1 parent d10435e commit 208460a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

apidump/apidump.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,13 @@ func isBpfFilterError(e error) bool {
282282
}
283283

284284
// Update the backend with new current capture stats.
285-
func (a *apidump) SendPacketTelemetry(observedDuration int) {
285+
func (a *apidump) SendPacketTelemetry(observationDuration int, windowStartTime time.Time, windowDuration int) {
286286
req := &kgxapi.PostClientPacketCaptureStatsRequest{
287-
AgentResourceUsage: usage.Get(),
288-
ObservedDurationInSeconds: observedDuration,
289-
AgentRateLimit: a.WitnessesPerMinute,
287+
AgentResourceUsage: usage.Get(),
288+
ObservedDurationInSeconds: observationDuration,
289+
ObservedWindowStartingAt: windowStartTime,
290+
ObservedWindowDurationInSeconds: windowDuration,
291+
AgentRateLimit: a.WitnessesPerMinute,
290292
}
291293
if a.dumpSummary != nil {
292294
req.PacketCountSummary = a.dumpSummary.FilterSummary.Summary(topNForSummary)
@@ -470,18 +472,25 @@ func (a *apidump) TelemetryWorker(done <-chan struct{}) {
470472
if a.TelemetryInterval > 0 {
471473
ticker := time.NewTicker(time.Duration(a.TelemetryInterval) * time.Second)
472474

475+
lastReport := time.Now()
473476
for {
474477
select {
475478
case <-done:
476479
return
477480
case now := <-ticker.C:
478-
duration := int(now.Sub(a.startTime) / time.Second)
479-
a.SendPacketTelemetry(duration)
481+
observationDuration := int(now.Sub(a.startTime) / time.Second)
482+
windowStart := lastReport
483+
windowDuration := int(now.Sub(windowStart) / time.Second)
484+
lastReport = time.Now()
485+
a.SendPacketTelemetry(observationDuration, windowStart, windowDuration)
480486
subsequentTelemetrySent = true
481487
case <-a.successTelemetry.Channel:
482488
if !subsequentTelemetrySent {
483-
duration := int(time.Since(a.startTime) / time.Second)
484-
a.SendPacketTelemetry(duration)
489+
observationDuration := int(time.Since(a.startTime) / time.Second)
490+
windowStart := lastReport
491+
windowDuration := int(time.Since(windowStart) / time.Second)
492+
lastReport = time.Now()
493+
a.SendPacketTelemetry(observationDuration, windowStart, windowDuration)
485494
}
486495
}
487496
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/OneOfOne/xxhash v1.2.8
88
github.com/Pallinder/go-randomdata v1.2.0
99
github.com/akitasoftware/akita-ir v0.0.0-20241213050034-057d7b6097e8
10-
github.com/akitasoftware/akita-libs v0.0.0-20250430223533-06e05e3725df
10+
github.com/akitasoftware/akita-libs v0.0.0-20250505211512-67888a517c64
1111
github.com/akitasoftware/go-utils v0.0.0-20240213133309-b95d4ace8803
1212
github.com/andybalholm/brotli v1.0.1
1313
github.com/aws/aws-sdk-go-v2 v1.17.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ github.com/akitasoftware/akita-libs v0.0.0-20250428180153-cb2e977a2ee3 h1:ANLqfV
3636
github.com/akitasoftware/akita-libs v0.0.0-20250428180153-cb2e977a2ee3/go.mod h1:Fg14kX6+N7we3KdP1c11W/SzbKsgapV1hP5d4Z/Hqwc=
3737
github.com/akitasoftware/akita-libs v0.0.0-20250430223533-06e05e3725df h1:NLeQdXerlr1FOXvVgwrYpAat2UeIFKyb+AmRlOz2otQ=
3838
github.com/akitasoftware/akita-libs v0.0.0-20250430223533-06e05e3725df/go.mod h1:Fg14kX6+N7we3KdP1c11W/SzbKsgapV1hP5d4Z/Hqwc=
39+
github.com/akitasoftware/akita-libs v0.0.0-20250505211512-67888a517c64 h1:DYjWUWnXOwvuMle72HdQokPDGtzs4cfHLsKHBfnGHiI=
40+
github.com/akitasoftware/akita-libs v0.0.0-20250505211512-67888a517c64/go.mod h1:Fg14kX6+N7we3KdP1c11W/SzbKsgapV1hP5d4Z/Hqwc=
3941
github.com/akitasoftware/go-utils v0.0.0-20240213133309-b95d4ace8803 h1:ebIh/EFuaP8GczzMe8EwVID/blSv5Tej6S8NE4xyarQ=
4042
github.com/akitasoftware/go-utils v0.0.0-20240213133309-b95d4ace8803/go.mod h1:+IOXf7l/QCAQECJzjJwhTp1sBkRoJ6WciZwJezUwBa4=
4143
github.com/akitasoftware/gopacket v1.1.18-0.20240820200020-7289ae956f70 h1:VnU7QLDBwRujpQoHwShs5yu0Ahv1fSalNJa4UijwlmY=

0 commit comments

Comments
 (0)