Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(telemetry): record silent error #1585

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func dailyComponentUpdateAvailable(componentName string) (bool, error) {
err := versionCache.StoreCache(cacheFile)

if err != nil {
cli.Event.Error = err.Error()
cli.Event.FeatureData = map[string]interface{}{"silent_error": err.Error()}
return false, err
}

Expand All @@ -193,12 +193,40 @@ func dailyComponentUpdateAvailable(componentName string) (bool, error) {
}
}

func firstTimeVersionCheck(dir, file string) error {
var (
err error
currentVersion *lwupdater.Version
)
defer func() {
cli.Event.Feature = featDailyVerCheck
if err != nil {
cli.Event.FeatureData = map[string]interface{}{"silent_error": err.Error()}
}
cli.SendHoneyvent()
}()
Comment on lines +201 to +207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the CLI always stay running long enough for this to send? Looks like the daily check is called in the post-execution of the root command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. We have workers in place to wait for this. https://github.com/lacework/go-sdk/blob/main/cli/cmd/honeyvent.go#L115-L124

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!


if err = os.MkdirAll(dir, 0755); err != nil {
return err
}

currentVersion, err = versionCheck()
if err != nil {
return err
}

cli.Log.Debugw("storing version cache", "content", currentVersion)
err = currentVersion.StoreCache(file)
return err
}

// dailyVersionCheck will execute a version check on a daily basis, the function uses
// the file ~/.config/lacework/version_cache to track the last check time
func dailyVersionCheck() error {
if cli.JSONOutput() || !isCheckEnabled() {
return nil
}

cacheDir, err := cache.CacheDir()
if err != nil {
return err
Expand All @@ -207,19 +235,7 @@ func dailyVersionCheck() error {
cacheFile := path.Join(cacheDir, VersionCacheFile)
if !file.FileExists(cacheFile) {
// first time running the daily version check, create directory
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return err
}

currentVersion, err := versionCheck()
if err != nil {
return err
}

cli.Log.Debugw("storing version cache", "content", currentVersion)
if err := currentVersion.StoreCache(cacheFile); err != nil {
return err
}
return firstTimeVersionCheck(cacheDir, cacheFile)
}

cli.Log.Debugw("verifying cached version", "cache_file", cacheFile)
Expand All @@ -244,17 +260,17 @@ func dailyVersionCheck() error {
cli.Log.Debugw("storing new version cache", "content", versionCache)
err := versionCache.StoreCache(cacheFile)
if err != nil {
cli.Event.Error = err.Error()
cli.Event.FeatureData = map[string]interface{}{"silent_error": err.Error()}
return err
}

lwv, err := versionCheck()
cli.Event.DurationMs = time.Since(nowTime).Milliseconds()
if err != nil {
cli.Event.Error = err.Error()
cli.Event.FeatureData = map[string]interface{}{"silent_error": err.Error()}
return err
}

cli.Event.DurationMs = time.Since(nowTime).Milliseconds()
cli.Event.FeatureData = lwv
return nil
}
Expand Down
Loading