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

topsql: refactor reporter and add reporting part of stmtstats #30954

Merged
merged 19 commits into from
Dec 29, 2021

Conversation

mornyx
Copy link
Contributor

@mornyx mornyx commented Dec 22, 2021

What is changed and how it works?

In this PR (#30277), we introduced the stmtstats framework, but the reporting part is missing. This PR completes this part by:

  • Refactor topsql/reporter for flexibility.
  • Implement stmtstats.Collector for reporter.RemoteTopSQLReporter.
  • Register reporter.RemoteTopSQLReporter as stmtstats.Collector.
  • Add reporting of stmtstats.

Related PR

Check List

Tests

  • Unit test
  • Integration test

Release note

None

Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 22, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • breeswish
  • crazycs520

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 22, 2021
Signed-off-by: mornyx <mornyx.z@gmail.com>
@mornyx
Copy link
Contributor Author

mornyx commented Dec 23, 2021

/run-all-tests

@mornyx
Copy link
Contributor Author

mornyx commented Dec 23, 2021

PTAL, Thanks~
/cc @crazycs520 @zhongzc @breeswish

util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

The current design is mixing the architecture and the business metrics. Could you make them isolated? A good design should be some architecture that, when we want to add a new metrics, reporter/* does not need any changes. Could you design for this direction?

Signed-off-by: mornyx <mornyx.z@gmail.com>
@mornyx mornyx changed the title topsql: add reporting part of stmtstats topsql: refactor reporter and add reporting part of stmtstats Dec 26, 2021
@mornyx
Copy link
Contributor Author

mornyx commented Dec 26, 2021

The current design is mixing the architecture and the business metrics. Could you make them isolated? A good design should be some architecture that, when we want to add a new metrics, reporter/* does not need any changes. Could you design for this direction?

I have refactored the entire topsql/reporter to decouple the "data logic"(datamodel.go) and "report logic"(reporter.go). In the future, if we need to add new indicators, we only need to add the corresponding lines of code to the protobuf conversion part in datamodel.go without modifying reporter.go.

Signed-off-by: mornyx <mornyx.z@gmail.com>
@sre-bot
Copy link
Contributor

sre-bot commented Dec 26, 2021

Signed-off-by: mornyx <mornyx.z@gmail.com>
@dianqihanwangzi
Copy link
Contributor

/run-check_dev_2

Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
@zhongzc
Copy link
Contributor

zhongzc commented Dec 28, 2021

rest LGTM

Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
@ti-chi-bot
Copy link
Member

@zhongzc: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

go.mod Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/reporter.go Show resolved Hide resolved
util/topsql/reporter/reporter.go Outdated Show resolved Hide resolved
util/topsql/reporter/datamodel.go Outdated Show resolved Hide resolved
util/topsql/reporter/datamodel.go Outdated Show resolved Hide resolved
r.tsIndex[timestamp] = len(r.tsItems)
r.tsItems = append(r.tsItems, newItem)
}
r.totalCPUTimeMs += uint64(cpuTimeMs)
Copy link
Member

@breezewish breezewish Dec 28, 2021

Choose a reason for hiding this comment

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

This calculation may be incorrect when duplicated ts is met, as you will replace the value instead of add the value in branch L183.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacement occurs only when the original value is zero.

Copy link
Member

@breezewish breezewish Dec 29, 2021

Choose a reason for hiding this comment

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

I still prefer to do a correct calculation here, since this function is indeed calculated incorrectly, it's just the caller has not entered this path yet. The overall result is fine only because the bug is not triggered, but the bug exists.

You have two ways to make this function correct:

  1. It only accepts the call and update the total when current value=0. For other cases, the array is not overwritten, and total is not updated.
  2. It accepts all calls and always update the total according to a delta of the current value.

Copy link
Contributor Author

@mornyx mornyx Dec 29, 2021

Choose a reason for hiding this comment

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

Your opinion is reasonable, I changed the "replace" behavior to "add/merge" behavior, so method names are changed back to appendXxx.

util/topsql/reporter/datamodel.go Show resolved Hide resolved
Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

the rest LGTM

util/topsql/reporter/datamodel.go Show resolved Hide resolved
util/topsql/reporter/datamodel.go Show resolved Hide resolved
util/topsql/reporter/datamodel.go Show resolved Hide resolved
util/topsql/reporter/datamodel.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 29, 2021
Signed-off-by: mornyx <mornyx.z@gmail.com>
Signed-off-by: mornyx <mornyx.z@gmail.com>
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 29, 2021
@crazycs520
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: c0524ef

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 29, 2021
@mornyx
Copy link
Contributor Author

mornyx commented Dec 29, 2021

/run-check_dev_2

1 similar comment
@mornyx
Copy link
Contributor Author

mornyx commented Dec 29, 2021

/run-check_dev_2

@zhongzc
Copy link
Contributor

zhongzc commented Dec 29, 2021

/run-mysql-test

@ti-chi-bot ti-chi-bot merged commit 7e2d12c into pingcap:master Dec 29, 2021
@mornyx mornyx deleted the stmtstats branch December 29, 2021 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants