Skip to content

fix: add validation for malformed headers in metrics module and add unit tests #383

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

Closed
wants to merge 9 commits into from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

This PR addresses issues identified in PR #333:

  1. Adds validation for malformed headers in the metrics module to prevent potential panics
  2. Adds unit tests for the header functionality

Link to Devin run: https://app.devin.ai/sessions/3d6fd518f5a5497cb18d40cbfdb321e6
Requested by: maxence@formance.com

@devin-ai-integration devin-ai-integration bot requested a review from a team as a code owner April 5, 2025 15:10
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: maxence@formance.com <maxence@formance.com>
@flemzord
Copy link
Member

flemzord commented Apr 5, 2025

@coderabbitai review

headersMap := make(map[string]string)
for _, header := range otelMetricsExporterOTLPHeaders {
parts := strings.SplitN(header, "=", 2)
if len(parts) == 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle the case where len(parts) == 1

Co-Authored-By: maxence@formance.com <maxence@formance.com>
if len(parts) == 2 {
headersMap[parts[0]] = parts[1]
} else if len(parts) == 1 {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Trigger an error...

Co-Authored-By: maxence@formance.com <maxence@formance.com>
if len(parts) == 2 {
headersMap[parts[0]] = parts[1]
} else if len(parts) == 1 && parts[0] != "" {
panic("malformed header: " + header + " (missing value)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Damn, just return a CLI error

Co-Authored-By: maxence@formance.com <maxence@formance.com>
if len(parts) == 2 {
headersMap[parts[0]] = parts[1]
} else if len(parts) == 1 && parts[0] != "" {
cmd.PrintErrf("Error: malformed header: %s (missing value)\n", header)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't print the error

Co-Authored-By: maxence@formance.com <maxence@formance.com>
Co-Authored-By: maxence@formance.com <maxence@formance.com>
Copy link
Contributor Author

Closing due to inactivity for more than 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants