Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: api request time for mock filtering #1067

Merged
merged 2 commits into from
Nov 3, 2023
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
1 change: 1 addition & 0 deletions pkg/hooks/bpf_bpfel_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/hooks/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/hooks/bpf_bpfel_x86.o
Binary file not shown.
11 changes: 10 additions & 1 deletion pkg/hooks/connection/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (conn *Tracker) AddDataEvent(event structs2.SocketDataEvent) {

case structs2.IngressTraffic:
// Capturing the timestamp of request as the request just started to come.
conn.reqTimestampTest = append(conn.reqTimestampTest, time.Now())
conn.reqTimestampTest = append(conn.reqTimestampTest, ConvertUnixNanoToTime(event.EntryTimestampNano))

// Assign the size of the message to the variable msgLength
msgLength := event.MsgSize
Expand Down Expand Up @@ -360,3 +360,12 @@ func (conn *Tracker) AddCloseEvent(event structs2.SocketCloseEvent) {
func (conn *Tracker) UpdateTimestamps() {
conn.lastActivityTimestamp = uint64(time.Now().UnixNano())
}

// ConvertUnixNanoToTime takes a Unix timestamp in nanoseconds as a uint64 and returns the corresponding time.Time
func ConvertUnixNanoToTime(unixNano uint64) time.Time {
// Unix time is the number of seconds since January 1, 1970 UTC,
// so convert nanoseconds to seconds for time.Unix function
seconds := int64(unixNano / uint64(time.Second))
nanoRemainder := int64(unixNano % uint64(time.Second))
return time.Unix(seconds, nanoRemainder)
}
3 changes: 3 additions & 0 deletions pkg/hooks/ringBufReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func socketDataEventCallback(reader *ringbuf.Reader, connectionFactory *connecti
logger.Error("failed to decode the recieve data from ringbuf socketDataEvent reader", zap.Error(err))
continue
}

event.TimestampNano += settings.GetRealTimeOffset()
event.EntryTimestampNano += settings.GetRealTimeOffset()

connectionFactory.GetOrCreate(event.ConnID).AddDataEvent(event)

}
Expand Down
2 changes: 2 additions & 0 deletions pkg/hooks/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
// SocketDataEvent is a conversion of the following C-Struct into GO.
// struct socket_data_event_t
// {
// u64 entry_timestamp_ns;
// u64 timestamp_ns;
// struct conn_id_t conn_id;
// enum traffic_direction_t direction;
Expand All @@ -49,6 +50,7 @@ const (

// Socket Data Event .....
type SocketDataEvent struct {
EntryTimestampNano uint64
TimestampNano uint64
ConnID ConnID
Direction TrafficDirectionEnum
Expand Down
Loading