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

fix: return provider response during fnc listing errors #1763

Conversation

LucasRoesler
Copy link
Member

Return the original upstream response body when the the list request returns an error. In general, the provider is returning useful and actionable error messages for the user, the previous code hid this in the logs and this is easy for user to overlook.

Additionally, remove an early return from error case after fetching metrics. This looked like a bug and could result in empty api responses if there was a prometheus error.

Motivation and Context

How Has This Been Tested?

Additional test has been added

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Return the original upstream response body when the the list request
returns an error. In general, the provider is returning useful and
actionable error messages for the user, the previous code hid this in
the logs and this is easy for user to overlook.

Additionally, remove an early return from error case after fetching
metrics. This looked like a bug and could result in empty api responses
if there was a prometheus error.

Signed-off-by: Lucas Roesler <[email protected]>
@LucasRoesler LucasRoesler self-assigned this Oct 7, 2022
@@ -55,6 +56,34 @@ func Test_PrometheusMetrics_MixedInto_Services(t *testing.T) {
}
}

func Test_MetricHandler_ForwardsErrors(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add one more test to show the positive case, if we have that already, just let me know and I'll go ahead and approve.

@@ -34,15 +34,13 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
log.Printf("List functions responded with code %d, body: %s",
recorder.Code,
string(upstreamBody))

http.Error(w, "Metrics handler: unexpected status code from provider listing functions", http.StatusInternalServerError)
http.Error(w, string(upstreamBody), recorder.Code)
Copy link
Member

Choose a reason for hiding this comment

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

I think I am OK with this change, let's hope nobody is looking for that specific message because I think it's been there a long time.

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Approved

@alexellis alexellis merged commit c07bebb into openfaas:master Oct 24, 2022
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.

2 participants