Skip to content

mysql proxy: Improve MySQL Proxy Codec - #14810

Merged
lizan merged 42 commits into
envoyproxy:mainfrom
qinggniq:codec
Mar 13, 2021
Merged

lizan merged 42 commits into
envoyproxy:mainfrom
qinggniq:codec

Conversation

@qinggniq

@qinggniq qinggniq commented Jan 25, 2021 •

Copy link
Copy Markdown
Contributor

Signed-off-by: qinggniq [email protected]

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Commit Message: Complete MySQL MySQL Proxy Codec. Fixed #14809
Additional Description: Now MySQL Proxy Codec can fully support MySQL Protocol
Risk Level: Low
Testing: unit test
Docs Changes: N/A
Release Notes: improve mysql proxy codec
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue] #14809
[Optional Deprecated:]
[Optional API Considerations:]

@repokitteh-read-only

Copy link
Copy Markdown

Hi @qinggniq, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #14810 was opened by qinggniq.

see: more, trace.

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

remove bits header

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

remove bits header

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>
@lizan
lizan requested a review from cpakulski January 27, 2021 21:48
@lizan

lizan commented Jan 27, 2021

Copy link
Copy Markdown
Member

@cpakulski can you take the first pass?

@cpakulski

Copy link
Copy Markdown
Contributor

Sure - I will take care of the first review pass.

…achine, (2) use const std::string& instead of std::string as getter return type

Signed-off-by: qinggniq <[email protected]>

fix format

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>
@qinggniq qinggniq changed the title Complete MySQL Proxy Codec mysql proxy: Improve MySQL Proxy Codec Feb 1, 2021
@qinggniq

qinggniq commented Feb 2, 2021

Copy link
Copy Markdown
Contributor Author

@cpakulski What can I do to help you review? Should I split this pr into some separate prs, each contains changes of one codec?

@cpakulski cpakulski left a comment

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.

Some comments after the first pass.

Can you also check coverage? Additional tests must probably be added to increase coverage.


int ClientLogin::parseResponseSsl(Buffer::Instance& buffer) {
if (BufferHelper::readUint32(buffer, client_cap_) != MYSQL_SUCCESS) {
ENVOY_LOG(info, "error when paring cap client ssl message");

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.

spelling: parsing .... The same below.

if (BufferHelper::endOfBuffer(buffer)) {
// HandshakeV10 can terminate after Server Capabilities
return MYSQL_SUCCESS;
goto 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.

Can you restructure it so you do not use goto?

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.

fixed.

constexpr int MYSQL_UT_SERVER_OK = 0;
constexpr int MYSQL_UT_SERVER_WARNINGS = 0x0001;

class MySQLCLoginRespTest : public testing::Test {};

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.

You dno not have to define fixture class if you do not have a common initialization for all classes or common data structures. You can put decode_data here instead of declaring it in each test. Otherwise delete fixture and declare tests as TEST not TEST_F.

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.

fixed.

namespace NetworkFilters {
namespace MySQLProxy {

class MySQLCLoginTest : public testing::Test {};

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.

Not used fixture class.

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.

fixed.

TEST_F(MySQLCLoginTest, MySQLParseLengthEncodedInteger) {
{
// encode 2 byte value
Buffer::InstancePtr buffer(new Buffer::OwnedImpl());

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.

Instead of using pointer, can you use Buffer::OwnedImpl and use drain method to clean it before you move to the next section of test?

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.

fixed.

namespace NetworkFilters {
namespace MySQLProxy {

class MySQLGreetTest : public testing::Test {};

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.

Empty fixture class.

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.

fixed.

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>

spell

Signed-off-by: qinggniq <[email protected]>
@qinggniq

qinggniq commented Feb 3, 2021

Copy link
Copy Markdown
Contributor Author

@cpakulsk Some corner cases in parseMessage are not covered, I will add tests to cover them ASAP.

Signed-off-by: qinggniq <[email protected]>

fix file mod

Signed-off-by: qinggniq <[email protected]>
@cpakulski

Copy link
Copy Markdown
Contributor

@qinggniq I will review it first thing in the morning. Sorry for delay.

@cpakulski cpakulski left a comment

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.

I think we are very close. Thanks.
Just a few small comments. Your choice if you want to address them (code will be cleaner).
In the meantime I am going to do another full review pass of all changes.

uint32_t init_len = buffer.length();
ASSERT(init_len >= len);
if (BufferHelper::readUint8(buffer, resp_code_) != DecodeStatus::Success) {
ENVOY_LOG(info, "error parsing more plugin data in mysql Login auth more msg");

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.

Can you rephrase the error message to something like:
error parsing body of ....
The same message is used below.

The current message is bit unclear.

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.

Sorry, fixed.

Signed-off-by: qinggniq <[email protected]>
@qinggniq

qinggniq commented Mar 4, 2021

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14810 (comment) was created by @qinggniq.

see: more, trace.

@qinggniq
qinggniq requested a review from cpakulski March 5, 2021 04:25
@qinggniq

qinggniq commented Mar 8, 2021

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14810 (comment) was created by @qinggniq.

see: more, trace.

@qinggniq

qinggniq commented Mar 8, 2021

Copy link
Copy Markdown
Contributor Author

ping @cpakulski

cpakulski
cpakulski previously approved these changes Mar 9, 2021

@cpakulski cpakulski left a comment

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.

Please add release notes.

@dio Passing it to you. I am fine with this PR.

@dio dio left a comment •

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, looks good! Thank you for working on this! However, let's put the error parsing logging on debug level or we can put it as error/warn? WDYT? And yeah seems like we need release notes entry.

// cap flag, so just assume the CLIENT_PROTOCOL_41 is always set. ref
// https://github.com/mysql/mysql-connector-j/blob/release/8.0/src/main/protocol-impl/java/com/mysql/cj/protocol/a/result/OkPacket.java#L48
if (BufferHelper::readUint16(buffer, warnings_) != DecodeStatus::Success) {
ENVOY_LOG(info, "error parsing warnings of ok msg");

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 this be on debug level? I know these were "info", however, don't you think this will be super chatty? The same as all the above error messages I think.

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.

Yes, debug level is appropriate.

uint32_t consumed_len = init_len - buffer.length();
// The tail might contain info base on cap flag and status flag, but just consume all
if (BufferHelper::readStringBySize(buffer, len - consumed_len, info_) != DecodeStatus::Success) {
ENVOY_LOG(info, "error parsing info of ok msg");

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.

debug?

dio
dio previously approved these changes Mar 9, 2021

@dio dio left a comment

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.

Awesome. Thanks!

@qinggniq

qinggniq commented Mar 9, 2021

Copy link
Copy Markdown
Contributor Author

Thanks very much for your patient review @cpakulski. could you help merge it?

@cpakulski

Copy link
Copy Markdown
Contributor

Signed-off-by: qinggniq <[email protected]>

doc: add mysql filter doc

Signed-off-by: qinggniq <[email protected]>

format

Signed-off-by: qinggniq <[email protected]>
Signed-off-by: qinggniq <[email protected]>
Comment on lines -99 to +100
mysql.egress_mysql.protocol_errors: 0
mysql.egress_mysql.queries_parse_error: 0
mysql.egress_mysql.protocol_errors: 21
mysql.egress_mysql.queries_parse_error: 2

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.

If you felt surprise for mysql.egress_mysql.protocol_errors: 21, ref this issue #14975.

@cpakulski cpakulski Mar 11, 2021 •

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.

Yeah, IMHO the filter should not be stateful and check expected seq. It should just do parsing.
It was already reported here: #12868. I tried to look at that and thought that filter should not track seq numbers.

@qinggniq

Copy link
Copy Markdown
Contributor Author

ping @cpakulski @dio

@cpakulski

Copy link
Copy Markdown
Contributor

@lizan. This PR LGTM. Can you take it over and merge it if you are ok with the changes? Thanks.

@dio dio left a comment

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.

Thanks!

@lizan
lizan merged commit df3f298 into envoyproxy:main Mar 13, 2021
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.

MySQL codec need to be improved

6 participants