@@ -17,7 +17,6 @@ import (
1717 kgxapi "github.com/akitasoftware/akita-libs/api_schema"
1818 "github.com/akitasoftware/akita-libs/buffer_pool"
1919 "github.com/akitasoftware/akita-libs/tags"
20- "github.com/akitasoftware/go-utils/math"
2120 "github.com/akitasoftware/go-utils/optionals"
2221 "github.com/pkg/errors"
2322 "github.com/postmanlabs/postman-insights-agent/apispec"
@@ -116,9 +115,6 @@ type Args struct {
116115 // How often to rotate learn sessions; set to zero to disable rotation.
117116 LearnSessionLifetime time.Duration
118117
119- // Print packet capture statistics after N seconds.
120- StatsLogDelay int
121-
122118 // Periodically report telemetry every N seconds thereafter
123119 TelemetryInterval int
124120
@@ -153,15 +149,20 @@ type apidump struct {
153149 backendSvcName string
154150 learnClient rest.LearnClient
155151
156- startTime time.Time
157- dumpSummary * Summary
152+ startTime time.Time
153+ dumpSummary * Summary
154+ successTelemetry * trace.SuccessTelemetry
158155}
159156
160157// Start a new apidump session based on the given arguments.
161158func newSession (args * Args ) * apidump {
162159 a := & apidump {
163160 Args : args ,
164161 startTime : time .Now (),
162+ successTelemetry : & trace.SuccessTelemetry {
163+ Channel : make (chan struct {}),
164+ Once : sync.Once {},
165+ },
165166 }
166167 return a
167168}
@@ -200,7 +201,7 @@ func (a *apidump) LookupService() error {
200201 return nil
201202}
202203
203- // Send the initial mesage to the backend indicating successful start
204+ // Send the initial message to the backend indicating successful start
204205func (a * apidump ) SendInitialTelemetry () {
205206 // Do not send packet capture telemetry for local captures.
206207 if ! a .TargetIsRemote () {
@@ -209,11 +210,11 @@ func (a *apidump) SendInitialTelemetry() {
209210
210211 // XXX(cns): The observed duration serves as a key for upserting packet
211212 // telemetry, so it needs to be the same here as in the packet
212- // telemetry sent sixty seconds after startup.
213+ // telemetry sent 5 minutes after startup.
213214 req := kgxapi.PostInitialClientTelemetryRequest {
214215 ClientID : a .ClientID ,
215216 ObservedStartingAt : a .startTime ,
216- ObservedDurationInSeconds : a .StatsLogDelay ,
217+ ObservedDurationInSeconds : a .TelemetryInterval ,
217218 SendsWitnessPayloads : a .ReproMode ,
218219 CLIVersion : version .ReleaseVersion ().String (),
219220 CLITargetArch : architecture .GetCanonicalArch (),
@@ -234,7 +235,7 @@ func (a *apidump) SendInitialTelemetry() {
234235// Send a message to the backend indicating failure to start and a cause
235236func (a * apidump ) SendErrorTelemetry (errorType api_schema.ApidumpErrorType , err error ) {
236237 req := & kgxapi.PostClientPacketCaptureStatsRequest {
237- ObservedDurationInSeconds : a .StatsLogDelay ,
238+ ObservedDurationInSeconds : a .TelemetryInterval ,
238239 ApidumpError : errorType ,
239240 ApidumpErrorText : err .Error (),
240241 }
@@ -414,31 +415,16 @@ func (a *apidump) RotateLearnSession(done <-chan struct{}, collectors []trace.Le
414415
415416// Goroutine to send telemetry, stop when "done" is closed.
416417//
417- // Prints a summary after a short delay. This ensures that statistics will
418- // appear in customer logs close to when the process is started.
419- // Omits if args.StatsLogDelay is <= 0.
420- //
421418// Sends telemetry to the server on a regular basis.
422419// Omits if args.TelemetryInterval is <= 0
423420func (a * apidump ) TelemetryWorker (done <- chan struct {}) {
424- if a .StatsLogDelay <= 0 && a . TelemetryInterval <= 0 {
421+ if a .TelemetryInterval <= 0 {
425422 return
426423 }
427424
428425 a .SendInitialTelemetry ()
429426
430- if a .StatsLogDelay > 0 {
431- // Wait while capturing statistics.
432- time .Sleep (time .Duration (a .StatsLogDelay ) * time .Second )
433-
434- // Print telemetry data.
435- printer .Stderr .Infof ("Printing packet capture statistics after %d seconds of capture.\n " , a .StatsLogDelay )
436- a .dumpSummary .PrintPacketCounts ()
437- a .dumpSummary .PrintWarnings ()
438-
439- a .SendPacketTelemetry (a .StatsLogDelay )
440- }
441-
427+ subsequentTelemetrySent := false
442428 if a .TelemetryInterval > 0 {
443429 ticker := time .NewTicker (time .Duration (a .TelemetryInterval ) * time .Second )
444430
@@ -449,6 +435,11 @@ func (a *apidump) TelemetryWorker(done <-chan struct{}) {
449435 case now := <- ticker .C :
450436 duration := int (now .Sub (a .startTime ) / time .Second )
451437 a .SendPacketTelemetry (duration )
438+ subsequentTelemetrySent = true
439+ case <- a .successTelemetry .Channel :
440+ if ! subsequentTelemetrySent {
441+ a .SendPacketTelemetry (a .TelemetryInterval )
442+ }
452443 }
453444 }
454445 }
@@ -641,15 +632,8 @@ func (a *apidump) Run() error {
641632 // when the main collection process does.
642633 if a .TargetIsRemote () {
643634 {
644- // Record the first resource usage data slightly before the
645- // stats log delay to ensure we include usage data in the first
646- // telemetry upload.
647- var delay time.Duration
648- if 0 < a .StatsLogDelay {
649- delay = time .Duration (math .Max (a .StatsLogDelay - 5 , 1 )) * time .Second
650- }
651-
652- go usage .Poll (stop , delay , time .Duration (a .ProcFSPollingInterval )* time .Second )
635+ // Record the first usage immediately (sending delay = 0) since we want to include it in the success telemetry
636+ go usage .Poll (stop , 0 , time .Duration (a .ProcFSPollingInterval )* time .Second )
653637 }
654638
655639 go a .TelemetryWorker (stop )
@@ -724,8 +708,9 @@ func (a *apidump) Run() error {
724708 // trace is empty or not.) In the future we could add columns for both
725709 // pre- and post-filtering.
726710 collector = & trace.PacketCountCollector {
727- PacketCounts : summary ,
728- Collector : collector ,
711+ PacketCounts : summary ,
712+ Collector : collector ,
713+ SuccessTelemetry : a .successTelemetry ,
729714 }
730715
731716 // Subsampling.
0 commit comments