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

Return 400 instead of 500 on incorrect OTLP payload #6599

Merged
merged 10 commits into from
Jan 25, 2025

Conversation

ADI-ROXX
Copy link
Contributor

@ADI-ROXX ADI-ROXX commented Jan 23, 2025

Which problem is this PR solving?

Description of the changes

  • Changed StatusInternalServerError to StatusBadRequest because otlp2traces doing the unmarshaling will go into error if there is error in the payload
  • Added a new unit test for the change

How was this change tested?

  • make lint test => pass

Checklist

Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
@ADI-ROXX ADI-ROXX requested a review from a team as a code owner January 23, 2025 17:46
@ADI-ROXX ADI-ROXX requested a review from mahadzaryab1 January 23, 2025 17:46
@ADI-ROXX
Copy link
Contributor Author

@yurishkuro I think that the issue of the 500 error is coming because of the otlp2traces function called here:
image

I think that if the otlp payload cannot be converted into a JSON, there's definitely an issue with the payload and not the server. That's why I have replaced the status code

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.08%. Comparing base (ca3763f) to head (e5dae10).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6599      +/-   ##
==========================================
- Coverage   96.10%   96.08%   -0.03%     
==========================================
  Files         366      366              
  Lines       20949    20949              
==========================================
- Hits        20133    20128       -5     
- Misses        620      624       +4     
- Partials      196      197       +1     
Flag Coverage Δ
badger_v1 9.57% <ø> (ø)
badger_v2 1.75% <ø> (ø)
cassandra-4.x-v1-manual 15.29% <ø> (ø)
cassandra-4.x-v2-auto 1.74% <ø> (ø)
cassandra-4.x-v2-manual 1.74% <ø> (ø)
cassandra-5.x-v1-manual 15.29% <ø> (ø)
cassandra-5.x-v2-auto 1.74% <ø> (ø)
cassandra-5.x-v2-manual 1.74% <ø> (ø)
elasticsearch-6.x-v1 19.42% <ø> (ø)
elasticsearch-7.x-v1 19.50% <ø> (ø)
elasticsearch-8.x-v1 19.67% <ø> (ø)
elasticsearch-8.x-v2 1.75% <ø> (ø)
grpc_v1 11.02% <ø> (ø)
grpc_v2 7.77% <ø> (ø)
kafka-3.x-v1 9.86% <ø> (ø)
kafka-3.x-v2 1.75% <ø> (ø)
memory_v2 1.75% <ø> (ø)
opensearch-1.x-v1 19.55% <ø> (ø)
opensearch-2.x-v1 19.55% <ø> (ø)
opensearch-2.x-v2 1.75% <ø> (ø)
tailsampling-processor 0.47% <ø> (ø)
unittests 94.91% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

please add a unit test to validate that

@yurishkuro
Copy link
Member

please make PR title more descriptive

@ADI-ROXX ADI-ROXX changed the title Return 400 Return 400 instead of 500 when incorrect OTLP payload Jan 23, 2025
Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
@ADI-ROXX
Copy link
Contributor Author

ADI-ROXX commented Jan 24, 2025

@yurishkuro I have added a test case in which I am providing a bad otlp payload and then I am checking is the phrase "400 error" is in the response or not.

response := new(any)
request := "Bad Payload"
err := postJSON(ts.server.URL+"/api/transform", request, response)
require.ErrorContains(t, err, "400 error")
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to check for string error message instead of the actual status code?

Copy link
Contributor Author

@ADI-ROXX ADI-ROXX Jan 24, 2025

Choose a reason for hiding this comment

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

I have done it in the latest commit titled "Directly check StatusCode". Can you please check it once?

Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
@ADI-ROXX
Copy link
Contributor Author

@yurishkuro In the latest commit, I have directly checked the status code without the need of regex or anything else. Can you review it once?

Comment on lines 778 to 780
if err := encoder.Encode(request); err != nil {
require.Error(t, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err := encoder.Encode(request); err != nil {
require.Error(t, err)
}
require.NoError(t, encoder.Encode(request))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in the latest commit.

Copy link
Member

Choose a reason for hiding this comment

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

I expected you'd be able to pattern match on the suggestion and apply it consistently, not just to this line.

ADI-ROXX and others added 2 commits January 25, 2025 10:59
Signed-off-by: cs-308-2023 <adityaruhela2003@gmail.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
@yurishkuro yurishkuro changed the title Return 400 instead of 500 when incorrect OTLP payload Return 400 instead of 500 on incorrect OTLP payload Jan 25, 2025
Signed-off-by: Yuri Shkuro <github@ysh.us>
@yurishkuro yurishkuro merged commit 5c9f16d into jaegertracing:main Jan 25, 2025
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return 400 instead of 500 from upload OTLP endpoint
2 participants