-
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.
Merge pull request #9 from OSGP/feature/FDP-94
FDP-94: Add monitoring and small fixes
- Loading branch information
Showing
11 changed files
with
275 additions
and
99 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
21 changes: 0 additions & 21 deletions
21
application/src/integrationTest/kotlin/org/gxf/soapbridge/SoapBridgeApplicationTests.kt
This file was deleted.
Oops, something went wrong.
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
16 changes: 0 additions & 16 deletions
16
.../src/main/java/org/gxf/soapbridge/soap/exceptions/ConnectionNotFoundInCacheException.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
application/src/main/kotlin/org/gxf/soapbridge/monitoring/MonitoringService.kt
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,56 @@ | ||
package org.gxf.soapbridge.monitoring | ||
|
||
import io.micrometer.core.instrument.Gauge | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.micrometer.core.instrument.Timer | ||
import org.springframework.stereotype.Service | ||
import java.time.Duration | ||
import java.time.Instant | ||
|
||
@Service | ||
class MonitoringService( | ||
private val registry: MeterRegistry | ||
) { | ||
|
||
companion object { | ||
private const val METRIC_PREFIX = "gxf.soap.bridge" | ||
const val CACHE_SIZE_METRIC = "${METRIC_PREFIX}.cache.size" | ||
const val CONNECTION_TIMER_METRIC = "${METRIC_PREFIX}.request.timer" | ||
|
||
const val CONNECTION_TIMER_CONTEXT_TAG = "context" | ||
const val CONNECTION_TIMER_SUCCESSFUL_TAG = "successful" | ||
|
||
} | ||
|
||
/** | ||
* Creates a gauge to monitor the size of a cache. | ||
* | ||
* @param cache The cache to monitor, represented as a Map. | ||
* @return A Gauge object that measures the size of the cache. | ||
*/ | ||
fun monitorCacheSize(cache: Map<*, *>) = | ||
Gauge | ||
.builder(CACHE_SIZE_METRIC, cache) { it.size.toDouble() } | ||
.register(registry) | ||
|
||
/** | ||
* Records the connection time for a request. | ||
* | ||
* The timer also counts the amount of requests handled. | ||
* | ||
* @param startTime The start time of the request. | ||
* @param context The context of the request. | ||
* @param successful Flag indicating if the request was successful. | ||
*/ | ||
fun recordConnectionTime(startTime: Instant, context: String, successful: Boolean) { | ||
val duration = Duration.between(startTime, Instant.now()) | ||
|
||
Timer | ||
.builder(CONNECTION_TIMER_METRIC) | ||
.description("The time it takes to handle an incoming soap request") | ||
.tag(CONNECTION_TIMER_CONTEXT_TAG, context) | ||
.tag(CONNECTION_TIMER_SUCCESSFUL_TAG, successful.toString()) | ||
.register(registry) | ||
.record(duration) | ||
} | ||
} |
Oops, something went wrong.