Skip to content

Commit 8f8a73c

Browse files
committed
feedback
1 parent e0bde89 commit 8f8a73c

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GcsRepositoryStatsCollector.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public long absoluteTimeInMillis() {
6565
public static final HttpResponseInterceptor METERING_INTERCEPTOR = response -> {
6666
var stats = getThreadLocal();
6767
var code = response.getStatusCode();
68-
stats.reqAtt += 1;
69-
stats.isLastReqSuccess = true;
68+
stats.requestAttempts += 1;
69+
stats.isLastRequestSucceed = true;
7070
if (((code >= 200 && code < 300) || code == 308 || code == 404) == false) {
71-
stats.reqErr += 1;
72-
stats.isLastReqSuccess = false;
71+
stats.requestError += 1;
72+
stats.isLastRequestSucceed = false;
7373
switch (code) {
74-
case 416 -> stats.reqErrRange += 1;
75-
case 429 -> stats.reqErrThrottle += 1;
74+
case 416 -> stats.requestRangeError += 1;
75+
case 429 -> stats.requestThrottle += 1;
7676
}
7777
}
7878
};
@@ -167,9 +167,6 @@ public void finishRunnable(OperationStats stats, IORunnable runnable) throws IOE
167167
}
168168
}
169169

170-
/**
171-
* Continue collecting metrics with given OperationStats. Useful for readers and writers.
172-
*/
173170
public void collectIORunnable(OperationPurpose purpose, StorageOperation operation, IORunnable runnable) throws IOException {
174171
var stats = initAndGetThreadLocal(purpose, operation);
175172
var t = timer.absoluteTimeInMillis();
@@ -193,9 +190,6 @@ public void collectRunnable(OperationPurpose purpose, StorageOperation operation
193190
}
194191
}
195192

196-
/**
197-
* Executes GCS Storage operation in a wrapper that stores metrics in ThreadLocal
198-
*/
199193
public <T> T collectIOSupplier(OperationPurpose purpose, StorageOperation operation, IOSupplier<T> blobFn) throws IOException {
200194
var t = timer.absoluteTimeInMillis();
201195
var stats = initAndGetThreadLocal(purpose, operation);
@@ -208,9 +202,6 @@ public <T> T collectIOSupplier(OperationPurpose purpose, StorageOperation operat
208202
}
209203
}
210204

211-
/**
212-
* Executes GCS Storage operation in a wrapper that stores metrics in ThreadLocal
213-
*/
214205
public <T> T collectSupplier(OperationPurpose purpose, StorageOperation operation, Supplier<T> blobFn) {
215206
var t = timer.absoluteTimeInMillis();
216207
var stats = initAndGetThreadLocal(purpose, operation);
@@ -224,28 +215,28 @@ public <T> T collectSupplier(OperationPurpose purpose, StorageOperation operatio
224215
}
225216

226217
private void collect(OperationStats stats) {
227-
if (stats.reqAtt == 0) {
218+
if (stats.requestAttempts == 0) {
228219
return; // nothing happened
229220
}
230221
var purpose = stats.purpose;
231222
var operation = stats.operation;
232-
var operationSuccess = stats.isLastReqSuccess ? 1 : 0;
233-
var operationErr = stats.isLastReqSuccess ? 0 : 1;
223+
var operationSuccess = stats.isLastRequestSucceed ? 1 : 0;
224+
var operationError = stats.isLastRequestSucceed ? 0 : 1;
234225
var collector = collectors.get(purpose).get(operation);
235226
assert collector != null;
236227
collector.operations.add(operationSuccess);
237-
collector.requests.add(stats.reqAtt);
228+
collector.requests.add(stats.requestAttempts);
238229

239230
var attr = telemetryAttributes.get(purpose).get(operation);
240231
assert attr != null;
241232
telemetry.operationCounter().incrementBy(operationSuccess, attr);
242-
telemetry.unsuccessfulOperationCounter().incrementBy(operationErr, attr);
243-
telemetry.requestCounter().incrementBy(stats.reqAtt, attr);
244-
telemetry.exceptionCounter().incrementBy(stats.reqErr, attr);
245-
telemetry.exceptionHistogram().record(stats.reqErr, attr);
246-
telemetry.throttleCounter().incrementBy(stats.reqErrThrottle, attr);
247-
telemetry.throttleHistogram().record(stats.reqErrThrottle, attr);
248-
telemetry.requestRangeNotSatisfiedExceptionCounter().incrementBy(stats.reqErrRange, attr);
233+
telemetry.unsuccessfulOperationCounter().incrementBy(operationError, attr);
234+
telemetry.requestCounter().incrementBy(stats.requestAttempts, attr);
235+
telemetry.exceptionCounter().incrementBy(stats.requestError, attr);
236+
telemetry.exceptionHistogram().record(stats.requestError, attr);
237+
telemetry.throttleCounter().incrementBy(stats.requestThrottle, attr);
238+
telemetry.throttleHistogram().record(stats.requestThrottle, attr);
239+
telemetry.requestRangeNotSatisfiedExceptionCounter().incrementBy(stats.requestRangeError, attr);
249240
telemetry.httpRequestTimeInMillisHistogram().record(stats.totalDuration, attr);
250241
}
251242

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/OperationStats.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ public class OperationStats {
2424
/**
2525
* true if last request is completed successfully
2626
*/
27-
boolean isLastReqSuccess;
27+
boolean isLastRequestSucceed;
2828

2929
/**
3030
* request attempts including retires and multi part requests
3131
*/
32-
int reqAtt;
32+
int requestAttempts;
3333

3434
/**
3535
* request errors, all unsuccessful request attempts {@code reqErr<=reqAtt}
3636
*/
37-
int reqErr;
37+
int requestError;
3838

3939
/**
4040
* request throttles (429), {@code reqErrThrottle<=reqErr}
4141
*/
42-
int reqErrThrottle;
42+
int requestThrottle;
4343

4444
/**
4545
* request range not satisfied error(416), only applicable for GetObject operations, {@code reqErrRange<=reqErr}
4646
*/
47-
int reqErrRange;
47+
int requestRangeError;
4848

4949
OperationStats(OperationPurpose purpose, StorageOperation operation) {
5050
this.purpose = purpose;
@@ -61,15 +61,15 @@ public String toString() {
6161
+ ", totalDuration="
6262
+ totalDuration
6363
+ ", isLastReqSuccess="
64-
+ isLastReqSuccess
64+
+ isLastRequestSucceed
6565
+ ", reqAtt="
66-
+ reqAtt
66+
+ requestAttempts
6767
+ ", reqErr="
68-
+ reqErr
68+
+ requestError
6969
+ ", reqErrThrottle="
70-
+ reqErrThrottle
70+
+ requestThrottle
7171
+ ", reqErrRange="
72-
+ reqErrRange
72+
+ requestRangeError
7373
+ '}';
7474
}
7575
}

0 commit comments

Comments
 (0)