Skip to content

[Telemetry] Collect the correct exit code when user intentionally stops deployment (0 instead of 1)#5704

Merged
kadupoornima merged 3 commits into
GoogleCloudPlatform:developfrom
kadupoornima:tel-fix-exit-code
May 26, 2026
Merged

[Telemetry] Collect the correct exit code when user intentionally stops deployment (0 instead of 1)#5704
kadupoornima merged 3 commits into
GoogleCloudPlatform:developfrom
kadupoornima:tel-fix-exit-code

Conversation

@kadupoornima

@kadupoornima kadupoornima commented May 25, 2026

Copy link
Copy Markdown
Contributor

Issue
When a user runs gcluster deploy and chooses to stop execution by selecting (s) at the prompt, the telemetry records an exit code of 1 instead of 0. 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(). The logging.Fatal() automatically triggers the FatalHook hardcoded with an exit code of 1. As a result, the tool treats this explicit user choice as a fatal application error.

Solution
The solution is to rename the core Fatal logic to ExitWithCode and make the existing Fatal a wrapper around it with an exit code 1. Specifically, this PR:

  1. Introduces ExitWithCode(exitCode int, f string, a ...any) in pkg/logging/logging.go to support specifying exit codes. It also ensures that a success code (0) logs to stdout via infolog instead of fatallog.
  2. Updates ApplyChangesChoice in pkg/shell/common.go to use logging.ExitWithCode(0, ...) when the user selects "s".

This allows the CLI to stop cleanly, triggering the FatalHook with an exit code of 0 and ensuring telemetry metrics accurately reflect user intent without breaking existing Fatal calls across the repository.

@kadupoornima kadupoornima requested a review from a team as a code owner May 25, 2026 12:39
@kadupoornima kadupoornima added the release-bugfix Added to release notes under the "Bug fixes" heading. label May 25, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Logging Enhancement: Introduced FatalWithCode to allow flexible exit codes when logging fatal events.
  • Graceful Exit Support: Updated logging logic to support exit code 0, which now routes messages to the info log instead of the fatal log.
  • Shell Interaction Update: Modified shell execution to use FatalWithCode(0) when a user chooses to stop execution, ensuring a clean exit.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread pkg/logging/logging.go Outdated
Comment thread pkg/logging/logging.go Outdated
Comment thread pkg/shell/common.go Outdated
@kadupoornima kadupoornima changed the title [Telemetry] [Telemetry] Collect the correct exit code when user intentionally stops deployment (0 instead of 1) May 25, 2026
@kadupoornima kadupoornima enabled auto-merge (squash) May 26, 2026 04:47
Comment thread pkg/logging/logging.go
@saara-tyagi27 saara-tyagi27 self-requested a review May 26, 2026 10:21
@kadupoornima kadupoornima merged commit 5803531 into GoogleCloudPlatform:develop May 26, 2026
14 of 76 checks passed
@kadupoornima kadupoornima deleted the tel-fix-exit-code branch May 27, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-bugfix Added to release notes under the "Bug fixes" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants