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

Fix known mysql type conversion issues #6647

Merged
merged 5 commits into from
Nov 12, 2019
Merged

Fix known mysql type conversion issues #6647

merged 5 commits into from
Nov 12, 2019

Conversation

danielnelson
Copy link
Contributor

@danielnelson danielnelson commented Nov 11, 2019

Add the ability to have per field conversion functions for the global status and global variables queries. These queries both return tables of the form:

+----------------+---------------+------+-----+---------+-------+
| Field          | Type          | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| VARIABLE_NAME  | varchar(64)   | NO   |     |         |       |
| VARIABLE_VALUE | varchar(2048) | NO   |     |         |       |
+----------------+---------------+------+-----+---------+-------+

closes #5529
closes #6646

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson danielnelson added area/mysql fix pr to fix corresponding bug labels Nov 11, 2019
@danielnelson danielnelson added this to the 1.12.5 milestone Nov 11, 2019
// Ignore ErrRange. When this error is set the returned value is "the
// maximum magnitude integer of the appropriate bitSize and sign."
if err, ok := err.(*strconv.NumError); ok && err.Err == strconv.ErrRange {
return v, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we expecting ints bigger than int64 or is this here to be defensive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expecting larger integers, I believe this is actually the cause of the 5529 bug. In the old strategy we tried to parse as an integer and then fell back to a float64, causing the conflict. In theory we also have a unsigned integer type that we could work with, but there isn't a clean way to migrate to it.

return int64(1), nil
case "OFF_PERMISSIVE":
return int64(0), nil
case "ON_PERMISSIVE":
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the permissive aspect of this mode not important? I'm a little concerned that we're throwing away information. Is that just for backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did do this for backwards compatibility, but since we are converting to an integer we could add a 2/3 value. This would mean we need to document the meaning of these values as they would be somewhat arbitrary.


var GlobalStatusConversions = map[string]ConversionFunc{
"ssl_ctx_verify_depth": ParseInt,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue #5529 also mentions type problems with ssl_verify_depth. Shouldn't that also have an entry here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll fix this.

var GlobalVariableConversions = map[string]ConversionFunc{
"gtid_mode": ParseGTIDMode,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

gtid_mode, ssl_ctx_verify_depth, ssl_verify_depth are the fields that have caused issues for us but I wonder if there are others that will be a problem in the future. Were you able to find a list of these changes in mysql API docs for instance? I wonder if adding them one at a time will be a whack-a-mole style headache that we could prevent by finding all the changes before they turn into issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this is going to be whack-a-mole, but I just checked and I don't see a document describing changes in this table. I believe the table is designed more for interactive use than how we are using it.

Perhaps it would make sense to whitelist in the known variables instead of trying to parse them dynamically? I also have some concerns about breaking compatibility if I get too aggressive changing the parse behavior of the fields though.

@danielnelson danielnelson merged commit d858d82 into master Nov 12, 2019
@danielnelson danielnelson deleted the mysql-convert branch November 12, 2019 19:56
danielnelson added a commit that referenced this pull request Nov 12, 2019
athoune pushed a commit to bearstech/telegraf that referenced this pull request Apr 17, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/mysql fix pr to fix corresponding bug
Projects
None yet
2 participants