Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class AbstractComputationObserver<R, P> {
protected static final String STATUS_TAG_NAME = "status";
protected static final String COMPUTATION_TOTAL_COUNTER_NAME = OBSERVATION_PREFIX + "count";
protected static final String COMPUTATION_CURRENT_COUNTER_NAME = OBSERVATION_PREFIX + "current.count";
private static final String UNKNOWN_PROVIDER = "unknown-provider";

private final ObservationRegistry observationRegistry;
private final MeterRegistry meterRegistry;
Expand All @@ -45,12 +46,9 @@ protected AbstractComputationObserver(@NonNull ObservationRegistry observationRe
protected abstract String getComputationType();

protected Observation createObservation(String name, AbstractComputationRunContext<P> runContext) {
Observation observation = Observation.createNotStarted(OBSERVATION_PREFIX + name, observationRegistry)
.lowCardinalityKeyValue(TYPE_TAG_NAME, getComputationType());
if (runContext.getProvider() != null) {
observation.lowCardinalityKeyValue(PROVIDER_TAG_NAME, runContext.getProvider());
}
return observation;
return Observation.createNotStarted(OBSERVATION_PREFIX + name, observationRegistry)
.lowCardinalityKeyValue(TYPE_TAG_NAME, getComputationType())
.lowCardinalityKeyValue(PROVIDER_TAG_NAME, runContext.getProvider() != null ? runContext.getProvider() : UNKNOWN_PROVIDER);
}

public <E extends Throwable> void observe(String name, AbstractComputationRunContext<P> runContext, Observation.CheckedRunnable<E> callable) throws E {
Expand All @@ -64,13 +62,14 @@ public <T, E extends Throwable> T observe(String name, AbstractComputationRunCon
public <T extends R, E extends Throwable> T observeRun(
String name, AbstractComputationRunContext<P> runContext, Observation.CheckedCallable<T, E> callable) throws E {
T result;
String provider = runContext.getProvider() != null ? runContext.getProvider() : UNKNOWN_PROVIDER;
try {
incrementCurrentCount(runContext.getProvider());
incrementCurrentCount(provider);
result = createObservation(name, runContext).observeChecked(callable);
} finally {
decrementCurrentCount(runContext.getProvider());
decrementCurrentCount(provider);
}
incrementTotalCount(runContext, result);
incrementTotalCount(provider, result);
return result;
}

Expand All @@ -91,13 +90,10 @@ private void updateCurrentCountMetric(String provider) {
.register(meterRegistry);
}

private void incrementTotalCount(AbstractComputationRunContext<P> runContext, R result) {
Counter.Builder builder =
Counter.builder(COMPUTATION_TOTAL_COUNTER_NAME);
if (runContext.getProvider() != null) {
builder.tag(PROVIDER_TAG_NAME, runContext.getProvider());
}
builder.tag(TYPE_TAG_NAME, getComputationType())
private void incrementTotalCount(String provider, R result) {
Counter.builder(COMPUTATION_TOTAL_COUNTER_NAME)
.tag(PROVIDER_TAG_NAME, provider)
.tag(TYPE_TAG_NAME, getComputationType())
.tag(STATUS_TAG_NAME, getResultStatus(result))
.register(meterRegistry)
.increment();
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/gridsuite/computation/ComputationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,15 @@ void testDownloadDebugFileIOException() throws IOException {
verify(computationS3Service).downloadFile(S3_KEY);
}

@Test
void testObserveRunWithNullProvider() {
MockComputationObserver observer = new MockComputationObserver(ObservationRegistry.create(), new SimpleMeterRegistry());

MockComputationRunContext context = new MockComputationRunContext(
UUID.randomUUID(), "variantId", "receiver",
new ReportInfos(null, "reporter", "computationType"),
"userId", null, new Object());

assertDoesNotThrow(() -> observer.observeRun("testName", context, () -> "result"));
}
}