[Telemetry] Collect the correct exit code when user intentionally stops deployment (0 instead of 1)#5704
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the logging infrastructure to support configurable exit codes during fatal events. By introducing a new method that accepts an exit code, the system can now distinguish between critical errors and intentional, graceful terminations, improving the telemetry and logging behavior of the application. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new FatalWithCode function in the logging package to support specifying exit codes, allowing for graceful exits with code 0. The reviewer suggests renaming this function to ExitWithCode to better align with Go naming idioms, as 'Fatal' typically implies an error condition. Additionally, the feedback recommends updating the function's documentation to correctly reflect that it logs to standard output for success codes and standard error for others.
5803531
into
GoogleCloudPlatform:develop
Issue
When a user runs
gcluster deployand chooses to stop execution by selecting(s)at the prompt, the telemetry records an exit code of1instead of0. This incorrectly flags intentional, graceful terminations as application failures in the telemetry data.Root Cause
The issue arises because of how the "s" (stop) action is handled during the deployment prompt. When the user stops execution, the CLI invokes
logging.Fatal(). Thelogging.Fatal()automatically triggers theFatalHookhardcoded with an exit code of1. As a result, the tool treats this explicit user choice as a fatal application error.Solution
The solution is to rename the core
Fatallogic toExitWithCodeand make the existingFatala wrapper around it with an exit code1. Specifically, this PR:ExitWithCode(exitCode int, f string, a ...any)inpkg/logging/logging.goto support specifying exit codes. It also ensures that a success code (0) logs tostdoutviainfologinstead offatallog.ApplyChangesChoiceinpkg/shell/common.goto uselogging.ExitWithCode(0, ...)when the user selects "s".This allows the CLI to stop cleanly, triggering the
FatalHookwith an exit code of0and ensuring telemetry metrics accurately reflect user intent without breaking existingFatalcalls across the repository.