-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add instrumentation setup * Replace the file size with the number of buses * Separation of failed import and export * Adding the number of buses for import and export Signed-off-by: TOURI ANIS <[email protected]> * Change jauge meter by DistributionSummary meter to have the max value for buses * Fix checkstyle Signed-off-by: Slimane AMAR <[email protected]> --------- Signed-off-by: TOURI ANIS <[email protected]> Signed-off-by: Slimane AMAR <[email protected]> Co-authored-by: Slimane AMAR <[email protected]>
- Loading branch information
Showing
7 changed files
with
110 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
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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/powsybl/network/conversion/server/NetworkConversionObserver.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,71 @@ | ||
/** | ||
* Copyright (c) 2024, 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 com.powsybl.network.conversion.server; | ||
|
||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.network.conversion.server.dto.ExportNetworkInfos; | ||
import io.micrometer.core.instrument.DistributionSummary; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import lombok.NonNull; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author Anis Touri <anis.touri at rte-france.com> | ||
*/ | ||
|
||
@Service | ||
public class NetworkConversionObserver { | ||
|
||
private static final String OBSERVATION_PREFIX = "app.conversion."; | ||
private static final String FORMAT_TAG_NAME = "format"; | ||
|
||
private static final String IMPORT_OBSERVATION_NAME = OBSERVATION_PREFIX + "import"; | ||
private static final String NUMBER_BUSES_IMPORTED_METER_NAME = IMPORT_OBSERVATION_NAME + ".buses"; | ||
|
||
private static final String EXPORT_OBSERVATION_NAME = OBSERVATION_PREFIX + "export"; | ||
private static final String NUMBER_BUSES_EXPORTED_METER_NAME = EXPORT_OBSERVATION_NAME + ".buses"; | ||
|
||
private final ObservationRegistry observationRegistry; | ||
|
||
private final MeterRegistry meterRegistry; | ||
|
||
public NetworkConversionObserver(@NonNull ObservationRegistry observationRegistry, @NonNull MeterRegistry meterRegistry) { | ||
this.observationRegistry = observationRegistry; | ||
this.meterRegistry = meterRegistry; | ||
} | ||
|
||
public <E extends Throwable> ExportNetworkInfos observeExport(String format, Observation.CheckedCallable<ExportNetworkInfos, E> callable) throws E { | ||
Observation observation = createObservation(EXPORT_OBSERVATION_NAME, format); | ||
ExportNetworkInfos exportInfos = observation.observeChecked(callable); | ||
if (exportInfos != null) { | ||
recordNumberBuses(NUMBER_BUSES_EXPORTED_METER_NAME, format, exportInfos.getNumberBuses()); | ||
} | ||
return exportInfos; | ||
} | ||
|
||
public <E extends Throwable> Network observeImport(String format, Observation.CheckedCallable<Network, E> callable) throws E { | ||
Network network = createObservation(IMPORT_OBSERVATION_NAME, format).observeChecked(callable); | ||
if (network != null) { | ||
recordNumberBuses(NUMBER_BUSES_IMPORTED_METER_NAME, format, network.getBusView().getBusStream().count()); | ||
} | ||
return network; | ||
} | ||
|
||
private Observation createObservation(String name, String format) { | ||
return Observation.createNotStarted(name, observationRegistry) | ||
.lowCardinalityKeyValue(FORMAT_TAG_NAME, format); | ||
} | ||
|
||
private void recordNumberBuses(String meterName, String format, long numberBuses) { | ||
DistributionSummary.builder(meterName) | ||
.tags(FORMAT_TAG_NAME, format) | ||
.register(meterRegistry) | ||
.record(numberBuses); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,6 @@ public class ExportNetworkInfos { | |
|
||
private byte[] networkData; | ||
|
||
private long numberBuses; | ||
|
||
} |
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