Skip to content

Commit 1296fd7

Browse files
fix: [NPM] close telemetry handler before crashing (#3333)
fix: close telemetry handler before crashing Signed-off-by: Hunter Gregory <[email protected]>
1 parent 4dac095 commit 1296fd7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

npm/cmd/start.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func newStartNPMCmd() *cobra.Command {
5757
KubeConfigPath: viper.GetString(flagKubeConfigPath),
5858
}
5959

60-
return start(*config, flags)
60+
// start is blocking, unless there's an error
61+
err = start(*config, flags)
62+
metrics.Close()
63+
return err
6164
},
6265
}
6366

npm/metrics/ai-utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"k8s.io/klog"
1212
)
1313

14+
const telemetryCloseWaitTimeSeconds = 10
15+
1416
var (
1517
th aitelemetry.TelemetryHandle
1618
npmVersion int
@@ -54,6 +56,15 @@ func CreateTelemetryHandle(npmVersionNum int, imageVersion, aiMetadata string) e
5456
return nil
5557
}
5658

59+
// Close cleans up the telemetry handle, which effectively waits for all telemetry data to be sent
60+
func Close() {
61+
if th == nil {
62+
return
63+
}
64+
65+
th.Close(telemetryCloseWaitTimeSeconds)
66+
}
67+
5768
// SendErrorLogAndMetric sends a metric through AI telemetry and sends a log to the Kusto Messages table
5869
func SendErrorLogAndMetric(operationID int, format string, args ...interface{}) {
5970
// Send error metrics

npm/pkg/dataplane/ipsets/ipsetmanager_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func (iMgr *IPSetManager) applyIPSets() error {
422422
msg := fmt.Sprintf("exceeded max consecutive failures (%d) when applying ipsets. final error: %s", maxConsecutiveFailures, restoreError.Error())
423423
klog.Error(msg)
424424
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
425+
metrics.Close()
425426
panic(msg)
426427
}
427428

0 commit comments

Comments
 (0)