Skip to content

health check: adding support for basic mysql health checks#3502

Closed
juchem wants to merge 1 commit intoenvoyproxy:masterfrom
airbnb:mj-mysql-hc
Closed

health check: adding support for basic mysql health checks#3502
juchem wants to merge 1 commit intoenvoyproxy:masterfrom
airbnb:mj-mysql-hc

Conversation

@juchem
Copy link
Copy Markdown
Contributor

@juchem juchem commented May 29, 2018

Description:
Adding support for basic mysql health checks, for feature parity with
HAProxy. Only passowrdless users are supported, so it's generally a good
idea to create a db user with no privileges exclusively for the health
checks.

Risk Level: Medium

Testing:
Unit tests added for the following scenarios:
{reuse_connection, dont_reuse_connection} x ({success, timeout, remote_close} + { bad_server_greeting, bad_server_reply} x coverage)

Docs Changes:
Inline documentation added for the new health check API.

Release Notes:
Added an entry to version_history.rst with the new feature.

cc: @lap1817

Fixes #3501

@juchem juchem force-pushed the mj-mysql-hc branch 3 times, most recently from ad39710 to d9ee136 Compare May 30, 2018 00:02
@mattklein123
Copy link
Copy Markdown
Member

@juchem thanks for the contribution. This new health checker should be implemented with our new health checker extension system. See the Redis one for example: https://github.com/envoyproxy/envoy/tree/master/source/extensions/health_checkers

Can you convert it over to an optional extension in a new mysql directory? Thank you!

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented May 30, 2018

sure, working on it

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented May 31, 2018

@mattklein123 done

@mattklein123
Copy link
Copy Markdown
Member

@juchem sorry for the delay here. I will review by the end of the week.

@mattklein123
Copy link
Copy Markdown
Member

@rshriram I'm going to take a pass on this now. Is anyone from VMWare interested in helping to review?

@mattklein123
Copy link
Copy Markdown
Member

Tagging @rshriram as I think he will help review also.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Overall, looks great. Thanks for working on this. Some comments to get started with.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/an user/a user

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: period end of sentence.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a validation that this is not empty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe an empty string is actually a valid case for an anonymous user auth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a/An user name/A user name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you merge master also when you update? I think @zuercher just added these in his Thrift PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check out the recent thrift PR. Can we add this extension to CODEOWNERS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that might have been added by mistake while rebasing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nvm, I've mixed things up in my head

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is this the PR you're referring to? #3789
I'm confused about what "Can we add this extension to CODEOWNERS?" means

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://github.com/envoyproxy/envoy/blob/master/CODEOWNERS. See the new extension policy. Each extension needs owners that will handle code reviews.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

:)
kinda saw that coming, but as I transition to a new team I won't have the cycles to spare, unfortunately

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@juchem is there someone on your old team who would want to help maintain this? If not, another option is to just keep it as a private or public out of tree filter for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@austin-zhu @Jason-Jian @ken-experiment any interest in helping maintain the MySQL health check?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign me up. although I'd need to come up to speed first. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There you go. I'll spend some time this week with Jason to provide an overview of the code structure, then I'll add him as a maintainer of the MySQL health checker in the CODEOWNERS file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is some missing coverage for error cases in this file. Can you check the coverage build in CI and add some more tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mattklein123 where can I find the coverage build in CI? I can't find the build checks. Maybe because the PR was closed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can we make all these methods camelCase per normal Envoy style?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

of course. sorry about that, it's just muscle memory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know the answer to this, but between the Thrift, Mongo, and now this, is there any way to share any of this type of functionality in a common EndianBufferHelper or something? cc @zuercher

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think if we can agree on parsing directly from the buffer (a la mongo/thrift) vs linearizing the entire request before parsing (mysql), we could come up with a helper that supports all 3 protocols. Thrift requests can be almost arbitrarily large, and depending on configuration the size may not be known at the start of the request, so it's not reasonable to linearize them.

Between the three I already see 8/16/24/32/64-bit integers (some signed, some unsigned) plus both null- and non-terminated strings, so there's a lot to go into this utility already.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, +1. @juchem can we at least file a tech debt tracking issue on figuring this out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree it's better. I'll check Mongo/Thrift implementation to see how they do it and depending on the work I'll either file a tech debt or update the PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technically, I think you need to handle partial data here (and elsewhere in similar parsing functions)? There is no guarantee that all the data will come in 1 shot. If that is something that you don't think we need to handle, we should clearly document that and possibly add a TODO here, though I would rather we just handle it. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I haven't seen the need for it just yet, so I believe leaving it as a TODO might suffice. As for how partial data is handled elsewhere in Envoy, does it accumulate partial data in a local buffer and parses in one shot or is there support for a parsing state machine? Implementing such a machine by hand sounds counter-productive and error prone.

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jun 8, 2018

Hey guys, thanks for all the feedback. I just got out on paternal leave so it'll take me a while until I can work on this again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does linearize mean here? Deserialize the payload ? If so I would rephrase accordingly. Because a stream of bytes is inherently linear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

linearize is a Buffer operation. I'll check Mongo's implementation as mentioned somewhere else to see how it reads straight from the buffer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A whole lot of functions here can be useful for anyone wanting to build a full blown MySQL codec in Envoy. I suggest moving these useful MySQL parsing stuff (login, packet okay and others) into a generic MySQL folder (I don’t know the right destination for it given that there is no MySQL filter), but it would provide the filter implementor a jump start. With all the codec functions abstracted, you could encapsulate checks for partial packets etc into the codec, such that the health check is dramatically simplified into
MySQL.doLogin(user)
MySQL.resp == okay -> health check ok

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds like a good idea. I'm not sure that would be useful out-of-the-box for a filter implementor, but it's a starting skeleton as you mentioned. I'll see what I can come up with

@stale
Copy link
Copy Markdown

stale bot commented Jun 18, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Jun 18, 2018
@mattklein123
Copy link
Copy Markdown
Member

I think @juchem is on paternity leave. I will just close for now and we can reopen when he is back.

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jul 6, 2018

Hey @mattklein123, I'm back from paternity leave. I don't have too many cycles to put on this PR so let's try to find a compromise in case I can't work on all requests. I'll strive to take care of them all, though.

@mattklein123 mattklein123 reopened this Jul 10, 2018
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Jul 10, 2018
@mattklein123
Copy link
Copy Markdown
Member

@juchem I reopened it. If you push new commits it should build again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the big- or little-endian appellation applies to single bytes, so probably undo this one.

But for the rest of the methods, is there a specific reason for renaming them all? For example, are you planning on moving this helper class out of the thrift extension so it can be reused elsewhere?

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jul 12, 2018 via email

@zuercher
Copy link
Copy Markdown
Member

You have to add a commit to get CI to run again, unfortunately.

@juchem juchem changed the title health check: adding support for basic mysql health checks [WIP] health check: adding support for basic mysql health checks Jul 12, 2018
@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jul 18, 2018

took care of the coverage, it was a simple issue in the way test packets were built

@mattklein123
Copy link
Copy Markdown
Member

@juchem so is this ready for re-review?

@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jul 19, 2018

Yes

@stale
Copy link
Copy Markdown

stale bot commented Jul 30, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Jul 30, 2018
@mattklein123
Copy link
Copy Markdown
Member

@juchem can you merge master? Then I promise I will look at this PR this week. Thank you!

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Jul 30, 2018
@juchem juchem force-pushed the mj-mysql-hc branch 2 times, most recently from b4d23d4 to 2607c33 Compare July 30, 2018 18:46
@juchem
Copy link
Copy Markdown
Contributor Author

juchem commented Jul 30, 2018

alright. I'll rebase and make sure tests run, then @Jason-Jian will commandeer the PR

Adding support for basic mysql health checks, for feature parity with
HAProxy. Only passowrdless users are supported, so it's generally a good
idea to create a db user with no privileges exclusively for the health
checks.

Signed-off-by: Marcelo Juchem <juchem@gmail.com>
@stale
Copy link
Copy Markdown

stale bot commented Aug 6, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Aug 6, 2018
@mattklein123
Copy link
Copy Markdown
Member

Sorry will look at this soon.

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Aug 6, 2018
<envoy_api_field_core.HealthCheck.unhealthy_edge_interval>`, :ref:`unhealthy to healthy
<envoy_api_field_core.HealthCheck.healthy_edge_interval>` and for subsequent checks on
:ref:`unhealthy hosts <envoy_api_field_core.HealthCheck.unhealthy_interval>`.
* health check: added basic support for :ref:`MySQL health checks <config_health_checkers_mysql>`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be moved to the 1.8.0 section.

* @param Size how many bytes to read out of the buffer.
* @param Endianness specifies the byte order to use when decoding the integral.
*/
template <typename T, ByteOrder Endianness = ByteOrder::Host, size_t Size = sizeof(T)>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I really like this set of changes. Can we please move this change (and the associated Thrift changes) into a separate change? We should make sure the new buffer functions have explicit tests in buffer_impl_test. Let's get that change first and then we can merge master into this change and get this in. Thank you!

@stale
Copy link
Copy Markdown

stale bot commented Aug 20, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Aug 20, 2018
@stale
Copy link
Copy Markdown

stale bot commented Aug 27, 2018

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this Aug 27, 2018
@jkemv
Copy link
Copy Markdown
Contributor

jkemv commented Aug 28, 2018

@mattklein123 FYI there were conflicts with upstream when I tried to rebase, I haven't fully resolved them yet. To clarify, your suggestion was to separate this PR into 2, with explicit tests for the buffer functions, correct? I can reopen the PR once I get these resolved.

@zuercher
Copy link
Copy Markdown
Member

zuercher commented Aug 28, 2018

@Jason-Jian Matt's out for a bit, but I think I understand what he wanted:

PR 1: the include/envoy/buffer and source/common/byte_order changes, and the refactoring of thrift_proxybuffer_helper.h/cc to use them. This PR should include direct tests for the byte_order/buffer code (it may be that you can move test cases from buffer_helper_test.cc, it's up to you)

PR 2: the mysql health check extension and it's API changes.

The idea is that as much as possible, PRs related to extensions should avoid modifying main-line Envoy code.

zuercher pushed a commit that referenced this pull request Sep 17, 2018
#4344)

Extract common buffer helper functions.

This is split out and rebased with upstream as per discussion in #3502 (comment).

Risk Level: Medium
Testing: Unit tests added for buffer and byte_order changes
Docs Changes: N/A
Release Notes: Per discussion with @zuercher this change itself shouldn't need an entry in version_history.rst

Signed-off-by: Jason Jian <jason.jian@airbnb.com>
@rshriram rshriram mentioned this pull request Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale stalebot believes this issue/PR has not been touched recently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passwordless MySQL Health Check

7 participants