Skip to content

fix: correct error messages in workloadMetricHandler and connectionMe…#1662

Open
sahanaxzy wants to merge 1 commit intokmesh-net:mainfrom
sahanaxzy:fix/wrong-error-messages
Open

fix: correct error messages in workloadMetricHandler and connectionMe…#1662
sahanaxzy wants to merge 1 commit intokmesh-net:mainfrom
sahanaxzy:fix/wrong-error-messages

Conversation

@sahanaxzy
Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
This fixes a small copy-paste error in status_server.go. The workloadMetricHandler and connectionMetricHandler were returning "invalid accesslog enable=..." when passed a bad enable value, instead of their respective handler names. This updates the error strings to say "invalid workload_metrics" and "invalid connection_metrics".

Which issue(s) this PR fixes:
Fixes #1660

Special notes for your reviewer:
none

Does this PR introduce a user-facing change?:

NONE

…tricHandler

Signed-off-by: sahanaxzy <kbsahana2007@gmail.com>
Copilot AI review requested due to automatic review settings April 30, 2026 11:41
@kmesh-bot kmesh-bot added the kind/bug Something isn't working label Apr 30, 2026
@kmesh-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign okabe-rintarou-0 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link
Copy Markdown

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 addresses a copy-paste error in the status server implementation. By correcting the error strings returned when invalid parameters are provided, the API now provides accurate feedback to users, improving debuggability and consistency.

Highlights

  • Error Message Correction: Updated error messages in workloadMetricHandler and connectionMetricHandler to correctly reflect the handler names instead of an incorrect reference to accesslog.
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 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 counter productive. 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.


A copy-paste error was found, where labels were wrongly unbound. The metrics were named, the error was blamed, now clarity finally is found.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect copy/paste error strings returned by the status server when enable cannot be parsed for workload/connection metrics endpoints (aligning the error message with the handler/endpoint actually used), addressing #1660.

Changes:

  • Update workloadMetricHandler parse error message to invalid workload_metrics enable=...
  • Update connectionMetricHandler parse error message to invalid connection_metrics enable=...

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 285 to 288
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid workload_metrics enable=%s", info)))
return
Comment on lines 308 to 311
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid connection_metrics enable=%s", info)))
return
Copy link
Copy Markdown

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

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 updates error messages in the workload and connection metric handlers to correctly identify the metrics being toggled. The review feedback highlights a security concern regarding Reflected Cross-Site Scripting (XSS) because user-provided input is returned in the response without an explicit Content-Type. It is recommended to use http.Error to safely handle these errors and maintain consistency with other parts of the codebase.

Comment on lines 286 to +287
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid workload_metrics enable=%s", info)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The error message reflects the info query parameter without setting a proper Content-Type. This can lead to Reflected Cross-Site Scripting (XSS) if the response is rendered in a browser. Using http.Error is safer as it sets the Content-Type to text/plain; charset=utf-8 and X-Content-Type-Options: nosniff. Additionally, it is more consistent with the error handling used later in this function (e.g., line 292).

Suggested change
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid workload_metrics enable=%s", info)))
http.Error(w, fmt.Sprintf("invalid workload_metrics enable=%s", info), http.StatusBadRequest)

Comment on lines 309 to +310
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid connection_metrics enable=%s", info)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The error message reflects the info query parameter without setting a proper Content-Type, posing a Reflected XSS risk. Using http.Error mitigates this by ensuring the response is treated as plain text. This also aligns with the error handling used elsewhere in this handler (e.g., lines 315 and 324).

Suggested change
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("invalid accesslog enable=%s", info)))
_, _ = w.Write([]byte(fmt.Sprintf("invalid connection_metrics enable=%s", info)))
http.Error(w, fmt.Sprintf("invalid connection_metrics enable=%s", info), http.StatusBadRequest)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.52%. Comparing base (e78a0a6) to head (a8f401e).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
pkg/status/status_server.go 0.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Files with missing lines Coverage Δ
pkg/status/status_server.go 35.81% <0.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa3035c...a8f401e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: wrong error messages in workload_metrics and connection_metrics handlers

3 participants