Skip to content

Commit

Permalink
FDP-94: Update metric counter
Browse files Browse the repository at this point in the history
Signed-off-by: Jasper Kamerling <[email protected]>
  • Loading branch information
jasperkamerling committed Dec 1, 2023
1 parent 3e77b6a commit 17b5deb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void handleRequest(
final String soapPayload = readSoapPayload(request);
if (soapPayload == null) {
LOGGER.error("Unable to read SOAP request, returning 500.");
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
return;
}
Expand All @@ -110,7 +110,7 @@ public void handleRequest(
}
if (organisationName == null) {
LOGGER.error("Unable to find client certificate, returning 500.");
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
return;
}
Expand All @@ -130,7 +130,7 @@ public void handleRequest(
requestMessage.setSignature(signature);
} catch (final ProxyServerException e) {
LOGGER.error("Unable to sign message or set security key", e);
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
connectionCacheService.removeConnection(connectionId);
return;
Expand All @@ -152,14 +152,14 @@ public void handleRequest(
final boolean responseReceived = newConnection.waitForResponseReceived(timeout);
if (!responseReceived) {
LOGGER.error("No response received within the specified timeout of {} seconds", timeout);
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
connectionCacheService.removeConnection(connectionId);
return;
}
} catch (final InterruptedException e) {
LOGGER.error("Error while waiting for response", e);
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
connectionCacheService.removeConnection(connectionId);
Thread.currentThread().interrupt();
Expand All @@ -169,12 +169,12 @@ public void handleRequest(
final String soap = readResponse(connectionId);
if (soap == null) {
LOGGER.error("Unable to read SOAP response: null");
monitoringService.connectionClose(startTime, request.getContextPath(), false);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), false);
createErrorResponse(response);
} else {
LOGGER.debug("Request handled, trying to send response...");
createSuccessFulResponse(response, soap);
monitoringService.connectionClose(startTime, request.getContextPath(), true);
monitoringService.recordConnectionTime(startTime, request.getContextPath(), true);
}

LOGGER.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gxf.soapbridge.monitoring

import io.micrometer.core.instrument.Counter
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Timer
import org.springframework.stereotype.Service
Expand All @@ -16,28 +15,15 @@ class MonitoringService(
private const val METRIC_PREFIX = "gxf.soap.bridge"
}

private val connectionsFailed: Counter = Counter
.builder("${METRIC_PREFIX}.connection.failed")
.description("Counts the successful requests to the Maki API")
.register(registry)

private val connectionsSuccessful: Counter = Counter
.builder("${METRIC_PREFIX}.connection.successful")
.description("Counts the successful requests to the Maki API")
.register(registry)


fun connectionClose(startTime: Instant, context: String, successful: Boolean) {
fun recordConnectionTime(startTime: Instant, context: String, successful: Boolean) {
val duration = Duration.between(startTime, Instant.now())

if (successful) connectionsSuccessful.increment()
else connectionsFailed.increment()

Timer
.builder("${METRIC_PREFIX}.connection.timer")
.description("Counts the successful requests to the Maki API")
.tag("context", context)
.tag("successful", successful.toString())
.register(registry)
.record(duration)
}
}
}

0 comments on commit 17b5deb

Please sign in to comment.