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

metrics: attach const label keyspace_id #41693

Merged
merged 6 commits into from
Mar 3, 2023

Conversation

lionelee
Copy link
Contributor

@lionelee lionelee commented Feb 23, 2023

What problem does this PR solve?

Issue Number: close #41698

Problem Summary:

What is changed and how it works?

If keyspace-name is set in the configuration, the TiDB node will get the corresponding keyspace id from PD, and then register metrics with const label 'keyspace_id' attached.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Manual test

  1. without keyspace-name set in tidb config:
  • create a TiDB cluster with 3 tidb-server , 3 tikv-server and 3 pd-server.
  • connect to a tidb instance, and do some queries
  • view the metrics
    w:o keyspace
  1. with keyspace-name set in tidb config:
  • create a TiDB cluster with 3 tidb-server , 3 tikv-server and 3 pd-server(with pre-alloc keyspace in config).
  • connect to a tidb instance, and do some queries
  • view the metrics
    w: keyspace

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

metrics: attach const label keyspace_id

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 23, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • CbcWestwolf
  • hawkingrei

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
Copy link
Member

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Feb 23, 2023
@sre-bot
Copy link
Contributor

sre-bot commented Feb 23, 2023

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 23, 2023
// See the License for the specific language governing permissions and
// limitations under the License.

package server
Copy link
Member

Choose a reason for hiding this comment

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

Some package, like server, executor, and so on, is too large to build in a short time. I suggest you can create a new package like executor/metrics to put this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ystaticy
Copy link
Contributor

ystaticy commented Mar 1, 2023

The results of the manual test should be provided in this PR description.

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 1, 2023
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 1, 2023
@lionelee lionelee marked this pull request as ready for review March 1, 2023 06:26
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2023
@lionelee
Copy link
Contributor Author

lionelee commented Mar 1, 2023

The results of the manual test should be provided in this PR description.

done

@ystaticy
Copy link
Contributor

ystaticy commented Mar 1, 2023

The screenshot needs to be verified.When keyspace-name is configured, metrics will have the label of keyspace_id, if the keyspace-name is not configured, metrics will not have the label of keyspace_id,

ignoreExceedSQLCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_exceed_sql")
ignoreExceedPlanCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_exceed_plan")
ignoreCollectChannelFullCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_collect_channel_full")
ignoreExceedSQLCounter prometheus.Counter
Copy link
Member

Choose a reason for hiding this comment

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

It looks like most of the changes are such separation of declaration and initialization.
Do we have a strong motivation to deliver this change of code style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will re-initialize metrics after getting keyspace from config, and these corresponding metrics variables should also be re-initialized. Thus, we conduct the separation of declaration and initialization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just initialize metircs once?

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'm not sure, it's worth a try. But no matter whether the metrics are initialized once or twice, the separation of declaration and initialization is needed.

@zeminzhou
Copy link
Contributor

/test unit-test

@CbcWestwolf
Copy link
Member

/retest-required


import "github.com/prometheus/client_golang/prometheus"

var keyspaceLabels prometheus.Labels
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use a more generic name so that we may add more labels in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

ignoreExceedSQLCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_exceed_sql")
ignoreExceedPlanCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_exceed_plan")
ignoreCollectChannelFullCounter = metrics.TopSQLIgnoredCounter.WithLabelValues("ignore_collect_channel_full")
ignoreExceedSQLCounter prometheus.Counter
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just initialize metircs once?

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 3, 2023
@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 Mar 3, 2023
Copy link
Contributor

@ystaticy ystaticy 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
Copy link
Member

@ystaticy: 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:

LGTM

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.

@hawkingrei
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: a7b8b73

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 3, 2023
@ti-chi-bot ti-chi-bot merged commit 7235267 into pingcap:master Mar 3, 2023
@ystaticy ystaticy mentioned this pull request Dec 8, 2023
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Attach keyspace labels to metrics
7 participants