Skip to content

Add config to control tracing sql parameters in MySQL agent#2846

Merged
wu-sheng merged 37 commits intoapache:masterfrom
kezhenxu94:gh/2587
Jun 19, 2019
Merged

Add config to control tracing sql parameters in MySQL agent#2846
wu-sheng merged 37 commits intoapache:masterfrom
kezhenxu94:gh/2587

Conversation

@kezhenxu94
Copy link
Copy Markdown
Member

@kezhenxu94 kezhenxu94 commented Jun 10, 2019

Please answer these questions before submitting pull request


New feature or improvement

  • Describe the details and related test reports.

Add a config key to control whether to collect the SQL parameters.

Here is one point need to discuss:

there're methods like java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, long), java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long) and similar methods in PreparedStatement, should we collect them as well? The InputStream may be large and hard to display in tags, I would like to only collect their length and display something like InputStream[length] or anyone has better idea?

cc @vision-ken

here is the span detail:
image

@wu-sheng wu-sheng added agent Language agent related. feature New feature plugin Plugin for agent or collector. Be used to extend the capabilities of default implementor. labels Jun 10, 2019
@wu-sheng
Copy link
Copy Markdown
Member

there're methods like java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, long), java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long) and similar methods in PreparedStatement, should we collect them as well? The InputStream may be large and hard to display in tags, I would like to only collect their length and display something like InputStream[length] or anyone has better idea?

You could simply ignore them. I don't think we need to do this with such high payload. For InputStream[length], I am not sure whether it is worth to do.
Also, based on this, your parameter tag value is not perfect. Thinking about these

  1. If one parameter is ignored somehow, parameter list would match, unless you keep a ? or InputStream or something to be a placeholder.
  2. If the parameter includes ,, what happens?

@wu-sheng
Copy link
Copy Markdown
Member

Also, active this in MySQL integration test case, and modify the test case, please.

@kezhenxu94
Copy link
Copy Markdown
Member Author

For InputStream[length], I am not sure whether it is worth to do.

The reason why I'd like to do this is to make it a placeholder, as you said:

If one parameter is ignored somehow, parameter list would match, unless you keep a ? or InputStream or something to be a placeholder.

keeping a ? as placeholder is fine for me.

If the parameter includes ,, what happens?

quoting the parameter with " seems to be not perfect either, I'll think about this

@ascrutae
Copy link
Copy Markdown
Member

Should we limit the length of string parameters? The performance of Agent will be reduced if the values of SQL parameter are too large

@kezhenxu94
Copy link
Copy Markdown
Member Author

kezhenxu94 commented Jun 11, 2019

Should we limit the length of string parameters? The performance of Agent will be reduced if the values of SQL parameter are too large

You mean truncating the final parameter string?

If users active this config but not get the complete parameters, it would be useless sometimes (the useful parameters may be truncated).

I'd rather suggest the users not to active this config when the parameters are large/long, or just active during debugging.

It's disabled by default, so the users must pay for the performance themselves if we clearly documented this.

Just my own opinion, further discussion are very welcomed. @ascrutae

@wu-sheng
Copy link
Copy Markdown
Member

Should we limit the length of string parameters? The performance of Agent will be reduced if the values of SQL parameter are too large

This could be argued too :) But for performance concern, I think @kezhenxu94 you could set a max parameter length config too.

@wu-sheng
Copy link
Copy Markdown
Member

quoting the parameter with " seems to be not perfect either, I'll think about this

Normally, I would say JSON Array should a good idea, but in agent, I think we don't have JSON lib today.

@kezhenxu94
Copy link
Copy Markdown
Member Author

quoting the parameter with " seems to be not perfect either, I'll think about this

Normally, I would say JSON Array should a good idea, but in agent, I think we don't have JSON lib today.

There seems to be GSON already

@wu-sheng
Copy link
Copy Markdown
Member

There seems to be GSON already

If so, using it is a better idea. What do you think?

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 11, 2019

Coverage Status

Coverage decreased (-0.02%) to 17.223% when pulling 7c78080 on kezhenxu94:gh/2587 into ee7c418 on apache:master.

@kezhenxu94
Copy link
Copy Markdown
Member Author

There seems to be GSON already

If so, using it is a better idea. What do you think?

I'm with it

@kezhenxu94
Copy link
Copy Markdown
Member Author

Should we limit the length of string parameters? The performance of Agent will be reduced if the values of SQL parameter are too large

This could be argued too :) But for performance concern, I think @kezhenxu94 you could set a max parameter length config too.

Hi @ascrutae , as suggested, I've truncate the sql parameters if it's long. now it works like this:

image

As @wu-sheng suggested, I've made another config SQL_PARAMETERS_MAX_LENGTH to make it possible for users who are perfectly sure they want to keep the complete parameters, thanks @wu-sheng :-)

@wu-sheng
Copy link
Copy Markdown
Member

OK. I am OK with this PR at high level. @IanCao @ascrutae Please do the code receivews.

@kezhenxu94 Let's make the test cases work.

@kezhenxu94
Copy link
Copy Markdown
Member Author

kezhenxu94 commented Jun 15, 2019

There seems to be GSON already

If so, using it is a better idea. What do you think?

Turns out that we cannot use the Gson library because of the same reason as #2871

Copy link
Copy Markdown
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

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

LGTM. Could you run the test case locally or ask @IanCao to run the cases on our server.

I think it would be safer to recheck the test cases. @kezhenxu94 If you want to run server, you need to tell @IanCao which cases are needed to run. All MySQL cases, I guess?

@kezhenxu94
Copy link
Copy Markdown
Member Author

kezhenxu94 commented Jun 18, 2019

LGTM. Could you run the test case locally or ask @IanCao to run the cases on our server.

I think it would be safer to recheck the test cases. @kezhenxu94 If you want to run server, you need to tell @IanCao which cases are needed to run. All MySQL cases, I guess?

Yes all MySQL cases.

@IanCao Could you please run the tests with the original test code and agent code of this PR? I'll run the modified version locally and post the result here

@wu-sheng
Copy link
Copy Markdown
Member

Could you please run the tests with the original test code and agent code of this PR? I'll run the modified version locally and post the result here

Our tests will use these PR codes, not original codes. @kezhenxu94

@kezhenxu94
Copy link
Copy Markdown
Member Author

kezhenxu94 commented Jun 18, 2019

Could you please run the tests with the original test code and agent code of this PR? I'll run the modified version locally and post the result here

Our tests will use these PR codes, not original codes. @kezhenxu94

@wu-sheng What I meant is to ask @IanCao to use the original test codes to test these PR codes (with the config key off, which is by default), and in order to test the codes with the config key on, I have to modify some test codes, and I'll use the modified test codes to test these PR code, make sense?

@SkyWalkingRobot
Copy link
Copy Markdown

Here is the test report and validate logs

@wu-sheng
Copy link
Copy Markdown
Member

@kezhenxu94 Look like most passed. One fails, I assume it is just accidental by current test tool, cc @ascrutae .

@wu-sheng
Copy link
Copy Markdown
Member

@kezhenxu94 I am waiting for your test results of tracing parameters on to make these merged.

@kezhenxu94
Copy link
Copy Markdown
Member Author

@kezhenxu94 I am waiting for your test results of tracing parameters on to make these merged.

Tests are still running locally, poor local machine 😢 once done, I'll post here

@wu-sheng
Copy link
Copy Markdown
Member

Tests are still running locally, poor local machine 😢 once done, I'll post here

Got it. @ascrutae Let's make this work in next month, then we could have a much more friendly PR procedure.

@kezhenxu94
Copy link
Copy Markdown
Member Author

Test Report - 2019-06-19 11:52

Cases List

Case description Status Cases
Mysql 53 passed. 0 failed click me

Mysql

Version Passed Failed
5.1.10 ✔️
5.1.11 ✔️
5.1.12 ✔️
5.1.13 ✔️
5.1.14 ✔️
5.1.15 ✔️
5.1.16 ✔️
5.1.17 ✔️
5.1.18 ✔️
5.1.19 ✔️
5.1.2 ✔️
5.1.20 ✔️
5.1.21 ✔️
5.1.22 ✔️
5.1.23 ✔️
5.1.24 ✔️
5.1.25 ✔️
5.1.26 ✔️
5.1.27 ✔️
5.1.28 ✔️
5.1.29 ✔️
5.1.3 ✔️
5.1.30 ✔️
5.1.31 ✔️
5.1.32 ✔️
5.1.33 ✔️
5.1.34 ✔️
5.1.35 ✔️
5.1.36 ✔️
5.1.37 ✔️
5.1.38 ✔️
5.1.39 ✔️
5.1.4 ✔️
5.1.40 ✔️
5.1.41 ✔️
5.1.42 ✔️
5.1.43 ✔️
5.1.44 ✔️
5.1.45 ✔️
5.1.5 ✔️
5.1.6 ✔️
5.1.8 ✔️
5.1.9 ✔️
6.0.2 ✔️
6.0.3 ✔️
6.0.4 ✔️
6.0.5 ✔️
6.0.6 ✔️
8.0.11 ✔️
8.0.12 ✔️
8.0.13 ✔️
8.0.14 ✔️
8.0.15 ✔️

And FYI, my test codes are here

@wu-sheng wu-sheng added this to the 6.2.0 milestone Jun 19, 2019
Copy link
Copy Markdown
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

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

LGTM, merging.

@wu-sheng wu-sheng merged commit 0956491 into apache:master Jun 19, 2019
@kezhenxu94 kezhenxu94 deleted the gh/2587 branch June 19, 2019 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Language agent related. feature New feature plugin Plugin for agent or collector. Be used to extend the capabilities of default implementor.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support database sql statement parameter value(optional)

5 participants