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
Add ability to config Timer and DistributionSummary with user defined… #1176
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1176 +/- ##
==========================================
- Coverage 72.7% 72.63% -0.07%
==========================================
Files 518 517 -1
Lines 23259 23282 +23
Branches 2910 2910
==========================================
+ Hits 16910 16911 +1
- Misses 4795 4823 +28
+ Partials 1554 1548 -6
Continue to review full report at Codecov.
|
|
||
/** | ||
* Provides utilities for accessing {@link MeterRegistry}. | ||
*/ | ||
public final class MoreMeters { | ||
|
||
private static DistributionStatisticConfig distributionStatisticConfig; | ||
|
||
public static void withConfig(DistributionStatisticConfig config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Missing Javadoc
- Rename to something like
setDistributionStatisticConfig()
? requireNonNull(config, "config")
- Add the getter as well:
public static DistributionStatisticConfig distributionStatisticConfig()
|
||
/** | ||
* Provides utilities for accessing {@link MeterRegistry}. | ||
*/ | ||
public final class MoreMeters { | ||
|
||
private static DistributionStatisticConfig distributionStatisticConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Missing
volatile
- Could we set the non-null default config so that it never becomes
null
?
* If distributionStatisticConfig is set, use the config. | ||
* If the config is not set, use default percentile. | ||
**/ | ||
public static DistributionSummary defaultDistributionSummary(MeterRegistry registry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just newDistributionSummary
?
.tags(tags) | ||
.publishPercentiles(distributionStatisticConfig.getPercentiles()) | ||
.publishPercentileHistogram( | ||
distributionStatisticConfig.isPercentileHistogram()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming to a shorter name so the line does not wrap? e.g. distStatCfg
?
String name, Iterable<Tag> tags) { | ||
* Returns a newly-registered {@link DistributionSummary}. | ||
* If distributionStatisticConfig is set, use the config. | ||
* If the config is not set, use default percentile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If .... If ....
could be removed and the necessary documentation could be put in the getter and setter of distributionStatisticConfig
.
} | ||
|
||
/** | ||
* Returns a newly-registered {@link Timer} with percentile publication configured. | ||
* If distributionStatisticConfig is set, use the config. | ||
* If the config is not set, use default percentile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If .... If ....
could be removed and the necessary documentation could be put in the getter and setter of distributionStatisticConfig
.
.tags(tags) | ||
.publishPercentiles(PERCENTILES) | ||
.register(registry); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a newly-registered {@link Timer} with percentile publication configured. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Replace
with percentile ...
withwith the current {@linkplain #distributionStatisticConfig() distribution statistic configuration}.
*/ | ||
public static DistributionSummary summaryWithDefaultQuantiles(MeterRegistry registry, | ||
String name, Iterable<Tag> tags) { | ||
* Returns a newly-registered {@link DistributionSummary}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Append: with the current {@linkplain #distributionStatisticConfig() distribution statistic configuration}.
.publishPercentiles(PERCENTILES) | ||
.register(registry); | ||
|
||
if (distributionStatisticConfig != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do null
check if changed as I requested.
return DistributionSummary.builder(name) | ||
.tags(tags) | ||
.publishPercentiles(PERCENTILES) | ||
.register(registry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will go away if changed as I requested.
You may want to keep the original methods and their old behavior to keep the backward compatibility, but I'm not strong on this. |
e194f99
to
9f706a7
Compare
.build(); | ||
|
||
/** | ||
* Set {@link DistributionStatisticConfig} to {@link MoreMeters}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set -> Sets
} | ||
|
||
/** | ||
* Return the current {@link DistributionStatisticConfig} of {@link MoreMeters}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return -> Returns
} | ||
|
||
/** | ||
* Returns a newly-registered {@link DistributionSummary} use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use -> configured by?
requireNonNull(name, "name"); | ||
requireNonNull(tags, "tags"); | ||
|
||
Duration maxExpectedValue = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final
Duration maxExpectedValue = | ||
Optional.ofNullable(distributionStatisticConfig.getMaximumExpectedValue()) | ||
.map(Duration::ofNanos).orElse(null); | ||
Duration minExpectedValue = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final
@@ -52,9 +106,37 @@ public static DistributionSummary summaryWithDefaultQuantiles(MeterRegistry regi | |||
.register(registry); | |||
} | |||
|
|||
/** | |||
* Returns a newly-registered {@link Timer} use {@link MoreMeters#distributionStatisticConfig}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff. Thanks!
* {@link MoreMeters#newDistributionSummary(MeterRegistry, String, Iterable)} will use this config. | ||
*/ | ||
public static void setDistributionStatisticConfig(DistributionStatisticConfig config) { | ||
requireNonNull(config, "distributionStatisticConfig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"distributionStatisticConfig"
-> "config"
.tags(tags) | ||
.publishPercentiles(distributionStatisticConfig.getPercentiles()) | ||
.publishPercentileHistogram( | ||
distributionStatisticConfig.isPercentileHistogram()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All setter calls could be joined into a single line so they look prettier:
.publishPercentileHistogram(distributionStatisticConfig.isPercentileHistogram())
.maximumExpectedValue(distributionStatisticConfig.getMaximumExpectedValue())
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is over checkStyle quota when joins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I suggested renaming the field to something like distStatCfg
. Seriously, it's way too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you change the name plz?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
/** | ||
* Returns a newly-registered {@link DistributionSummary} with percentile publication configured. | ||
* @deprecated use {@link MoreMeters#newDistributionSummary(MeterRegistry, String, Iterable)} instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MoreMeters
in{@link }
is redundant because we are referring to the member in the current class. i.e.{@link #newDistributionSummary(...)}
- use -> Use
s/ instead//
(instead is redundant)
@@ -52,9 +106,37 @@ public static DistributionSummary summaryWithDefaultQuantiles(MeterRegistry regi | |||
.register(registry); | |||
} | |||
|
|||
/** | |||
* Returns a newly-registered {@link Timer} configured by {@link MoreMeters#distributionStatisticConfig}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{@link #distributionStatisticConfig()}
- We should not refer to a field but to a method.
MoreMeters
is redundant.
/** | ||
* Returns a newly-registered {@link Timer} with percentile publication configured. | ||
* @deprecated use {@link MoreMeters#newTimer(MeterRegistry, String, Iterable)} instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/MoreMeters//
- use -> Use
s/ instead//
.build(); | ||
|
||
/** | ||
* Sets {@link DistributionStatisticConfig} to {@link MoreMeters}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
Sets the {@link DistributionStatisticConfig} to use when the factory methods in {@link MoreMeter} create
a {@link Timer} or a {@link DistributionSummary}.
...?
Then the remaining sentences ('Any... will use this config.) would be OK to be removed.
} | ||
|
||
/** | ||
* Returns the current {@link DistributionStatisticConfig} of {@link MoreMeters}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How about adding
@see #setDistributionStatisticConfig(..)
? Returns the {@link DistributionStatisticConfig} to use when the factory methods in {@link MoreMeter} create a {@link Timer} or a {@link DistributionSummary}.
?
2ff8dcc
to
69bece0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two more nits and we're done I guess. :-)
/** | ||
* Returns a newly-registered {@link DistributionSummary} configured by | ||
* {@link #distributionStatisticConfig()}. | ||
**/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**/
-> */
/** | ||
* Returns a newly-registered {@link Timer} with percentile publication configured. | ||
* @deprecated Use {@link MoreMeters#newTimer(MeterRegistry, String, Iterable)}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MoreMeters
-> <nil>
PTAL~ @trustin |
@minwoox Any comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you~!
Thanks, @huydx and reviewers! |
Motivation: It is currently not possible to customize the settings of `DistributionSummary`s and `Timer`s, such as `expiry` and `bucketLength`. See `MoreMeters.summary/timerWithDefaultQuantiles()`. Modifications: - Add `MoreMeters.distributionStatisticConfig` property so that a user can change the default settings - Deprecate `MoreMeters.summaryWithDefaultQuantiles` and `timerWithDefaultQuantiles` - Add `MoreMeters.newDistributionSummary()` and `newTimer()` Result: - A user can customize the `Timer`s and `DistributionSummary`s created by Armeria. - Fixes line#1170
… config
Solve #1170