|
6 | 6 | * Side Public License, v 1.
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -package org.elasticsearch.indices.breaker; |
| 9 | +package org.elasticsearch.indices.memory.breaker; |
10 | 10 |
|
11 | 11 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
12 | 12 | import org.elasticsearch.common.breaker.CircuitBreakingException;
|
13 | 13 | import org.elasticsearch.common.settings.Settings;
|
14 | 14 | import org.elasticsearch.common.unit.ByteSizeUnit;
|
| 15 | +import org.elasticsearch.indices.breaker.CircuitBreakerMetrics; |
| 16 | +import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService; |
15 | 17 | import org.elasticsearch.plugins.Plugin;
|
16 | 18 | import org.elasticsearch.plugins.PluginsService;
|
17 | 19 | import org.elasticsearch.rest.RestStatus;
|
18 | 20 | import org.elasticsearch.telemetry.Measurement;
|
19 |
| -import org.elasticsearch.telemetry.RecordingInstruments; |
20 |
| -import org.elasticsearch.telemetry.RecordingMeterRegistry; |
21 | 21 | import org.elasticsearch.telemetry.TestTelemetryPlugin;
|
22 |
| -import org.elasticsearch.telemetry.metric.LongCounter; |
23 |
| -import org.elasticsearch.telemetry.metric.MeterRegistry; |
24 | 22 | import org.elasticsearch.test.ESIntegTestCase;
|
25 | 23 | import org.hamcrest.Matchers;
|
| 24 | +import org.junit.After; |
26 | 25 |
|
27 |
| -import java.util.Arrays; |
28 | 26 | import java.util.Collection;
|
29 | 27 | import java.util.List;
|
30 | 28 | import java.util.Map;
|
|
41 | 39 | import static org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING;
|
42 | 40 |
|
43 | 41 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, supportsDedicatedMasters = true)
|
44 |
| -public class HierarchyCircuitBreakerTelemetryTests extends ESIntegTestCase { |
| 42 | +public class HierarchyCircuitBreakerTelemetryIT extends ESIntegTestCase { |
45 | 43 |
|
46 | 44 | @Override
|
47 | 45 | protected Collection<Class<? extends Plugin>> nodePlugins() {
|
48 |
| - return List.of(TestCircuitBreakerTelemetryPlugin.class); |
49 |
| - } |
50 |
| - |
51 |
| - public static class TestCircuitBreakerTelemetryPlugin extends TestTelemetryPlugin { |
52 |
| - protected final MeterRegistry meter = new RecordingMeterRegistry() { |
53 |
| - private final LongCounter tripCount = new RecordingInstruments.RecordingLongCounter( |
54 |
| - CircuitBreakerMetrics.ES_BREAKER_TRIP_COUNT_TOTAL, |
55 |
| - recorder |
56 |
| - ) { |
57 |
| - @Override |
58 |
| - public void incrementBy(long inc) { |
59 |
| - throw new UnsupportedOperationException(); |
60 |
| - } |
61 |
| - |
62 |
| - @Override |
63 |
| - public void incrementBy(long inc, Map<String, Object> attributes) { |
64 |
| - throw new UnsupportedOperationException(); |
65 |
| - } |
66 |
| - }; |
67 |
| - |
68 |
| - @Override |
69 |
| - protected LongCounter buildLongCounter(String name, String description, String unit) { |
70 |
| - if (name.equals(tripCount.getName())) { |
71 |
| - return tripCount; |
72 |
| - } |
73 |
| - throw new IllegalArgumentException("Unknown counter metric name [" + name + "]"); |
74 |
| - } |
75 |
| - |
76 |
| - @Override |
77 |
| - public LongCounter registerLongCounter(String name, String description, String unit) { |
78 |
| - assertCircuitBreakerName(name); |
79 |
| - return super.registerLongCounter(name, description, unit); |
80 |
| - } |
81 |
| - |
82 |
| - @Override |
83 |
| - public LongCounter getLongCounter(String name) { |
84 |
| - assertCircuitBreakerName(name); |
85 |
| - return super.getLongCounter(name); |
86 |
| - } |
87 |
| - |
88 |
| - private void assertCircuitBreakerName(final String name) { |
89 |
| - assertThat(name, Matchers.oneOf(CircuitBreakerMetrics.ES_BREAKER_TRIP_COUNT_TOTAL)); |
90 |
| - } |
91 |
| - }; |
| 46 | + return List.of(TestTelemetryPlugin.class); |
92 | 47 | }
|
93 | 48 |
|
94 | 49 | public void testCircuitBreakerTripCountMetric() {
|
@@ -142,37 +97,29 @@ public void testCircuitBreakerTripCountMetric() {
|
142 | 97 | fail("Expected exception not thrown");
|
143 | 98 | }
|
144 | 99 |
|
145 |
| - private List<Measurement> getMeasurements(String dataNodeName) { |
146 |
| - final TestTelemetryPlugin dataNodeTelemetryPlugin = internalCluster().getInstance(PluginsService.class, dataNodeName) |
147 |
| - .filterPlugins(TestCircuitBreakerTelemetryPlugin.class) |
| 100 | + @After |
| 101 | + public void resetClusterSetting() { |
| 102 | + final var circuitBreakerSettings = Settings.builder() |
| 103 | + .putNull(FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING.getKey()) |
| 104 | + .putNull(FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey()) |
| 105 | + .putNull(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey()) |
| 106 | + .putNull(REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey()) |
| 107 | + .putNull(IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey()) |
| 108 | + .putNull(IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey()) |
| 109 | + .putNull(TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING.getKey()) |
| 110 | + .putNull(HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.getKey()); |
| 111 | + updateClusterSettings(circuitBreakerSettings); |
| 112 | + } |
| 113 | + |
| 114 | + private List<Measurement> getMeasurements(String nodeName) { |
| 115 | + final TestTelemetryPlugin telemetryPlugin = internalCluster().getInstance(PluginsService.class, nodeName) |
| 116 | + .filterPlugins(TestTelemetryPlugin.class) |
148 | 117 | .toList()
|
149 | 118 | .get(0);
|
150 | 119 | return Measurement.combine(
|
151 |
| - Stream.of(dataNodeTelemetryPlugin.getLongCounterMeasurement(CircuitBreakerMetrics.ES_BREAKER_TRIP_COUNT_TOTAL).stream()) |
| 120 | + Stream.of(telemetryPlugin.getLongCounterMeasurement(CircuitBreakerMetrics.ES_BREAKER_TRIP_COUNT_TOTAL).stream()) |
152 | 121 | .flatMap(Function.identity())
|
153 | 122 | .toList()
|
154 | 123 | );
|
155 | 124 | }
|
156 |
| - |
157 |
| - // Make sure circuit breaker telemetry on trip count reports the same values as circuit breaker stats |
158 |
| - private void assertCircuitBreakerTripCount( |
159 |
| - final HierarchyCircuitBreakerService circuitBreakerService, |
160 |
| - final String circuitBreakerName, |
161 |
| - int firstBytesEstimate, |
162 |
| - int secondBytesEstimate, |
163 |
| - long expectedTripCountValue |
164 |
| - ) { |
165 |
| - try { |
166 |
| - circuitBreakerService.getBreaker(circuitBreakerName).addEstimateBytesAndMaybeBreak(firstBytesEstimate, randomAlphaOfLength(5)); |
167 |
| - circuitBreakerService.getBreaker(circuitBreakerName).addEstimateBytesAndMaybeBreak(secondBytesEstimate, randomAlphaOfLength(5)); |
168 |
| - } catch (final CircuitBreakingException cbex) { |
169 |
| - final CircuitBreakerStats circuitBreakerStats = Arrays.stream(circuitBreakerService.stats().getAllStats()) |
170 |
| - .filter(stats -> circuitBreakerName.equals(stats.getName())) |
171 |
| - .findAny() |
172 |
| - .get(); |
173 |
| - assertThat(circuitBreakerService.getBreaker(circuitBreakerName).getTrippedCount(), Matchers.equalTo(expectedTripCountValue)); |
174 |
| - assertThat(circuitBreakerStats.getTrippedCount(), Matchers.equalTo(expectedTripCountValue)); |
175 |
| - } |
176 |
| - } |
177 |
| - |
178 | 125 | }
|
0 commit comments