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

Add ability to config Timer and DistributionSummary with user defined… #1176

Merged
merged 1 commit into from May 10, 2018

Conversation

huydx
Copy link
Contributor

@huydx huydx commented May 2, 2018

… config

Solve #1170

@codecov
Copy link

codecov bot commented May 2, 2018

Codecov Report

Merging #1176 into master will decrease coverage by 0.06%.
The diff coverage is 91.3%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
.../armeria/internal/metric/RequestMetricSupport.java 75.94% <100%> (ø) ⬆️
...com/linecorp/armeria/common/metric/MoreMeters.java 75% <90.24%> (-22.15%) ⬇️
...necorp/armeria/server/cors/CorsServiceBuilder.java 28.88% <0%> (-8.89%) ⬇️
.../com/linecorp/armeria/server/cors/CorsService.java 53% <0%> (-4.74%) ⬇️
...linecorp/armeria/internal/Http2GoAwayListener.java 76% <0%> (-4%) ⬇️
...m/linecorp/armeria/client/HttpResponseDecoder.java 82.05% <0%> (-1.29%) ⬇️
...corp/armeria/common/logging/DefaultRequestLog.java 79.94% <0%> (ø) ⬆️
...om/linecorp/armeria/spring/ThriftServiceUtils.java
...linecorp/armeria/client/HttpRequestSubscriber.java 67.15% <0%> (+0.72%) ⬆️
... and 3 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 b79f25c...44f6dd6. Read the comment docs.

@trustin trustin added this to the 0.64.0 milestone May 2, 2018

/**
* Provides utilities for accessing {@link MeterRegistry}.
*/
public final class MoreMeters {

private static DistributionStatisticConfig distributionStatisticConfig;

public static void withConfig(DistributionStatisticConfig config) {
Copy link
Member

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

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

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

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

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

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

Choose a reason for hiding this comment

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

  • Replace with percentile ... with with the current {@linkplain #distributionStatisticConfig() distribution statistic configuration}.

*/
public static DistributionSummary summaryWithDefaultQuantiles(MeterRegistry registry,
String name, Iterable<Tag> tags) {
* Returns a newly-registered {@link DistributionSummary}.
Copy link
Member

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

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

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.

@trustin
Copy link
Member

trustin commented May 2, 2018

Thanks, @huydx!
/cc @jwills

@trustin
Copy link
Member

trustin commented May 2, 2018

You may want to keep the original methods and their old behavior to keep the backward compatibility, but I'm not strong on this.

@huydx huydx force-pushed the huydx-metrics-2 branch 6 times, most recently from e194f99 to 9f706a7 Compare May 2, 2018 07:21
.build();

/**
* Set {@link DistributionStatisticConfig} to {@link MoreMeters}.
Copy link
Contributor

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}.
Copy link
Contributor

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

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 =
Copy link
Contributor

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 =
Copy link
Contributor

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}.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member

@trustin trustin left a 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");
Copy link
Member

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

@trustin trustin May 2, 2018

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())
...

Copy link
Contributor Author

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

Copy link
Member

@trustin trustin May 2, 2018

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.

Copy link
Member

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?

Copy link
Contributor Author

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

@trustin trustin May 2, 2018

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

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

@trustin trustin May 2, 2018

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

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

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}.?

@huydx huydx force-pushed the huydx-metrics-2 branch 2 times, most recently from 2ff8dcc to 69bece0 Compare May 2, 2018 12:30
Copy link
Member

@trustin trustin left a 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()}.
**/
Copy link
Member

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)}.
Copy link
Member

Choose a reason for hiding this comment

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

MoreMeters -> <nil>

@huydx
Copy link
Contributor Author

huydx commented May 7, 2018

PTAL~ @trustin

@trustin
Copy link
Member

trustin commented May 9, 2018

@minwoox Any comments?

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thank you~!

@trustin trustin merged commit d070e06 into line:master May 10, 2018
@trustin
Copy link
Member

trustin commented May 10, 2018

Thanks, @huydx and reviewers!

@huydx huydx deleted the huydx-metrics-2 branch June 17, 2018 14:38
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants