Skip to content

Mysql proxy filter#4975

Merged
lizan merged 102 commits intoenvoyproxy:masterfrom
rshriram:mysql
Jan 17, 2019
Merged

Mysql proxy filter#4975
lizan merged 102 commits intoenvoyproxy:masterfrom
rshriram:mysql

Conversation

@rshriram
Copy link
Copy Markdown
Member

@rshriram rshriram commented Nov 6, 2018

This filter contains the logic to decode the mysql wire protocol and SQL queries (SQL99 only).
The code is based on our internal version at VMware. The SQL parser can be found at https://github.com/rshriram/sql-parser. Its a cleaned up version of Hyrise SQL parser. I am keeping the code as a separate library as importing the sources into envoy will cause a lot of changes to the code.

Signed-off-by: Giorgio Valentini gvalentini@vmware.com
Signed-off-by: Deepa Kalani dkalani@vmware.com
Signed-off-by: Shriram Rajagopalan shriramr@vmware.com
Signed-off-by: Venil Noronha veniln@vmware.com

Shriram Rajagopalan added 5 commits November 6, 2018 12:33
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@mattklein123
Copy link
Copy Markdown
Member

@rshriram what's the high level plan here for this? Can you provide some context on what this will do before we start thinking about reviewing? Note also that we have the older MySQL HC PR from AirBnb which was never finished.

@rshriram
Copy link
Copy Markdown
Member Author

rshriram commented Nov 6, 2018

@mattklein123 this filter by itself is useful for decoding the connection phase of the mysql wire protocol (https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_PROTOCOL.html#protocol_overview) . It will emit stats like the database accessed (not the tables), the user, active sessions, failed login sessions, etc. So, the current PR by itself carries a decent amount of utility.

In order to decode the SQL queries in the command phase (https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_command_phase.html), we need a full fledged SQL parser based on lex/yacc etc. The code we have internally doesn't use such a parser. It extracts only the pieces we want. Thats unlikely to be useful to the rest of the community.

The MySQL health check stuff can be written on top of this code. IIRC, the mysql health check stuff was doing some minimal protocol processing just enough to decode the simple mysql ping queries, while this provides a full fledged parser for the connection phase.

@lizan lizan requested a review from dio November 6, 2018 23:26
Shriram Rajagopalan added 2 commits November 8, 2018 15:36
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@rshriram
Copy link
Copy Markdown
Member Author

rshriram commented Nov 9, 2018

ping.. any comments on this?

Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Overall this is very interesting. As @mattklein123 comment, let's have this: #3502 to be built based on this?

Just curious, since it has WIP prefix, do you think you want to add more features in this PR?

@rshriram
Copy link
Copy Markdown
Member Author

@dio that’s my plan. Once this is in, we can build #3502 on top of this.

I put it as wip thinking there will be major changes to the design. Will remove.

@rshriram rshriram changed the title WIP: Mysql proxy Mysql proxy filter Nov 13, 2018
@dio
Copy link
Copy Markdown
Member

dio commented Nov 13, 2018

@rshriram cool. Apart from what the clang_tidy has found and that "multiple definitions of ..." when linking MysqlTestUtils in coverage CI (I think either to split the interface and the impl in the different files or put the impl directly in *.h should fix that?), I think this PR is good (tried it manually and it works great).

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Shriram Rajagopalan added 9 commits November 13, 2018 21:29
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Shriram Rajagopalan added 2 commits January 15, 2019 18:45
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Shriram Rajagopalan added 2 commits January 15, 2019 19:51
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@rshriram
Copy link
Copy Markdown
Member Author

@mattklein123 / @lizan
the coverage is missing for getters and setters, or empty virtual functions. I have added more tests for the parts that matter (length encoded integer and the fallback to plain tcp proxy if there is a decoder error)

@rshriram
Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🔨 rebuilding ci/circleci: coverage (failed build)

🐱

Caused by: a #4975 (comment) was created by @rshriram.

see: more, trace.

dio
dio previously approved these changes Jan 16, 2019
Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thanks! I'll defer to Lizan and Matt.

@lizan
Copy link
Copy Markdown
Member

lizan commented Jan 16, 2019

@rshriram re: empty virtual functions, are they supposed not to be called? If so add NOT_IMPLEMENTED_GCOVR_EXCL_LINE, if not some test should cover them.

Signed-off-by: Giorgio Valentini <gvalentini@vmware.com>
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.

Thanks, this is super cool. I skimmed the code and it seems fine to go in as an experimental filter.

Some doc requests, otherwise will defer to @lizan on any remaining code changes.

/wait

@@ -0,0 +1,46 @@
.. _config_network_filters_mysql_proxy:

MySQL proxy
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 add an experimental warning like we do for other new filters? Also, can you add a release note that introduces experimental MySQL support?

Optimally, can you also add a config snippet that shows how to setup the filter? That's typically done now for new filters and it makes it easier on new users.

It would also be super sweet if in a follow up you could add a docker compose example of getting all of this running so that people can use a sample app w/ mysql and actually see this all work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I took a look at other filters. There is no mention of experimental in their docs. The proto stuff however has experimental tag. is that what you meant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added proto status experimental to the protos. And added config snippets along with some RBAC examples as well.

Shriram Rajagopalan added 2 commits January 17, 2019 06:47
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Shriram Rajagopalan added 2 commits January 17, 2019 17:02
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@rshriram
Copy link
Copy Markdown
Member Author

@lizan / @mattklein123 I have added the docs with config samples, version history, and the experimental warning. The docker compose example would have to wait until we have access logging for MySQL.

mattklein123
mattklein123 previously approved these changes Jan 17, 2019
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.

LGTM with small version history at nit. Will defer to @lizan for final review and merge. Thank you for working on this! Super cool.

* tls: enabled TLS 1.3 on the server-side (non-FIPS builds).
* router: added per-route configuration of :ref:`internal redirects <envoy_api_field_route.RouteAction.internal_redirect_action>`.
* upstream: add hash_function to specify the hash function for :ref:`ring hash<envoy_api_msg_Cluster.RingHashLbConfig>` as either xxHash or `murmurHash2 <https://sites.google.com/site/murmurhash>`_. MurmurHash2 is compatible with std::hash in GNU libstdc++ 3.4.20 or above. This is typically the case when compiled on Linux and not macOS.
* network filters: added a MySQL proxy filter that is capable of parsing SQL queries over MySQL wire protocol. Refer to ::ref:`MySQL proxy<config_network_filters_mysql_proxy>` for more details.
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: alpha order and also I would call this "mysql:"

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@lizan lizan merged commit b3be571 into envoyproxy:master Jan 17, 2019
// Safety measure just to make sure that if we have a decoding error we keep going and lose stats.
// This can be removed once we are more confident of this code.
if (!sniffing_) {
buffer.drain(buffer.length());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @rshriram. Why does the buffer need draining here ?
I tried out the filter with SSL and it hangs after draining for both onData and onWrite.
Taking out this line altogether results in a build that works as intended.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was merely following the logic in mongo filter, that did the same.

void ProxyFilter::doDecode(Buffer::Instance& buffer) {
  if (!sniffing_ ||
      !runtime_.snapshot().featureEnabled(MongoRuntimeConfig::get().ProxyEnabled, 100)) {
    // Safety measure just to make sure that if we have a decoding error we keep going and lose
    // stats. This can be removed once we are more confident of this code.
    buffer.drain(buffer.length());
    return;
  }

fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
This filter contains the logic to decode the mysql wire protocol and SQL queries (SQL99 only).
The code is based on our internal version at VMware. The SQL parser can be found at https://github.com/rshriram/sql-parser. Its a cleaned up version of Hyrise SQL parser. I am keeping the code as a separate library as importing the sources into envoy will cause a lot of changes to the code.

Signed-off-by: Giorgio Valentini <gvalentini@vmware.com>
Signed-off-by: Deepa Kalani <dkalani@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Venil Noronha <veniln@vmware.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no stalebot Disables stalebot from closing an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants