Skip to content

Commit 6fa8dd0

Browse files
authored
usm: Prevent negative latency (#41263)
### What does this PR do? Prevents an edge case of negative latency. ### Motivation Seen in staging. While we keep investigating the issue, we should at least drop the traffic. ### Describe how you validated your changes ### Additional Notes
1 parent 5f331b5 commit 6fa8dd0

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

pkg/network/protocols/http/model_linux.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strconv"
1313
"strings"
1414

15+
"github.com/DataDog/datadog-agent/pkg/network/ebpf"
1516
"github.com/DataDog/datadog-agent/pkg/network/protocols"
16-
1717
"github.com/DataDog/datadog-agent/pkg/network/types"
1818
)
1919

@@ -27,7 +27,10 @@ func (e *EbpfEvent) Path(buffer []byte) ([]byte, bool) {
2727

2828
// RequestLatency returns the latency of the request in nanoseconds
2929
func (e *EbpfEvent) RequestLatency() float64 {
30-
if uint64(e.Http.Request_started) == 0 || uint64(e.Http.Response_last_seen) == 0 {
30+
if e.Http.Request_started == 0 || e.Http.Response_last_seen == 0 {
31+
return 0
32+
}
33+
if e.Http.Response_last_seen < e.Http.Request_started {
3134
return 0
3235
}
3336
return protocols.NSTimestampToFloat(e.Http.Response_last_seen - e.Http.Request_started)
@@ -92,7 +95,7 @@ func (e *EbpfEvent) StaticTags() uint64 {
9295
return e.Http.Tags
9396
}
9497

95-
// DynamicTags returns the dynamic tags associated to the HTTP trasnaction
98+
// DynamicTags returns the dynamic tags associated to the HTTP transaction
9699
func (e *EbpfEvent) DynamicTags() []string {
97100
return nil
98101
}
@@ -101,8 +104,12 @@ func (e *EbpfEvent) DynamicTags() []string {
101104
func (e *EbpfEvent) String() string {
102105
var output strings.Builder
103106
output.WriteString("ebpfTx{")
107+
output.WriteString("Conn Tuple: " + ebpf.ConnTuple(e.Tuple).String() + "', ")
104108
output.WriteString("Method: '" + Method(e.Http.Request_method).String() + "', ")
105109
output.WriteString("Tags: '0x" + strconv.FormatUint(e.Http.Tags, 16) + "', ")
110+
output.WriteString("Request Start: " + strconv.FormatUint(e.Http.Request_started, 10) + "', ")
111+
output.WriteString("Response Last Seen: " + strconv.FormatUint(e.Http.Response_last_seen, 10) + "', ")
112+
output.WriteString("Latency: " + strconv.FormatFloat(e.RequestLatency(), 'f', -1, 64) + "', ")
106113
output.WriteString("Fragment: '" + hex.EncodeToString(e.Http.Request_fragment[:]) + "', ")
107114
output.WriteString("}")
108115
return output.String()

pkg/network/protocols/http/statkeeper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (h *StatKeeper) add(tx Transaction) {
171171
if latency <= 0 {
172172
h.telemetry.invalidLatency.Add(1)
173173
if h.oversizedLogLimit.ShouldLog() {
174-
log.Warnf("latency should never be equal to 0: %s", tx.String())
174+
log.Warnf("latency should never be non positive: %s", tx.String())
175175
}
176176
return
177177
}

pkg/network/protocols/http2/model_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ func (tx *EbpfTx) Path(buffer []byte) ([]byte, bool) {
145145

146146
// RequestLatency returns the latency of the request in nanoseconds
147147
func (tx *EbpfTx) RequestLatency() float64 {
148-
if uint64(tx.Stream.Request_started) == 0 || uint64(tx.Stream.Response_last_seen) == 0 {
148+
if tx.Stream.Request_started == 0 || tx.Stream.Response_last_seen == 0 {
149+
return 0
150+
}
151+
if tx.Stream.Response_last_seen < tx.Stream.Request_started {
149152
return 0
150153
}
151154
return protocols.NSTimestampToFloat(tx.Stream.Response_last_seen - tx.Stream.Request_started)

pkg/network/protocols/kafka/model_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func (tx *EbpfTx) ErrorCode() int8 {
4848

4949
// RequestLatency returns the latency of the request in nanoseconds
5050
func (tx *EbpfTx) RequestLatency() float64 {
51-
if uint64(tx.Transaction.Request_started) == 0 || uint64(tx.Transaction.Response_last_seen) == 0 {
51+
if tx.Transaction.Request_started == 0 || tx.Transaction.Response_last_seen == 0 {
52+
return 0
53+
}
54+
if tx.Transaction.Response_last_seen < tx.Transaction.Request_started {
5255
return 0
5356
}
5457
return protocols.NSTimestampToFloat(tx.Transaction.Response_last_seen - tx.Transaction.Request_started)

pkg/network/protocols/postgres/model_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ func (e *EventWrapper) Parameters() string {
134134

135135
// RequestLatency returns the latency of the request in nanoseconds
136136
func (e *EventWrapper) RequestLatency() float64 {
137-
if uint64(e.Tx.Request_started) == 0 || uint64(e.Tx.Response_last_seen) == 0 {
137+
if e.Tx.Request_started == 0 || e.Tx.Response_last_seen == 0 {
138+
return 0
139+
}
140+
if e.Tx.Response_last_seen < e.Tx.Request_started {
138141
return 0
139142
}
140143
return protocols.NSTimestampToFloat(e.Tx.Response_last_seen - e.Tx.Request_started)

pkg/network/protocols/redis/model_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ func (e *EventWrapper) CommandType() CommandType {
7676

7777
// RequestLatency returns the latency of the request in nanoseconds
7878
func (e *EventWrapper) RequestLatency() float64 {
79-
if uint64(e.Tx.Request_started) == 0 || uint64(e.Tx.Response_last_seen) == 0 {
79+
if e.Tx.Request_started == 0 || e.Tx.Response_last_seen == 0 {
80+
return 0
81+
}
82+
if e.Tx.Response_last_seen < e.Tx.Request_started {
8083
return 0
8184
}
8285
return protocols.NSTimestampToFloat(e.Tx.Response_last_seen - e.Tx.Request_started)

0 commit comments

Comments
 (0)