Skip to content

Commit b796ce2

Browse files
authored
Add dedicated feature flag for breakdown_metrics (#743)
1 parent d838bb4 commit b796ce2

File tree

5 files changed

+64
-7
lines changed

5 files changed

+64
-7
lines changed

apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ public class CoreConfiguration extends ConfigurationOptionProvider {
354354
"----\n")
355355
.buildWithDefault("co.elastic.apm.agent.*");
356356

357+
private final ConfigurationOption<Boolean> breakdownMetrics = ConfigurationOption.booleanOption()
358+
.key("breakdown_metrics")
359+
.configurationCategory(CORE_CATEGORY)
360+
.description("Disables the collection of breakdown metrics (`span.self_time`)")
361+
.buildWithDefault(true);
362+
357363
public boolean isActive() {
358364
return active.get();
359365
}
@@ -440,4 +446,8 @@ public TimeDuration getTraceMethodsDurationThreshold() {
440446
public Map<String, String> getGlobalLabels() {
441447
return globalLabels.get();
442448
}
449+
450+
public boolean isBreakdownMetricsEnabled() {
451+
return breakdownMetrics.get();
452+
}
443453
}

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package co.elastic.apm.agent.impl.transaction;
2626

27+
import co.elastic.apm.agent.configuration.CoreConfiguration;
2728
import co.elastic.apm.agent.impl.ElasticApmTracer;
2829
import co.elastic.apm.agent.impl.context.AbstractContext;
2930
import co.elastic.apm.agent.matcher.WildcardMatcher;
@@ -117,7 +118,9 @@ public long getDuration() {
117118
public AbstractSpan(ElasticApmTracer tracer) {
118119
super(tracer);
119120
traceContext = TraceContext.with64BitId(this.tracer);
120-
collectBreakdownMetrics = !WildcardMatcher.isAnyMatch(tracer.getConfig(ReporterConfiguration.class).getDisableMetrics(), "span.self_time");
121+
boolean selfTimeCollectionEnabled = !WildcardMatcher.isAnyMatch(tracer.getConfig(ReporterConfiguration.class).getDisableMetrics(), "span.self_time");
122+
boolean breakdownMetricsEnabled = tracer.getConfig(CoreConfiguration.class).isBreakdownMetricsEnabled();
123+
collectBreakdownMetrics = selfTimeCollectionEnabled && breakdownMetricsEnabled;
121124
}
122125

123126
public boolean isReferenced() {

apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ public class ReporterConfiguration extends ConfigurationOptionProvider {
162162
"If the name of a metric matches any of the wildcard expressions, it will not be collected.\n" +
163163
"Example: `foo.*,bar.*`\n" +
164164
"\n" +
165-
"To disable all breakdown metric collection code paths, add `span.self_time` to the list.\n" +
166-
"\n" +
167165
WildcardMatcher.DOCUMENTATION)
168166
.dynamic(false)
169167
.buildWithDefault(Collections.<WildcardMatcher>emptyList());

apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import co.elastic.apm.agent.MockReporter;
2828
import co.elastic.apm.agent.MockTracer;
29+
import co.elastic.apm.agent.configuration.CoreConfiguration;
2930
import co.elastic.apm.agent.configuration.SpyConfiguration;
3031
import co.elastic.apm.agent.impl.sampling.ConstantSampler;
3132
import co.elastic.apm.agent.impl.transaction.Span;
@@ -43,6 +44,7 @@
4344
import java.util.Map;
4445

4546
import static org.assertj.core.api.Assertions.assertThat;
47+
import static org.mockito.Mockito.when;
4648

4749
class SpanTypeBreakdownTest {
4850

@@ -73,6 +75,25 @@ void testBreakdown_noSpans() {
7375
});
7476
}
7577

78+
/*
79+
* ██████████████████████████████
80+
* 10 20 30
81+
*/
82+
@Test
83+
void testBreakdown_disabled() {
84+
when(tracer.getConfig(CoreConfiguration.class).isBreakdownMetricsEnabled()).thenReturn(false);
85+
tracer.startTransaction(TraceContext.asRoot(), null, ConstantSampler.of(true), 0, getClass().getClassLoader())
86+
.withName("test")
87+
.withType("request")
88+
.end(30);
89+
tracer.getMetricRegistry().report(metricSets -> {
90+
assertThat(getTimer(metricSets, "span.self_time", "app", null)).isNull();
91+
assertThat(getTimer(metricSets, "span.self_time", "app", null)).isNull();
92+
assertThat(getTimer(metricSets, "transaction.duration", null, null).getTotalTimeUs()).isEqualTo(30);
93+
assertThat(metricSets.get(Labels.Mutable.of().transactionName("test").transactionType("request")).getCounters().get("transaction.breakdown.count")).isNull();
94+
});
95+
}
96+
7697
/*
7798
* ██████████░░░░░░░░░░██████████
7899
* └─────────██████████

docs/configuration.asciidoc

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Click on a key to get more information.
7373
** <<config-trace-methods>>
7474
** <<config-trace-methods-duration-threshold>>
7575
** <<config-boot-delegation-packages>>
76+
** <<config-breakdown-metrics>>
7677
* <<config-http>>
7778
** <<config-capture-body>>
7879
** <<config-capture-body-content-types>>
@@ -514,6 +515,26 @@ boot_delegation_packages=org.apache.karaf.jaas.boot, org.apache.karaf.jaas.boot.
514515
| `elastic.apm.boot_delegation_packages` | `boot_delegation_packages` | `ELASTIC_APM_BOOT_DELEGATION_PACKAGES`
515516
|============
516517

518+
[float]
519+
[[config-breakdown-metrics]]
520+
==== `breakdown_metrics`
521+
522+
Disables the collection of breakdown metrics (`span.self_time`)
523+
524+
525+
[options="header"]
526+
|============
527+
| Default | Type | Dynamic
528+
| `true` | Boolean | false
529+
|============
530+
531+
532+
[options="header"]
533+
|============
534+
| Java System Properties | Property file | Environment
535+
| `elastic.apm.breakdown_metrics` | `breakdown_metrics` | `ELASTIC_APM_BREAKDOWN_METRICS`
536+
|============
537+
517538
[[config-http]]
518539
=== HTTP configuration options
519540
[float]
@@ -1071,8 +1092,6 @@ Disables the collection of certain metrics.
10711092
If the name of a metric matches any of the wildcard expressions, it will not be collected.
10721093
Example: `foo.*,bar.*`
10731094

1074-
To disable all breakdown metric collection code paths, add `span.self_time` to the list.
1075-
10761095
This option supports the wildcard `*`, which matches zero or more characters.
10771096
Examples: `/foo/*/bar/*/baz*`, `*foo*`.
10781097
Matching is case insensitive by default.
@@ -1419,6 +1438,14 @@ The default unit for this option is `ms`
14191438
#
14201439
# boot_delegation_packages=co.elastic.apm.agent.*
14211440
1441+
# Disables the collection of breakdown metrics (`span.self_time`)
1442+
#
1443+
# This setting can not be changed at runtime. Changes require a restart of the application.
1444+
# Type: Boolean
1445+
# Default value: true
1446+
#
1447+
# breakdown_metrics=true
1448+
14221449
############################################
14231450
# HTTP #
14241451
############################################
@@ -1729,8 +1756,6 @@ The default unit for this option is `ms`
17291756
# If the name of a metric matches any of the wildcard expressions, it will not be collected.
17301757
# Example: `foo.*,bar.*`
17311758
#
1732-
# To disable all breakdown metric collection code paths, add `span.self_time` to the list.
1733-
#
17341759
# This option supports the wildcard `*`, which matches zero or more characters.
17351760
# Examples: `/foo/*/bar/*/baz*`, `*foo*`.
17361761
# Matching is case insensitive by default.

0 commit comments

Comments
 (0)