-
Notifications
You must be signed in to change notification settings - Fork 896
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
Changes from 4 commits
6b103e0
76a7461
524f005
55f0616
7c26ec9
b706bec
fd44022
f30bb03
e8fd096
ddba25c
daff026
27c59c9
08b756d
85788da
b18280c
b8cff4a
969c5d4
755c120
ff7fae8
337c09c
c664ebf
a7388cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -73,6 +73,7 @@ | |||||
|
||||||
import io.micrometer.core.instrument.MeterRegistry; | ||||||
import io.micrometer.core.instrument.Metrics; | ||||||
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||||||
import io.netty.buffer.ByteBufAllocator; | ||||||
import io.netty.channel.ChannelOption; | ||||||
import io.netty.channel.EventLoopGroup; | ||||||
|
@@ -386,6 +387,9 @@ public final class Flags { | |||||
getValue(FlagsProvider::defaultUnhandledExceptionsReportIntervalMillis, | ||||||
"defaultUnhandledExceptionsReportIntervalMillis", value -> value >= 0); | ||||||
|
||||||
private static final DistributionStatisticConfig DISTRIBUTION_STATISTIC_CONFIG = | ||||||
getValue(FlagsProvider::distributionStatisticConfig, "distributionStatisticConfig"); | ||||||
|
||||||
/** | ||||||
* Returns the specification of the {@link Sampler} that determines whether to retain the stack | ||||||
* trace of the exceptions that are thrown frequently by Armeria. A sampled exception will have the stack | ||||||
|
@@ -1343,6 +1347,16 @@ public static long defaultUnhandledExceptionsReportIntervalMillis() { | |||||
return DEFAULT_UNHANDLED_EXCEPTIONS_REPORT_INTERVAL_MILLIS; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns the {@link DistributionStatisticConfig} where armeria utilizes. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* <p>The default value of this flag is {@link DistributionStatisticConfig#DEFAULT}</p> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs an update. We could paste some code here:
|
||||||
*/ | ||||||
@UnstableApi | ||||||
public static DistributionStatisticConfig distributionStatisticConfig() { | ||||||
return DISTRIBUTION_STATISTIC_CONFIG; | ||||||
} | ||||||
|
||||||
@Nullable | ||||||
private static String nullableCaffeineSpec(Function<FlagsProvider, String> method, String flagName) { | ||||||
return caffeineSpec(method, flagName, true); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ | |
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
import io.netty.channel.ChannelOption; | ||
import io.netty.channel.EventLoopGroup; | ||
import io.netty.handler.codec.http2.Http2Exception; | ||
|
@@ -1003,4 +1004,15 @@ default MeterRegistry meterRegistry() { | |
default Long defaultUnhandledExceptionsReportIntervalMillis() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the {@link DistributionStatisticConfig} where armeria utilizes. | ||
* | ||
* <p>The default value of this flag is {@link DistributionStatisticConfig#DEFAULT}</p> | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto - please keep in sync with |
||
@Nullable | ||
@UnstableApi | ||
default DistributionStatisticConfig distributionStatisticConfig() { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,6 +26,8 @@ | |||
import com.linecorp.armeria.common.logging.RequestLog; | ||||
import com.linecorp.armeria.server.ServerBuilder; | ||||
|
||||
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||||
|
||||
/** | ||||
* Builds an implementing class of {@link AbstractMetricCollectingBuilder} instance. | ||||
*/ | ||||
|
@@ -36,6 +38,9 @@ public abstract class AbstractMetricCollectingBuilder { | |||
@Nullable | ||||
private BiPredicate<? super RequestContext, ? super RequestLog> successFunction; | ||||
|
||||
@Nullable | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
private DistributionStatisticConfig distributionStatisticConfig; | ||||
|
||||
/** | ||||
* Creates a new instance with the specified {@link MeterIdPrefixFunction}. | ||||
*/ | ||||
|
@@ -83,4 +88,22 @@ public AbstractMetricCollectingBuilder successFunction( | |||
this.successFunction = requireNonNull(successFunction, "successFunction"); | ||||
return this; | ||||
} | ||||
|
||||
/** | ||||
* Returns the {@code distributionStatisticConfig}. | ||||
*/ | ||||
@Nullable | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
protected final DistributionStatisticConfig distributionStatisticConfig() { | ||||
return distributionStatisticConfig; | ||||
} | ||||
|
||||
/** | ||||
* Defines a custom {@link DistributionStatisticConfig} to use for the distribution config. | ||||
*/ | ||||
public AbstractMetricCollectingBuilder distributionStatisticConfig( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't our builder test ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The builder isn't final 😅 armeria/it/builders/src/test/java/com/linecorp/armeria/OverriddenBuilderMethodsReturnTypeTest.java Line 51 in 5df7f16
|
||||
DistributionStatisticConfig distributionStatisticConfig) { | ||||
this.distributionStatisticConfig = requireNonNull(distributionStatisticConfig, | ||||
"distributionStatisticConfig"); | ||||
return this; | ||||
} | ||||
} |
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.
We don't use
DistributionStatisticConfig.DEFAULT
as default.We use
from
MoreMeters.distStatCfg
as default instead. So we need to:MoreMeters.DEFAULT_DIST_STAT_CFG
Flags.distributionStatisticConfig()
todistStatCfg
.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 theAbstractMetricCollectingBuilder
:The
distributionStatisticConfig
will be passed to the constructor ofMetricCollectingClient
andMetricCollectingService
and it will be also passed toRequestMetricSupport.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 inMoreMeters
. We can move it toRequestMetricSupport
as a private method.)Please let me know if there's anything unclear. 😄
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.
Thanks for the feedback!
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.
@minwoox
I implemented as you mentioned above but setting
MoreMeters.distStatCfg
fromFlags.distributionStatisticConfig()
doesn't work well on some tests.It complains that
MoteMeters.distStatCfg
isnull
. So I checked the failed test from local environment and I got this.In theory,
Flags.DISTRIBUTION_STATISTIC_CONFIG
should be populated byDefaultFlagsProvider.distributionStatisticConfig()
and thusMoreMeters.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?
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.
Sorry about the problem. 😅
The
DEFAULT_DIST_STAT_CFG
is not instantiated beforedefaultDistributionStatisticConfig()
is called. 😓Let's move it to another class: