-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Florent MILLOT <[email protected]>
- Loading branch information
Showing
4 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...in/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.gridsuite.sensitivityanalysis.server.service; | ||
|
||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import lombok.NonNull; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author Florent MILLOT <florent.millot at rte-france.com> | ||
*/ | ||
@Service | ||
public class SensitivityAnalysisObserver { | ||
|
||
private final ObservationRegistry observationRegistry; | ||
|
||
private static final String OBSERVATION_PREFIX = "app.sensitivity.analysis."; | ||
private static final String PROVIDER_TAG_NAME = "provider"; | ||
|
||
public SensitivityAnalysisObserver(@NonNull ObservationRegistry observationRegistry) { | ||
this.observationRegistry = observationRegistry; | ||
} | ||
|
||
public <E extends Throwable> void observe(String name, SensitivityAnalysisRunContext runContext, Observation.CheckedRunnable<E> callable) throws E { | ||
createSensitivityAnalysisObservation(name, runContext).observeChecked(callable); | ||
} | ||
|
||
public <T, E extends Throwable> T observe(String name, SensitivityAnalysisRunContext runContext, Observation.CheckedCallable<T, E> callable) throws E { | ||
return createSensitivityAnalysisObservation(name, runContext).observeChecked(callable); | ||
} | ||
|
||
private Observation createSensitivityAnalysisObservation(String name, SensitivityAnalysisRunContext runContext) { | ||
return Observation.createNotStarted(OBSERVATION_PREFIX + name, observationRegistry) | ||
.lowCardinalityKeyValue(PROVIDER_TAG_NAME, runContext.getProvider()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters