Skip to content

Commit d1eb2db

Browse files
committed
chore: added usefull comments
Signed-off-by: Yash Patel <[email protected]>
1 parent 128777a commit d1eb2db

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

bpf/kmesh/probes/probe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#ifndef __KMESH_BPF_PROBE_H__
55
#define __KMESH_BPF_PROBE_H__
66

7-
#define LONG_CONN_THRESHOLD_TIME (5 * 1000000000ULL) // 5s
8-
97
#include "tcp_probe.h"
108
#include "performance_probe.h"
119

10+
#define LONG_CONN_THRESHOLD_TIME (5 * 1000000000ULL) // 5s
11+
1212
volatile __u32 enable_monitoring = 0;
1313

1414
static inline bool is_monitoring_enable()

pkg/controller/telemetry/accesslog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
type logInfo struct {
2828
direction string
29-
status string
29+
state string
3030
sourceAddress string
3131
sourceWorkload string
3232
sourceNamespace string
@@ -89,7 +89,7 @@ func buildAccesslog(data requestMetric, conn_metrics connMetric, accesslog logIn
8989
timeInfo := fmt.Sprintf("%v", uptime)
9090
sourceInfo := fmt.Sprintf("src.addr=%s, src.workload=%s, src.namespace=%s", accesslog.sourceAddress, accesslog.sourceWorkload, accesslog.sourceNamespace)
9191
destinationInfo := fmt.Sprintf("dst.addr=%s, dst.service=%s, dst.workload=%s, dst.namespace=%s", accesslog.destinationAddress, accesslog.destinationService, accesslog.destinationWorkload, accesslog.destinationNamespace)
92-
connectionInfo := fmt.Sprintf("connection_id=%d, start_time=%s, direction=%s, status=%s, sent_bytes=%d, received_bytes=%d, packet_loss=%d, retransmissions=%d, srtt=%dus, min_rtt=%dus, duration=%vms", conn_metrics.connId, startTimeInfo, accesslog.direction, accesslog.status, conn_metrics.sentBytes, conn_metrics.receivedBytes, conn_metrics.packetLost, conn_metrics.totalRetrans, data.srtt, data.minRtt, (float64(data.duration) / 1000000.0))
92+
connectionInfo := fmt.Sprintf("connection_id=%d, start_time=%s, direction=%s, state=%s, sent_bytes=%d, received_bytes=%d, packet_loss=%d, retransmissions=%d, srtt=%dus, min_rtt=%dus, duration=%vms", conn_metrics.connId, startTimeInfo, accesslog.direction, accesslog.state, conn_metrics.sentBytes, conn_metrics.receivedBytes, conn_metrics.packetLost, conn_metrics.totalRetrans, data.srtt, data.minRtt, (float64(data.duration) / 1000000.0))
9393

9494
logResult := fmt.Sprintf("%s %s, %s, %s", timeInfo, sourceInfo, destinationInfo, connectionInfo)
9595
return logResult

pkg/controller/telemetry/accesslog_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func Test_buildAccesslog(t *testing.T) {
5656
destinationService: "httpbin.ambient-demo.svc.cluster.local",
5757
destinationWorkload: "httpbin-86b8ffc5ff-bhvxx",
5858
destinationNamespace: "kmesh-system",
59-
status: "BPF_TCP_SYN_RECV",
59+
state: "BPF_TCP_SYN_RECV",
6060
},
6161
},
62-
want: "2024-08-14 10:11:27.005837715 +0000 UTC src.addr=10.244.0.10:47667, src.workload=sleep-7656cf8794-9v2gv, src.namespace=kmesh-system, dst.addr=10.244.0.7:8080, dst.service=httpbin.ambient-demo.svc.cluster.local, dst.workload=httpbin-86b8ffc5ff-bhvxx, dst.namespace=kmesh-system, connection_id=12345678, start_time=2024-08-14 10:11:27.005837715 +0000 UTC, direction=INBOUND, status=BPF_TCP_SYN_RECV, sent_bytes=60, received_bytes=172, packet_loss=0, retransmissions=0, srtt=0us, min_rtt=0us, duration=2.236ms",
62+
want: "2024-08-14 10:11:27.005837715 +0000 UTC src.addr=10.244.0.10:47667, src.workload=sleep-7656cf8794-9v2gv, src.namespace=kmesh-system, dst.addr=10.244.0.7:8080, dst.service=httpbin.ambient-demo.svc.cluster.local, dst.workload=httpbin-86b8ffc5ff-bhvxx, dst.namespace=kmesh-system, connection_id=12345678, start_time=2024-08-14 10:11:27.005837715 +0000 UTC, direction=INBOUND, state=BPF_TCP_SYN_RECV, sent_bytes=60, received_bytes=172, packet_loss=0, retransmissions=0, srtt=0us, min_rtt=0us, duration=2.236ms",
6363
},
6464
}
6565
osStartTime = time.Date(2024, 7, 4, 20, 14, 0, 0, time.UTC)

pkg/controller/telemetry/metric.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ type statistics struct {
101101
ReceivedBytes uint32
102102
ConnectSuccess uint32
103103
Direction uint32
104-
State uint32
104+
State uint32 // TCP state ex: BPF_TCP_ESTABLISHED
105105
_ uint32
106-
Duration uint64
107-
StartTime uint64
108-
LastReportTime uint64
106+
Duration uint64 // duration of the connection till now
107+
StartTime uint64 // time when the connection is established
108+
LastReportTime uint64 // time when the metric is reported
109109
Protocol uint32
110-
SRttTime uint32
111-
RttMin uint32
112-
Retransmits uint32
113-
LostPackets uint32
110+
SRttTime uint32 // smoothed RTT
111+
RttMin uint32 // minimum RTT
112+
Retransmits uint32 // total retransmits
113+
LostPackets uint32 // total lost packets
114114
}
115115

116116
// connectionDataV4 read from ebpf km_tcp_probe ringbuf and padding with `_`
@@ -146,10 +146,10 @@ type connectionDataV6 struct {
146146

147147
type connMetric struct {
148148
connId uint64
149-
receivedBytes uint32
150-
sentBytes uint32
151-
totalRetrans uint32
152-
packetLost uint32
149+
receivedBytes uint32 // total bytes received till now
150+
sentBytes uint32 // total bytes sent till now
151+
totalRetrans uint32 // total retransmits till now
152+
packetLost uint32 // total packets lost till now
153153
}
154154

155155
type requestMetric struct {
@@ -161,17 +161,17 @@ type requestMetric struct {
161161
origDstPort uint16
162162
currentConnId uint64
163163
direction uint32
164-
receivedBytes uint32
165-
sentBytes uint32
164+
receivedBytes uint32 // total bytes received after previous report
165+
sentBytes uint32 // total bytes sent after previous report
166166
state uint32
167167
success uint32
168168
duration uint64
169169
startTime uint64
170170
lastReportTime uint64
171171
srtt uint32
172172
minRtt uint32
173-
totalRetrans uint32
174-
packetLost uint32
173+
totalRetrans uint32 // total retransmits after previous report
174+
packetLost uint32 // total packets lost after previous report
175175
}
176176

177177
type workloadMetricLabels struct {
@@ -414,6 +414,7 @@ func (m *MetricController) Run(ctx context.Context, mapOfTcpInfo *ebpf.Map) {
414414
}
415415

416416
if m.EnableAccesslog.Load() {
417+
// accesslogs at start of connection, at interval of 5 sec during connection lifecycle and at close of connection
417418
OutputAccesslog(data, tcp_conns[data.currentConnId], accesslog)
418419
}
419420

@@ -660,7 +661,7 @@ func (m *MetricController) buildServiceMetric(data *requestMetric) (serviceMetri
660661
accesslog.direction = "OUTBOUND"
661662
}
662663

663-
accesslog.status = TCP_STATES[data.state]
664+
accesslog.state = TCP_STATES[data.state]
664665
return *trafficLabels, *accesslog
665666
}
666667

0 commit comments

Comments
 (0)