-
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 a metric for diagram generations in the thread pool
Signed-off-by: Slimane AMAR <amarsli@gm0winl104.bureau.si.interne>
- Loading branch information
Slimane AMAR
committed
Dec 27, 2024
1 parent
53b0714
commit 6e3e4f3
Showing
6 changed files
with
140 additions
and
52 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/powsybl/sld/server/DiagramGenerationExecutionService.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,40 @@ | ||
/** | ||
* 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.sld.server; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import lombok.NonNull; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.*; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* @author Slimane Amar <slimane.amar at rte-france.com> | ||
*/ | ||
@Service | ||
public class DiagramGenerationExecutionService { | ||
|
||
private ThreadPoolExecutor executorService; | ||
|
||
public DiagramGenerationExecutionService(@Value("${max-concurrent-nad-generations}") int maxConcurrentNadGenerations, | ||
@NonNull DiagramGenerationObserver diagramGenerationObserver) { | ||
executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(maxConcurrentNadGenerations); | ||
diagramGenerationObserver.createThreadPoolMetric(executorService); | ||
} | ||
|
||
@PreDestroy | ||
private void preDestroy() { | ||
executorService.shutdown(); | ||
} | ||
|
||
public <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) { | ||
return CompletableFuture.supplyAsync(supplier, executorService); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/powsybl/sld/server/DiagramGenerationObserver.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) 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.sld.server; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.MultiGauge; | ||
import io.micrometer.core.instrument.Tags; | ||
import lombok.NonNull; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
/** | ||
* @author Slimane Amar <slimane.amar at rte-france.com> | ||
*/ | ||
@Service | ||
public class DiagramGenerationObserver { | ||
private static final String OBSERVATION_PREFIX = "app.diagram."; | ||
private static final String TYPE_TAG_NAME = "type"; | ||
private static final String TYPE_TAG_VALUE_CURRENT = "current"; | ||
private static final String TYPE_TAG_VALUE_PENDING = "pending"; | ||
private static final String POOL_METER_NAME = OBSERVATION_PREFIX + "tasks.pool"; | ||
|
||
private final MeterRegistry meterRegistry; | ||
|
||
public DiagramGenerationObserver(@NonNull MeterRegistry meterRegistry) { | ||
this.meterRegistry = meterRegistry; | ||
} | ||
|
||
public void createThreadPoolMetric(ThreadPoolExecutor threadPoolExecutor) { | ||
MultiGauge multiGauge = MultiGauge.builder(POOL_METER_NAME).description("The number of diagram generations (tasks) in the thread pool").register(meterRegistry); | ||
multiGauge.register(List.of( | ||
MultiGauge.Row.of(Tags.of(TYPE_TAG_NAME, TYPE_TAG_VALUE_CURRENT), () -> threadPoolExecutor.getActiveCount()), | ||
MultiGauge.Row.of(Tags.of(TYPE_TAG_NAME, TYPE_TAG_VALUE_PENDING), () -> threadPoolExecutor.getQueue().size()) | ||
)); | ||
} | ||
} |
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
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