Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,41 @@ func (c *Analytics) prepareAnalyticEvent(logEntry *v3.HTTPAccessLogEntry) *dto.E
}

properties := logEntry.GetCommonProperties()
if properties != nil && properties.TimeToLastUpstreamRxByte != nil && properties.TimeToFirstUpstreamTxByte != nil && properties.TimeToLastDownstreamTxByte != nil {
if properties != nil && properties.TimeToLastRxByte != nil &&
properties.TimeToFirstUpstreamTxByte != nil && properties.TimeToFirstUpstreamRxByte != nil &&
properties.TimeToLastUpstreamRxByte != nil && properties.TimeToLastDownstreamTxByte != nil {
Comment on lines +232 to +234
Copy link
Contributor

@renuka-fernando renuka-fernando Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, to populate this dto.Latencies, all the conditions should be true, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Anyway this shouldn't be an issue because for moesif side they calculate their own latency info using the request and response timestamps. These additional latency info are to populate the custom dashboards we have. So if the required properties aren't there then there's no point of trying to calculate them

Also since we are deriving these from envoy access logs, they'll be present in almost every time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack. Thanks


lastRx :=
(properties.TimeToLastRxByte.Seconds * 1000) +
(int64(properties.TimeToLastRxByte.Nanos) / 1_000_000)

firstUpTx :=
(properties.TimeToFirstUpstreamTxByte.Seconds * 1000) +
(int64(properties.TimeToFirstUpstreamTxByte.Nanos) / 1_000_000)

firstUpRx :=
(properties.TimeToFirstUpstreamRxByte.Seconds * 1000) +
(int64(properties.TimeToFirstUpstreamRxByte.Nanos) / 1_000_000)

backendResponseRecvTimestamp :=
lastUpRx :=
(properties.TimeToLastUpstreamRxByte.Seconds * 1000) +
(int64(properties.TimeToLastUpstreamRxByte.Nanos) / 1_000_000)

backendRequestSendTimestamp :=
(properties.TimeToFirstUpstreamTxByte.Seconds * 1000) +
(int64(properties.TimeToFirstUpstreamTxByte.Nanos) / 1_000_000)

downstreamResponseSendTimestamp :=
lastDownTx :=
(properties.TimeToLastDownstreamTxByte.Seconds * 1000) +
(int64(properties.TimeToLastDownstreamTxByte.Nanos) / 1_000_000)

// Prepare Latencies
latencies := dto.Latencies{}
latencies.BackendLatency = backendResponseRecvTimestamp - backendRequestSendTimestamp
latencies.RequestMediationLatency = backendRequestSendTimestamp
latencies.ResponseLatency = downstreamResponseSendTimestamp
latencies.ResponseMediationLatency = downstreamResponseSendTimestamp - backendResponseRecvTimestamp
latencies := dto.Latencies{
BackendLatency: lastUpRx - firstUpTx,
RequestMediationLatency: firstUpTx - lastRx,
ResponseLatency: lastDownTx - firstUpRx,
ResponseMediationLatency: lastDownTx - lastUpRx,
}

event.Latencies = &latencies
}


// prepare metaInfo
metaInfo := dto.MetaInfo{}
if logEntry.GetCommonProperties().GetStreamId() != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,11 @@ func createLogEntryWithMetadata(metadata map[string]string) *v3.HTTPAccessLogEnt
func createLogEntryWithLatencies() *v3.HTTPAccessLogEntry {
return &v3.HTTPAccessLogEntry{
CommonProperties: &v3.AccessLogCommon{
TimeToFirstUpstreamTxByte: &durationpb.Duration{Seconds: 0, Nanos: 100000000}, // 100ms
TimeToLastUpstreamRxByte: &durationpb.Duration{Seconds: 0, Nanos: 200000000}, // 200ms
TimeToLastDownstreamTxByte: &durationpb.Duration{Seconds: 0, Nanos: 250000000}, // 250ms
TimeToLastRxByte: &durationpb.Duration{Seconds: 0, Nanos: 50000000}, // 50ms - request fully received from client
TimeToFirstUpstreamTxByte: &durationpb.Duration{Seconds: 0, Nanos: 100000000}, // 100ms - start sending to backend
TimeToFirstUpstreamRxByte: &durationpb.Duration{Seconds: 0, Nanos: 150000000}, // 150ms - start receiving from backend
TimeToLastUpstreamRxByte: &durationpb.Duration{Seconds: 0, Nanos: 200000000}, // 200ms - finish receiving from backend
TimeToLastDownstreamTxByte: &durationpb.Duration{Seconds: 0, Nanos: 250000000}, // 250ms - finish sending to client
DownstreamRemoteAddress: &corev3.Address{
Address: &corev3.Address_SocketAddress{
SocketAddress: &corev3.SocketAddress{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,34 @@ func (m *Moesif) Publish(event *dto.Event) {
metadataMap["response_payload"] = responsePayload
}

// responseContentType
if responseContentType, ok := event.Properties["responseContentType"]; ok && responseContentType != nil {
metadataMap["responseContentType"] = responseContentType
}

// responseSize
if responseSize, ok := event.Properties["responseSize"]; ok && responseSize != nil {
metadataMap["responseSize"] = responseSize
}

// Advanced latency info
if event.Latencies != nil {
metadataMap["backendLatency"] = event.Latencies.BackendLatency
metadataMap["requestMediationLatency"] = event.Latencies.RequestMediationLatency
metadataMap["responseLatency"] = event.Latencies.ResponseLatency
metadataMap["responseMediationLatency"] = event.Latencies.ResponseMediationLatency
}

// commonName
if commonName, ok := event.Properties["commonName"]; ok && commonName != nil {
metadataMap["commonName"] = commonName
}

// isEgress
if isEgress, ok := event.Properties["isEgress"]; ok && isEgress != nil {
metadataMap["isEgress"] = isEgress
}

// Determine user ID - use from event properties if available, otherwise anonymous
userID := anonymous
if userIDVal, ok := event.Properties[userIDPropertyKey]; ok {
Expand Down
Loading