Skip to content

Commit

Permalink
fix: [NPM] close telemetry handler before crashing (#3333)
Browse files Browse the repository at this point in the history
fix: close telemetry handler before crashing

Signed-off-by: Hunter Gregory <[email protected]>
  • Loading branch information
huntergregory authored Jan 8, 2025
1 parent 4dac095 commit 1296fd7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion npm/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func newStartNPMCmd() *cobra.Command {
KubeConfigPath: viper.GetString(flagKubeConfigPath),
}

return start(*config, flags)
// start is blocking, unless there's an error
err = start(*config, flags)
metrics.Close()
return err
},
}

Expand Down
11 changes: 11 additions & 0 deletions npm/metrics/ai-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"k8s.io/klog"
)

const telemetryCloseWaitTimeSeconds = 10

var (
th aitelemetry.TelemetryHandle
npmVersion int
Expand Down Expand Up @@ -54,6 +56,15 @@ func CreateTelemetryHandle(npmVersionNum int, imageVersion, aiMetadata string) e
return nil
}

// Close cleans up the telemetry handle, which effectively waits for all telemetry data to be sent
func Close() {
if th == nil {
return
}

th.Close(telemetryCloseWaitTimeSeconds)
}

// SendErrorLogAndMetric sends a metric through AI telemetry and sends a log to the Kusto Messages table
func SendErrorLogAndMetric(operationID int, format string, args ...interface{}) {
// Send error metrics
Expand Down
1 change: 1 addition & 0 deletions npm/pkg/dataplane/ipsets/ipsetmanager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func (iMgr *IPSetManager) applyIPSets() error {
msg := fmt.Sprintf("exceeded max consecutive failures (%d) when applying ipsets. final error: %s", maxConsecutiveFailures, restoreError.Error())
klog.Error(msg)
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
metrics.Close()
panic(msg)
}

Expand Down

0 comments on commit 1296fd7

Please sign in to comment.