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

Allow distribution config customization #4829

Merged
merged 22 commits into from Apr 2, 2024

Conversation

echo304
Copy link
Contributor

@echo304 echo304 commented Apr 15, 2023

Motivation:
As of now, users need to use MoreMeters.setDistributionStatisticConfig(config) to specify the distribution config.
It prevents users from configuring different configs depending on the client.
This PR is to resolve above issue.

Modifications:

  • Add distributionStatisticConfig getter to FlagsProvider and DefaultFlagsProvider
  • Add distributionStatisticConfig setter and getter to AbstractMetricCollectingBuilder

Result:

@echo304
Copy link
Contributor Author

echo304 commented Apr 15, 2023

To be honest, I'm not sure if this is right direction. 😱
Any advice/review/comment about the change is welcome!


@Override
public DistributionStatisticConfig distributionStatisticConfig() {
return DistributionStatisticConfig.DEFAULT;
Copy link
Member

Choose a reason for hiding this comment

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

We don't use DistributionStatisticConfig.DEFAULT as default.
We use

DistributionStatisticConfig.builder()
                           .percentilesHistogram(false)
                           .sla()
                           .percentiles(PERCENTILES)
                           .percentilePrecision(2)
                           .minimumExpectedValue(1L)
                           .maximumExpectedValue(Long.MAX_VALUE)
                           .expiry(Duration.ofMinutes(3))
                           .bufferLength(3)
                           .build();

from MoreMeters.distStatCfg as default instead. So we need to:

  • Define the default config in MoreMeters.DEFAULT_DIST_STAT_CFG
    private static volatile DistributionStatisticConfig DEFAULT_DIST_STAT_CFG =
          DistributionStatisticConfig.builder()
                                     .percentilesHistogram(false)
                                     .sla()
                                     .percentiles(PERCENTILES)
                                     .percentilePrecision(2)
                                     .minimumExpectedValue(1L)
                                     .maximumExpectedValue(Long.MAX_VALUE)
                                     .expiry(Duration.ofMinutes(3))
                                     .bufferLength(3)
                                     .build();
  • Use the value from the DefaultFlagsProvider:
    @Override
    public DistributionStatisticConfig distributionStatisticConfig() {
        return MoreMeters.defaultDistributionStatisticConfig();
    }
  • Set the Flags.distributionStatisticConfig() to distStatCfg.
    private static volatile DistributionStatisticConfig distStatCfg = Flags.distributionStatisticConfig();

In this way, we can add this new API without breaking the behavior.

Now, we need to use the MoreMeters.distributionStatisticConfig() as the default value for the AbstractMetricCollectingBuilder:

public abstract class AbstractMetricCollectingBuilder {
  private DistributionStatisticConfig distributionStatisticConfig = MoreMeters.distributionStatisticConfig;
} 

The distributionStatisticConfig will be passed to the constructor of MetricCollectingClient and MetricCollectingService and it will be also passed to RequestMetricSupport.setup(...).
It will be eventually used to create the summary here: https://github.com/line/armeria/blob/main/core/src/main/java/com/linecorp/armeria/internal/common/metric/RequestMetricSupport.java#L221
(MoreMeters.newDistributionSummary() method no longer need to be in MoreMeters. We can move it to RequestMetricSupport as a private method.)

Please let me know if there's anything unclear. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@minwoox
I implemented as you mentioned above but setting MoreMeters.distStatCfg from Flags.distributionStatisticConfig() doesn't work well on some tests.
It complains that MoteMeters.distStatCfg is null. So I checked the failed test from local environment and I got this.
스크린샷 2023-04-21 오후 1 22 26

In theory, Flags.DISTRIBUTION_STATISTIC_CONFIG should be populated by DefaultFlagsProvider.distributionStatisticConfig() and thus MoreMeters.distStatCfg should be populated by `Flags.distributionStatisticConfig().
But in fact, it's null. Maybe there is some timing issue...or circular referencing...or whatever unknown problem.

Any idea?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry about the problem. 😅
The DEFAULT_DIST_STAT_CFG is not instantiated before defaultDistributionStatisticConfig() is called. 😓
Let's move it to another class:

package com.linecorp.armeria.internal.common.metric;
...
public final class DistributionStatisticConfigUtil {
 public static final DistributionStatisticConfig DEFAULT_DIST_STAT_CFG =
    DistributionStatisticConfig.builder()...
  ...
} 

// DefaultFlagProvider

@Override
public DistributionStatisticConfig distributionStatisticConfig() {
    return DistributionStatisticConfigUtil.DEFAULT_DIST_STAT_CFG;
}

- Use MoreMeters default distribution config as default
- allow MetricCollecting{Client,RpcClient,Service} to receive DistributionStatisticConfig
@echo304 echo304 requested review from ikhoon and minwoox May 2, 2023 00:33
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.

Thanks for the PR, @echo304! Left some comments you might want to take a look. 🙇

@@ -1343,6 +1347,16 @@ public static long defaultUnhandledExceptionsReportIntervalMillis() {
return DEFAULT_UNHANDLED_EXCEPTIONS_REPORT_INTERVAL_MILLIS;
}

/**
* Returns the {@link DistributionStatisticConfig} where armeria utilizes.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Returns the {@link DistributionStatisticConfig} where armeria utilizes.
* Returns the default {@link DistributionStatisticConfig} of the {@link Timer}s and {@link DistributionSummary}s created by Armeria.

/**
* Returns the {@link DistributionStatisticConfig} where armeria utilizes.
*
* <p>The default value of this flag is {@link DistributionStatisticConfig#DEFAULT}</p>
Copy link
Member

Choose a reason for hiding this comment

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

This needs an update. We could paste some code here:

<p>The default value of this flag is as follows:
<pre>{@code
DistributionStatisticConfig
  .builder()
  ...
  .build();
}</pre>

Comment on lines 1008 to 1012
/**
* Returns the {@link DistributionStatisticConfig} where armeria utilizes.
*
* <p>The default value of this flag is {@link DistributionStatisticConfig#DEFAULT}</p>
*/
Copy link
Member

Choose a reason for hiding this comment

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

Ditto - please keep in sync with Flags.distributionStatisticConfig().

Comment on lines 23 to 27
public final class DistributionStatisticConfigUtil {
private static final double[] PERCENTILES = { 0, 0.5, 0.75, 0.9, 0.95, 0.98, 0.99, 0.999, 1.0 };

public static final DistributionStatisticConfig DEFAULT_DIST_STAT_CFG =
DistributionStatisticConfig.builder()
Copy link
Member

Choose a reason for hiding this comment

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

Could you reformat this file?

import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;

public final class DistributionStatisticConfigUtil {
private static final double[] PERCENTILES = { 0, 0.5, 0.75, 0.9, 0.95, 0.98, 0.99, 0.999, 1.0 };
Copy link
Member

Choose a reason for hiding this comment

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

It's used only once, so I guess we can inline it.

@trustin trustin self-requested a review May 2, 2023 12:47
@trustin
Copy link
Member

trustin commented May 2, 2023

Approved by mistake. Sorry! 🙏

- Fix comments
- Reformat a file
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.

Let's keep moving on. 😆

- Override MoreMeters.distributionStatisticConfig from RequestMetricSupport.setup
@@ -66,6 +68,8 @@ public static void setup(
RequestLogProperty.NAME,
RequestLogProperty.SESSION)
.thenAccept(log -> onRequest(log, meterIdPrefixFunction, server, successFunction));

MoreMeters.setDistributionStatisticConfig(distributionStatisticConfig);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of your advice(#4829 (comment)), I've override a distributionStatisticConfig from here.

Do you think this is too dangerous approach?
@minwoox

Copy link
Contributor

@ikhoon ikhoon May 12, 2023

Choose a reason for hiding this comment

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

It is not thread safe. The two requests having different DistributionStatisticConfigs update the global DistributionStatisticConfig concurrently, the result is unpredictable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me 😞

Copy link
Member

Choose a reason for hiding this comment

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

As @ikhoon said, we can't just set the config here.
Is there any reason that you are reluctant to use the config in the onResponse method?

Copy link
Contributor Author

@echo304 echo304 May 16, 2023

Choose a reason for hiding this comment

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

Let's pass it to the setup method in execute(...) so we can use it when creating the distribution:

RequestMetricSupport.setup(ctx, REQUEST_METRICS_SET, meterIdPrefixFunction, false,
                           successFunction != null ? successFunction::test
                                                   : ctx.options().successFunction(),
                           distributionStatisticConfig);

In RequestMetricSupport

private static void onRequest(
        RequestLog log, MeterIdPrefixFunction meterIdPrefixFunction, boolean server,
        SuccessFunction successFunction, DistributionStatisticConfig distStatCfg) { ...}

private static void onResponse(
        RequestLog log, MeterIdPrefixFunction meterIdPrefixFunction, boolean server,
        SuccessFunction successFunction, DistributionStatisticConfig distStatCfg) {
        ...
        new DefaultClientRequestMetrics(distStatCfg);
        ...
        new DefaultServiceRequestMetrics(distStatCfg);
        ...
    }

@minwoox I looked into DefaultClientRequestMetrics class but it seems like there is no injection point as of now.
Because the constructor of the class calls MoreMeters.newTimer() but to pass given distStatCfg I need to change current implementation of newTimer().
That's why I tried to use setter of MoreMeters.

If you meant that I do modify newTimer method signature and its logic, just let me know. I will do it :)

@@ -36,6 +38,9 @@ public abstract class AbstractMetricCollectingBuilder {
@Nullable
private BiPredicate<? super RequestContext, ? super RequestLog> successFunction;

@Nullable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Nullable

/**
* Returns the {@code distributionStatisticConfig}.
*/
@Nullable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Nullable

# Conflicts:
#	core/src/main/java/com/linecorp/armeria/internal/common/metric/RequestMetricSupport.java
#	core/src/main/java/com/linecorp/armeria/server/metric/MetricCollectingService.java
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.

Left only minor comments. I think it's almost done. 😄


AbstractMetricCollectingClient(
Client<I, O> delegate, MeterIdPrefixFunction meterIdPrefixFunction,
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction) {
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction,
@Nullable 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.

Suggested change
@Nullable DistributionStatisticConfig distributionStatisticConfig) {
DistributionStatisticConfig distributionStatisticConfig) {

@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction) {
super(delegate, meterIdPrefixFunction, successFunction);
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction,
@Nullable 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.

Suggested change
@Nullable DistributionStatisticConfig distributionStatisticConfig) {
DistributionStatisticConfig distributionStatisticConfig) {

@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction) {
super(delegate, meterIdPrefixFunction, successFunction);
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction,
@Nullable 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.

Suggested change
@Nullable DistributionStatisticConfig distributionStatisticConfig) {
DistributionStatisticConfig distributionStatisticConfig) {

Comment on lines 1393 to 1402
* DistributionStatisticConfig.builder()
* .percentilesHistogram(false)
* .sla()
* .percentiles(PERCENTILES)
* .percentilePrecision(2)
* .minimumExpectedValue(1L)
* .maximumExpectedValue(Long.MAX_VALUE)
* .expiry(Duration.ofMinutes(3))
* .bufferLength(3)
* .build();
Copy link
Member

Choose a reason for hiding this comment

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

It seems like some of the methods are deprecated. Could you fix it, please? 🙏

requireNonNull(registry, "registry");
requireNonNull(name, "name");
requireNonNull(tags, "tags");
requireNonNull(distStatCfgOverride, "distributionStatisticConfig");
Copy link
Member

Choose a reason for hiding this comment

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

nit: The name should be the same:

Suggested change
requireNonNull(distStatCfgOverride, "distributionStatisticConfig");
requireNonNull(distStatCfgOverride, "distStatCfgOverride");

Also, how about removing Override? If you worry about naming the same with the field, we might rename it to distStatsConfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!
Following your advice, I will change the name of the field to distStatsConfig and same for the string "distStatsConfig".

requireNonNull(registry, "registry");
requireNonNull(name, "name");
requireNonNull(tags, "tags");
requireNonNull(distStatCfgOverride, "distributionStatisticConfig");
Copy link
Member

Choose a reason for hiding this comment

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

ditto


MetricCollectingService(HttpService delegate,
MeterIdPrefixFunction meterIdPrefixFunction,
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction) {
@Nullable BiPredicate<? super RequestContext, ? super RequestLog> successFunction,
@Nullable 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.

Suggested change
@Nullable DistributionStatisticConfig distributionStatisticConfig) {
DistributionStatisticConfig distributionStatisticConfig) {

RequestMetricSupport.setup(ctx, REQUEST_METRICS_SET, meterIdPrefixFunction, false,
SuccessFunction.ofDefault());
SuccessFunction.ofDefault(), distributionStatisticConfig);
Copy link
Member

Choose a reason for hiding this comment

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

Let's inline:

Suggested change
SuccessFunction.ofDefault(), distributionStatisticConfig);
SuccessFunction.ofDefault(), DEFAULT_DIST_STAT_CFG);

RequestMetricSupport.setup(ctx, REQUEST_METRICS_SET, meterIdPrefixFunction, true,
SuccessFunction.ofDefault());
SuccessFunction.ofDefault(), distributionStatisticConfig);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SuccessFunction.ofDefault(), distributionStatisticConfig);
SuccessFunction.ofDefault(), DEFAULT_DIST_STAT_CFG);

Please also fix the below changes as well. 😉

Comment on lines 27 to 32
.serviceLevelObjectives()
.percentiles(
0, 0.5, 0.75, 0.9, 0.95, 0.98, 0.99, 0.999, 1.0)
.percentilePrecision(2)
.minimumExpectedValue(1.0)
.maximumExpectedValue(Double.MAX_VALUE)
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 replaced deprecated methods as you mentioned here
Does it make sense to you?
@minwoox

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it looks good! 👍

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.

Left only minor comments. Thanks @echo304! 👍 👍

super(delegate);
this.meterIdPrefixFunction = requireNonNull(meterIdPrefixFunction, "meterIdPrefixFunction");
this.successFunction = successFunction;
this.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.

Let's add requireNonNull for consistency.

Comment on lines 1044 to 1050
* .percentilesHistogram(false)
* .sla()
* .percentiles(PERCENTILES)
* .percentilePrecision(2)
* .minimumExpectedValue(1L)
* .maximumExpectedValue(Long.MAX_VALUE)
* .expiry(Duration.ofMinutes(3))
Copy link
Member

Choose a reason for hiding this comment

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

It seems like we should also fix this. 😉

super(delegate);
this.meterIdPrefixFunction = requireNonNull(meterIdPrefixFunction, "meterIdPrefixFunction");
this.successFunction = successFunction;
this.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.

ditto

RequestMetricSupport.setup(sctx, REQUEST_METRICS_SET,
MeterIdPrefixFunction.ofDefault("foo"), true,
SuccessFunction.ofDefault());
SuccessFunction.ofDefault(), distributionStatisticConfig);
Copy link
Member

Choose a reason for hiding this comment

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

Let's just inline. 😉

@@ -388,7 +391,7 @@ void serviceAndClientContext() {
.build();
RequestMetricSupport.setup(cctx, AttributeKey.valueOf("differentKey"),
MeterIdPrefixFunction.ofDefault("bar"), false,
SuccessFunction.ofDefault());
SuccessFunction.ofDefault(), distributionStatisticConfig);
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -439,12 +442,15 @@ void customSuccessFunction() {
.build();

final MeterIdPrefixFunction meterIdPrefixFunction = MeterIdPrefixFunction.ofDefault("foo");
final DistributionStatisticConfig distributionStatisticConfig = DEFAULT_DIST_STAT_CFG;
Copy link
Member

Choose a reason for hiding this comment

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

ditto

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.

Left only minor comments. Thanks @echo304! 👍 👍

@codecov
Copy link

codecov bot commented Jul 29, 2023

Codecov Report

Attention: Patch coverage is 90.10989% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 74.05%. Comparing base (0ab1721) to head (a7388cc).
Report is 1 commits behind head on main.

Files Patch % Lines
...com/linecorp/armeria/common/metric/MoreMeters.java 80.76% 5 Missing ⚠️
...lient/metric/MetricCollectingRpcClientBuilder.java 50.00% 2 Missing ⚠️
...a/client/metric/MetricCollectingClientBuilder.java 66.66% 1 Missing ⚠️
.../server/metric/MetricCollectingServiceBuilder.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4829      +/-   ##
============================================
+ Coverage     74.03%   74.05%   +0.01%     
- Complexity    20854    20865      +11     
============================================
  Files          1807     1808       +1     
  Lines         76754    76790      +36     
  Branches       9790     9792       +2     
============================================
+ Hits          56827    56865      +38     
  Misses        15301    15301              
+ Partials       4626     4624       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ikhoon
Copy link
Contributor

ikhoon commented Jul 31, 2023

Could you add more tests for DistributionStatisticConfig set via FlagsProvider and AbstractMetricCollectingBuilder?

* DistributionStatisticConfig.builder()
* .percentilesHistogram(false)
* .serviceLevelObjectives()
* .percentiles(PERCENTILES)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we inline PERCENTILES to show the actual value?

* DistributionStatisticConfig.builder()
* .percentilesHistogram(false)
* .serviceLevelObjectives()
* .percentiles(PERCENTILES)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we inline PERCENTILES to show the actual value?

.expiry(Duration.ofMinutes(3))
.bufferLength(3)
.build();
private static volatile DistributionStatisticConfig distStatCfg = Flags.distributionStatisticConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static volatile DistributionStatisticConfig distStatCfg = Flags.distributionStatisticConfig();
private static volatile DistributionStatisticConfig defaultDistStatCfg = Flags.distributionStatisticConfig();

@ikhoon ikhoon added this to the 1.25.0 milestone Jul 31, 2023
@ikhoon
Copy link
Contributor

ikhoon commented Jul 31, 2023

Please check the lint failure.

requireNonNull(registry, "registry");
requireNonNull(name, "name");
requireNonNull(tags, "tags");
requireNonNull(distStatsConfig, "distStatCfg");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
requireNonNull(distStatsConfig, "distStatCfg");
requireNonNull(distStatsConfig, "distStatsConfig");

requireNonNull(registry, "registry");
requireNonNull(name, "name");
requireNonNull(tags, "tags");
requireNonNull(distStatsConfig, "distStatCfg");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
requireNonNull(distStatsConfig, "distStatCfg");
requireNonNull(distStatsConfig, "distStatsConfig");

assertThat(abstractMetricCollectingBuilder.distributionStatisticConfig())
.isEqualTo(distConfig);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add an EOL character?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Left two comments 🙇

DefaultClientRequestMetrics(MeterRegistry parent, MeterIdPrefix idPrefix) {
super(parent, idPrefix);
DefaultClientRequestMetrics(MeterRegistry parent, MeterIdPrefix idPrefix,
DistributionStatisticConfig distributionStatisticConfig) {
Copy link
Contributor

@jrhee17 jrhee17 Aug 14, 2023

Choose a reason for hiding this comment

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

Shouldn't we also use this distributionStatisticConfig for timers/distributions in this class?

connectionAcquisitionDuration = newTimer(
parent, idPrefix.name("connection.acquisition.duration"), idPrefix.tags());
dnsResolutionDuration = newTimer(
parent, idPrefix.name("dns.resolution.duration"), idPrefix.tags());
socketConnectDuration = newTimer(
parent, idPrefix.name("socket.connect.duration"), idPrefix.tags());
pendingAcquisitionDuration = newTimer(
parent, idPrefix.name("pending.acquisition.duration"), idPrefix.tags());

public DistributionSummary successAttempts() {
if (successAttempts != null) {
return successAttempts;
}
return successAttempts = newDistributionSummary(parent,
idPrefix.name("actual.requests.attempts"),
idPrefix.tags("result", "success"));
}
@Override
public DistributionSummary failureAttempts() {
if (failureAttempts != null) {
return failureAttempts;
}
return failureAttempts = newDistributionSummary(parent,
idPrefix.name("actual.requests.attempts"),
idPrefix.tags("result", "failure"));
}

/**
* Defines a custom {@link DistributionStatisticConfig} to use for the distribution config.
*/
public AbstractMetricCollectingBuilder distributionStatisticConfig(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also override this method in child classes?

i.e. the following won't compile:

MetricCollectingClient.builder(MeterIdPrefixFunction.ofDefault("armeria"))
                      .distributionStatisticConfig(DistributionStatisticConfig.DEFAULT)
                      .newDecorator()

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't our builder test (com.linecorp.armeria.OverriddenBuilderMethodsReturnTypeTest) catch this issue automatically? Let's make sure this PR is failed by it first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't our builder test (com.linecorp.armeria.OverriddenBuilderMethodsReturnTypeTest) catch this issue automatically?

The builder isn't final 😅

@minwoox minwoox modified the milestones: 1.25.0, 1.26.0 Aug 18, 2023
@minwoox minwoox modified the milestones: 1.26.0, 1.27.0 Oct 11, 2023
@ikhoon ikhoon modified the milestones: 1.27.0, 1.28.0 Jan 16, 2024
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Nice work! 🚀🚀

@jrhee17 jrhee17 merged commit 9b936c6 into line:main Apr 2, 2024
18 checks passed
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.

Provide a way to set DistributionSummary config via builder
5 participants