|
14 | 14 | import org.elasticsearch.cluster.node.DiscoveryNode; |
15 | 15 | import org.elasticsearch.common.blobstore.BlobContainer; |
16 | 16 | import org.elasticsearch.common.blobstore.BlobPath; |
17 | | -import org.elasticsearch.common.blobstore.BlobStore; |
18 | 17 | import org.elasticsearch.common.blobstore.OperationPurpose; |
19 | 18 | import org.elasticsearch.common.bytes.BytesArray; |
20 | 19 | import org.elasticsearch.common.collect.Iterators; |
|
23 | 22 | import org.elasticsearch.plugins.PluginsService; |
24 | 23 | import org.elasticsearch.repositories.RepositoriesService; |
25 | 24 | import org.elasticsearch.repositories.blobstore.BlobStoreRepository; |
| 25 | +import org.elasticsearch.repositories.blobstore.RequestedRangeNotSatisfiedException; |
26 | 26 | import org.elasticsearch.repositories.s3.S3BlobStore.Operation; |
27 | 27 | import org.elasticsearch.rest.RestStatus; |
28 | 28 | import org.elasticsearch.telemetry.Measurement; |
|
39 | 39 |
|
40 | 40 | import static org.elasticsearch.repositories.RepositoriesMetrics.HTTP_REQUEST_TIME_IN_MICROS_HISTOGRAM; |
41 | 41 | import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_EXCEPTIONS_HISTOGRAM; |
| 42 | +import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_EXCEPTIONS_REQUEST_RANGE_NOT_SATISFIED_TOTAL; |
42 | 43 | import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_EXCEPTIONS_TOTAL; |
43 | 44 | import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_OPERATIONS_TOTAL; |
44 | 45 | import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_REQUESTS_TOTAL; |
|
47 | 48 | import static org.elasticsearch.repositories.RepositoriesMetrics.METRIC_UNSUCCESSFUL_OPERATIONS_TOTAL; |
48 | 49 | import static org.elasticsearch.rest.RestStatus.INTERNAL_SERVER_ERROR; |
49 | 50 | import static org.elasticsearch.rest.RestStatus.NOT_FOUND; |
| 51 | +import static org.elasticsearch.rest.RestStatus.REQUESTED_RANGE_NOT_SATISFIED; |
50 | 52 | import static org.elasticsearch.rest.RestStatus.TOO_MANY_REQUESTS; |
51 | 53 | import static org.hamcrest.Matchers.equalTo; |
| 54 | +import static org.hamcrest.Matchers.instanceOf; |
52 | 55 |
|
53 | 56 | @SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") |
54 | 57 | // Need to set up a new cluster for each test because cluster settings use randomized authentication settings |
@@ -80,22 +83,29 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { |
80 | 83 | .build(); |
81 | 84 | } |
82 | 85 |
|
83 | | - public void testMetricsWithErrors() throws IOException { |
84 | | - final String repository = createRepository(randomRepositoryName()); |
85 | | - |
86 | | - final String dataNodeName = internalCluster().getNodeNameThat(DiscoveryNode::canContainData); |
87 | | - final var blobStoreRepository = (BlobStoreRepository) internalCluster().getInstance(RepositoriesService.class, dataNodeName) |
88 | | - .repository(repository); |
89 | | - final BlobStore blobStore = blobStoreRepository.blobStore(); |
90 | | - final TestTelemetryPlugin plugin = internalCluster().getInstance(PluginsService.class, dataNodeName) |
| 86 | + private static TestTelemetryPlugin getPlugin(String dataNodeName) { |
| 87 | + var plugin = internalCluster().getInstance(PluginsService.class, dataNodeName) |
91 | 88 | .filterPlugins(TestTelemetryPlugin.class) |
92 | 89 | .findFirst() |
93 | 90 | .orElseThrow(); |
94 | | - |
95 | 91 | plugin.resetMeter(); |
| 92 | + return plugin; |
| 93 | + } |
| 94 | + |
| 95 | + private static BlobContainer getBlobContainer(String dataNodeName, String repository) { |
| 96 | + final var blobStoreRepository = (BlobStoreRepository) internalCluster().getInstance(RepositoriesService.class, dataNodeName) |
| 97 | + .repository(repository); |
| 98 | + return blobStoreRepository.blobStore().blobContainer(BlobPath.EMPTY.add(randomIdentifier())); |
| 99 | + } |
| 100 | + |
| 101 | + public void testMetricsWithErrors() throws IOException { |
| 102 | + final String repository = createRepository(randomRepositoryName()); |
| 103 | + |
| 104 | + final String dataNodeName = internalCluster().getNodeNameThat(DiscoveryNode::canContainData); |
| 105 | + final TestTelemetryPlugin plugin = getPlugin(dataNodeName); |
96 | 106 |
|
97 | 107 | final OperationPurpose purpose = randomFrom(OperationPurpose.values()); |
98 | | - final BlobContainer blobContainer = blobStore.blobContainer(BlobPath.EMPTY.add(randomIdentifier())); |
| 108 | + final BlobContainer blobContainer = getBlobContainer(dataNodeName, repository); |
99 | 109 | final String blobName = randomIdentifier(); |
100 | 110 |
|
101 | 111 | // Put a blob |
@@ -132,6 +142,9 @@ public void testMetricsWithErrors() throws IOException { |
132 | 142 | assertThat(getLongHistogramValue(plugin, METRIC_EXCEPTIONS_HISTOGRAM, Operation.GET_OBJECT), equalTo(batch)); |
133 | 143 | assertThat(getLongHistogramValue(plugin, METRIC_THROTTLES_HISTOGRAM, Operation.GET_OBJECT), equalTo(batch)); |
134 | 144 | assertThat(getNumberOfMeasurements(plugin, HTTP_REQUEST_TIME_IN_MICROS_HISTOGRAM, Operation.GET_OBJECT), equalTo(batch)); |
| 145 | + |
| 146 | + // Make sure we don't hit the request range not satisfied counters |
| 147 | + assertThat(getLongCounterValue(plugin, METRIC_EXCEPTIONS_REQUEST_RANGE_NOT_SATISFIED_TOTAL, Operation.GET_OBJECT), equalTo(0L)); |
135 | 148 | } |
136 | 149 |
|
137 | 150 | // List retry exhausted |
@@ -166,6 +179,39 @@ public void testMetricsWithErrors() throws IOException { |
166 | 179 | assertThat(getNumberOfMeasurements(plugin, HTTP_REQUEST_TIME_IN_MICROS_HISTOGRAM, Operation.DELETE_OBJECTS), equalTo(1L)); |
167 | 180 | } |
168 | 181 |
|
| 182 | + public void testMetricsForRequestRangeNotSatisfied() { |
| 183 | + final String repository = createRepository(randomRepositoryName()); |
| 184 | + final String dataNodeName = internalCluster().getNodeNameThat(DiscoveryNode::canContainData); |
| 185 | + final BlobContainer blobContainer = getBlobContainer(dataNodeName, repository); |
| 186 | + final TestTelemetryPlugin plugin = getPlugin(dataNodeName); |
| 187 | + |
| 188 | + final OperationPurpose purpose = randomFrom(OperationPurpose.values()); |
| 189 | + final String blobName = randomIdentifier(); |
| 190 | + |
| 191 | + for (int i = 0; i < randomIntBetween(1, 3); i++) { |
| 192 | + final long batch = i + 1; |
| 193 | + addErrorStatus(TOO_MANY_REQUESTS, TOO_MANY_REQUESTS, REQUESTED_RANGE_NOT_SATISFIED); |
| 194 | + try { |
| 195 | + blobContainer.readBlob(purpose, blobName).close(); |
| 196 | + } catch (Exception e) { |
| 197 | + assertThat(e, instanceOf(RequestedRangeNotSatisfiedException.class)); |
| 198 | + } |
| 199 | + |
| 200 | + assertThat(getLongCounterValue(plugin, METRIC_REQUESTS_TOTAL, Operation.GET_OBJECT), equalTo(3 * batch)); |
| 201 | + assertThat(getLongCounterValue(plugin, METRIC_OPERATIONS_TOTAL, Operation.GET_OBJECT), equalTo(batch)); |
| 202 | + assertThat(getLongCounterValue(plugin, METRIC_UNSUCCESSFUL_OPERATIONS_TOTAL, Operation.GET_OBJECT), equalTo(batch)); |
| 203 | + assertThat(getLongCounterValue(plugin, METRIC_EXCEPTIONS_TOTAL, Operation.GET_OBJECT), equalTo(batch)); |
| 204 | + assertThat(getLongHistogramValue(plugin, METRIC_EXCEPTIONS_HISTOGRAM, Operation.GET_OBJECT), equalTo(batch)); |
| 205 | + assertThat( |
| 206 | + getLongCounterValue(plugin, METRIC_EXCEPTIONS_REQUEST_RANGE_NOT_SATISFIED_TOTAL, Operation.GET_OBJECT), |
| 207 | + equalTo(batch) |
| 208 | + ); |
| 209 | + assertThat(getLongCounterValue(plugin, METRIC_THROTTLES_TOTAL, Operation.GET_OBJECT), equalTo(2 * batch)); |
| 210 | + assertThat(getLongHistogramValue(plugin, METRIC_THROTTLES_HISTOGRAM, Operation.GET_OBJECT), equalTo(2 * batch)); |
| 211 | + assertThat(getNumberOfMeasurements(plugin, HTTP_REQUEST_TIME_IN_MICROS_HISTOGRAM, Operation.GET_OBJECT), equalTo(batch)); |
| 212 | + } |
| 213 | + } |
| 214 | + |
169 | 215 | private void addErrorStatus(RestStatus... statuses) { |
170 | 216 | errorStatusQueue.addAll(Arrays.asList(statuses)); |
171 | 217 | } |
|
0 commit comments