diff --git a/TrafficCapture/dockerSolution/src/main/docker/otelcol/otel-config.yml b/TrafficCapture/dockerSolution/src/main/docker/otelcol/otel-config.yml index 5ee7127c4..f6ccc70e6 100644 --- a/TrafficCapture/dockerSolution/src/main/docker/otelcol/otel-config.yml +++ b/TrafficCapture/dockerSolution/src/main/docker/otelcol/otel-config.yml @@ -23,6 +23,16 @@ processors: action: insert - key: log4j.context_data.channel_id action: delete + # The following actions convert various should-be-int strings to ints + - key: log4j.context_data.source_http_status + action: convert + converted_type: int + - key: log4j.context_data.target_http_status + action: convert + converted_type: int + - key: log4j.context_data.http_status_match + action: convert + converted_type: int extensions: basicauth/client: diff --git a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/SourceTargetCaptureTuple.java b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/SourceTargetCaptureTuple.java index 41ca43594..b112d8101 100644 --- a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/SourceTargetCaptureTuple.java +++ b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/SourceTargetCaptureTuple.java @@ -9,6 +9,7 @@ import org.json.JSONObject; import org.opensearch.migrations.coreutils.MetricsAttributeKey; import org.opensearch.migrations.coreutils.MetricsEvent; +import org.opensearch.migrations.coreutils.MetricsLogBuilder; import org.opensearch.migrations.coreutils.MetricsLogger; import org.opensearch.migrations.replay.datatypes.HttpRequestTransformationStatus; import org.opensearch.migrations.replay.datatypes.TransformedPackets; @@ -125,20 +126,24 @@ private JSONObject toJSONObject(SourceTargetCaptureTuple tuple) { meta.put("connectionId", tuple.uniqueRequestKey); Optional.ofNullable(tuple.errorCause).ifPresent(e->meta.put("error", e)); - if (tuple.targetRequestData != null && tuple.sourcePair.responseData != null) { + if (meta.has("sourceResponse") && meta.has("targetResponse")) { String sourceResponseStatus = (String) meta.getJSONObject("sourceResponse").get("Status-Code"); String targetResponseStatus = (String) meta.getJSONObject("targetResponse").get("Status-Code"); - String httpMethod = (String) meta.getJSONObject("sourceRequest").get("Method"); - String endpoint = (String) meta.getJSONObject("sourceRequest").get("Request-URI"); - - metricsLogger.atSuccess(MetricsEvent.STATUS_CODE_COMPARISON) - .setAttribute(MetricsAttributeKey.REQUEST_ID, tuple.uniqueRequestKey.toString()) - .setAttribute(MetricsAttributeKey.HTTP_METHOD, httpMethod) - .setAttribute(MetricsAttributeKey.HTTP_ENDPOINT, endpoint) + MetricsLogBuilder metric = metricsLogger.atSuccess(MetricsEvent.STATUS_CODE_COMPARISON) + .setAttribute(MetricsAttributeKey.REQUEST_ID, + tuple.uniqueRequestKey.getTrafficStreamKey().getConnectionId() + "." + tuple.uniqueRequestKey.getSourceRequestIndex()) .setAttribute(MetricsAttributeKey.SOURCE_HTTP_STATUS, sourceResponseStatus) .setAttribute(MetricsAttributeKey.TARGET_HTTP_STATUS, targetResponseStatus) - .setAttribute(MetricsAttributeKey.HTTP_STATUS_MATCH, sourceResponseStatus.equals(targetResponseStatus)) - .emit(); + .setAttribute(MetricsAttributeKey.HTTP_STATUS_MATCH, + sourceResponseStatus.equals(targetResponseStatus) ? 1 : 0); + + if (meta.has("sourceRequest")) { + String httpMethod = (String) meta.getJSONObject("sourceRequest").get("Method"); + String endpoint = (String) meta.getJSONObject("sourceRequest").get("Request-URI"); + metric = metric.setAttribute(MetricsAttributeKey.HTTP_METHOD, httpMethod) + .setAttribute(MetricsAttributeKey.HTTP_ENDPOINT, endpoint); + } + metric.emit(); } return meta; }