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

statistics: refactor #1750

Merged
merged 20 commits into from
Oct 11, 2019
Merged

statistics: refactor #1750

merged 20 commits into from
Oct 11, 2019

Conversation

Luffbee
Copy link
Contributor

@Luffbee Luffbee commented Sep 11, 2019

What problem does this PR solve?

The statistics package is too hard to understand.

What is changed and how it works?

Refactor it. There are mainly these kinds of changes:

  • separate exported types into different files to the dependencies more clear
  • remove unnecessary types
  • rename types and fields to make them more meaningful
  • reduce if branches to make logic more clear
  • extract some helper functions to reduce the length of huge functions

There are still some problems, but considering that this PR is already changed a lot of things, I'd like to improve them in future PRs.

Check List

Tests

  • Unit test

@Luffbee Luffbee added the type/enhancement The issue or PR belongs to an enhancement. label Sep 11, 2019
"github.com/montanaflynn/stats"
)

func storeTag(id uint64) string {
Copy link
Member

Choose a reason for hiding this comment

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

This function also can be used somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So where should I put it?

server/statistics/region_stat_informer.go Show resolved Hide resolved
server/statistics/hot_regions_stat.go Show resolved Hide resolved
package statistics

// StoreHotRegionInfos : used to get human readable description for hot regions.
type StoreHotRegionInfos struct {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to merge this file into hot_regions_stat.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two struct are too simple, and not use by other types or functions in this package. So I'm thinking about moving them to where they are used.
Is there any suggestions?

server/schedulers/hot_region.go Outdated Show resolved Hide resolved
server/statistics/hot_cache.go Outdated Show resolved Hide resolved
@Luffbee Luffbee added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 17, 2019
@codecov-io
Copy link

codecov-io commented Sep 17, 2019

Codecov Report

Merging #1750 into master will increase coverage by 0.18%.
The diff coverage is 87.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1750      +/-   ##
==========================================
+ Coverage   77.32%   77.51%   +0.18%     
==========================================
  Files         163      166       +3     
  Lines       16433    16395      -38     
==========================================
+ Hits        12707    12708       +1     
+ Misses       2674     2657      -17     
+ Partials     1052     1030      -22
Impacted Files Coverage Δ
server/statistics/store.go 96.07% <ø> (+1.96%) ⬆️
server/statistics/store_collection.go 88% <ø> (ø) ⬆️
server/statistics/flowkind.go 0% <0%> (ø)
server/coordinator.go 78.78% <0%> (-6.44%) ⬇️
server/api/trend.go 68.75% <0%> (ø) ⬆️
server/cluster.go 85.23% <100%> (+1.02%) ⬆️
server/namespace_cluster.go 88.88% <100%> (ø) ⬆️
server/schedulers/shuffle_hot_region.go 65.38% <100%> (ø) ⬆️
server/statistics/util.go 100% <100%> (ø) ⬆️
server/statistics/hot_cache.go 98.14% <100%> (+19.76%) ⬆️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1fbadf8...f38cfed. Read the comment docs.

Copy link
Contributor

@shafreeck shafreeck left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

LGTM. Please resolve the conflict.

@Luffbee Luffbee added status/can-merge Indicates a PR has been approved by a committer. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 11, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Oct 11, 2019

/run-all-tests

@sre-bot sre-bot merged commit 2550168 into tikv:master Oct 11, 2019
@Luffbee Luffbee deleted the refactor-statistics branch October 11, 2019 03:04
lhy1024 pushed a commit to lhy1024/pd that referenced this pull request Oct 11, 2019
(cherry picked from commit 2550168)
Signed-off-by: lhy1024 <admin@liudos.us>
@Luffbee Luffbee restored the refactor-statistics branch November 1, 2019 05:24
@Luffbee Luffbee mentioned this pull request Nov 1, 2019
@Luffbee Luffbee deleted the refactor-statistics branch January 27, 2020 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/can-merge Indicates a PR has been approved by a committer. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants