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

feat(tools): HTTP Response 503 Service unavailable #2023

Closed
wants to merge 4 commits into from
Closed

feat(tools): HTTP Response 503 Service unavailable #2023

wants to merge 4 commits into from

Conversation

pauldaustin
Copy link

Summary

Add HTTP response for 503 Service unavailable. This will be used for a
new api-unavailable plugin that will send a 503 error. See #1279.

Full changelog

  • Implement HTTP response for 503 Service unavailable.

Issues resolved

N/A

Add HTTP response for 503 Service unavailable. This will be used for a
new api-unavailable plugin that will send a 503 error. See #1279.
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Hi,

Just a few style tweaks should be changed. Ultimately, you didn't have to add this feature and could have simply used the ngx_lua API (done in a few places when this - outdated - tool is not flexible enough) but it cannot hurt to have it :)

Thanks

@@ -55,7 +56,8 @@ local _M = {
HTTP_METHOD_NOT_ALLOWED = 405,
HTTP_CONFLICT = 409,
HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_INTERNAL_SERVER_ERROR = 500
HTTP_INTERNAL_SERVER_ERROR = 500,
HTTP_SERVICE_UNAVAILABLE = 503
Copy link
Member

Choose a reason for hiding this comment

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

We need to add a trailing comma here so that future diffs on that table will be more pertinent.

Copy link
Author

Choose a reason for hiding this comment

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

24 years of java programming has me not putting the trailing comma. I like the consistent diff idea where languages support it

@@ -96,7 +102,7 @@ local function send_response(status_code)
-- @param content (Optional) The content to send as a response.
-- @return ngx.exit (Exit current context)
return function(content, headers)
if status_code >= _M.status_codes.HTTP_INTERNAL_SERVER_ERROR then
if status_code >= _M.status_codes.HTTP_INTERNAL_SERVER_ERROR and status_code ~= _M.status_codes.HTTP_SERVICE_UNAVAILABLE then
Copy link
Member

Choose a reason for hiding this comment

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

style: let's not go over the 80 characters limit per line

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, I wonder if this behavior should actually be changed to only log when we send 500, instead of 5xx.

Added , to end of list
Changed to only log 500 errors
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of it.

Would you now mind adding the necessary tests to spec/01-unit/10-responses_spec.lua? Namely, that requests are not logged on all 5xx status codes and that the new "Service Unavailable" one is working as expected?

Thanks

@pauldaustin
Copy link
Author

pauldaustin commented Jan 26, 2017 via email

@thibaultcha
Copy link
Member

bin/busted path/to/file

@@ -83,6 +86,9 @@ local response_default_content = {
end,
[_M.status_codes.HTTP_METHOD_NOT_ALLOWED] = function(content)
return "Method not allowed"
end,
[_M.status_codes.HTTP_SERVICE_UNAVAILABLE] = function(content)
return content or "Service Unavailable"
Copy link
Member

Choose a reason for hiding this comment

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

nitpick; align capitalization, single capital. eg. "Service unavailable"

@thibaultcha thibaultcha added the pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) label Jan 31, 2017
@Tieske
Copy link
Member

Tieske commented Jan 31, 2017

Let's wait for the 0.10.0 to be final before merging, to reduce conflicts. And to refactor some other 503 references in /kong/core/balancer.lua (in the new release)

@thibaultcha
Copy link
Member

thibaultcha commented Jan 31, 2017 via email

@pauldaustin
Copy link
Author

Do you want me to update this branch to change the existing send(503) to use the new send method?

@Tieske
Copy link
Member

Tieske commented Feb 6, 2017

@pauldaustin only after the 0.10.0 release branch has been merged (that's where those references are).

@Tieske Tieske added this to the 0.10.2 milestone Apr 4, 2017
@Tieske
Copy link
Member

Tieske commented Apr 4, 2017

merged through #2328 closing this.

@pauldaustin Thank you!

@Tieske Tieske closed this Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants