Skip to content

Commit 87c6e6b

Browse files
committed
rfac: changed metric to kmesh_tcp_sent_bytes_total in telemetry e2e test
Signed-off-by: Yash Patel <yp969803@gmail.com>
1 parent deea6b9 commit 87c6e6b

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

pkg/controller/telemetry/metric.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,19 +516,19 @@ func (m *MetricController) Run(ctx context.Context, mapOfTcpInfo *ebpf.Map) {
516516
OutputAccesslog(data, tcpConns[data.conSrcDstInfo], accesslog)
517517
}
518518

519-
if data.state == TCP_CLOSTED {
520-
delete(tcpConns, data.conSrcDstInfo)
521-
}
522-
523519
m.mutex.Lock()
524520
if m.EnableWorkloadMetric.Load() {
525-
m.updateWorkloadMetricCache(data, workloadLabels, tcpConns)
521+
m.updateWorkloadMetricCache(data, workloadLabels, tcpConns[data.conSrcDstInfo])
526522
}
527-
m.updateServiceMetricCache(data, serviceLabels, tcpConns)
523+
m.updateServiceMetricCache(data, serviceLabels, tcpConns[data.conSrcDstInfo])
528524
if m.EnableConnectionMetric.Load() && data.duration > LONG_CONN_METRIC_THRESHOLD {
529525
m.updateConnectionMetricCache(data, tcpConns[data.conSrcDstInfo], connectionLabels)
530526
}
531527
m.mutex.Unlock()
528+
529+
if data.state == TCP_CLOSTED {
530+
delete(tcpConns, data.conSrcDstInfo)
531+
}
532532
}
533533
}
534534
}
@@ -842,10 +842,10 @@ func buildPrincipal(workload *workloadapi.Workload) string {
842842
return DEFAULT_UNKNOWN
843843
}
844844

845-
func (m *MetricController) updateWorkloadMetricCache(data requestMetric, labels workloadMetricLabels, tcpConns map[connectionSrcDst]connMetric) {
845+
func (m *MetricController) updateWorkloadMetricCache(data requestMetric, labels workloadMetricLabels, metric connMetric) {
846846
v, ok := m.workloadMetricCache[labels]
847847
if ok {
848-
if data.state == TCP_ESTABLISHED && tcpConns[data.conSrcDstInfo].totalReports == 1 {
848+
if data.state == TCP_ESTABLISHED && metric.totalReports == 1 {
849849
v.WorkloadConnOpened = v.WorkloadConnOpened + 1
850850
}
851851
if data.state == TCP_CLOSTED {
@@ -860,7 +860,7 @@ func (m *MetricController) updateWorkloadMetricCache(data requestMetric, labels
860860
v.WorkloadConnPacketLost = v.WorkloadConnPacketLost + float64(data.packetLost)
861861
} else {
862862
newWorkloadMetricInfo := workloadMetricInfo{}
863-
if data.state == TCP_ESTABLISHED && tcpConns[data.conSrcDstInfo].totalReports == 1 {
863+
if data.state == TCP_ESTABLISHED && metric.totalReports == 1 {
864864
newWorkloadMetricInfo.WorkloadConnOpened = 1
865865
}
866866
if data.state == TCP_CLOSTED {
@@ -877,10 +877,10 @@ func (m *MetricController) updateWorkloadMetricCache(data requestMetric, labels
877877
}
878878
}
879879

880-
func (m *MetricController) updateServiceMetricCache(data requestMetric, labels serviceMetricLabels, tcpConns map[connectionSrcDst]connMetric) {
880+
func (m *MetricController) updateServiceMetricCache(data requestMetric, labels serviceMetricLabels, metric connMetric) {
881881
v, ok := m.serviceMetricCache[labels]
882882
if ok {
883-
if data.state == TCP_ESTABLISHED && tcpConns[data.conSrcDstInfo].totalReports == 1 {
883+
if data.state == TCP_ESTABLISHED && metric.totalReports == 1 {
884884
v.ServiceConnOpened = v.ServiceConnOpened + 1
885885
}
886886
if data.state == TCP_CLOSTED {
@@ -893,7 +893,7 @@ func (m *MetricController) updateServiceMetricCache(data requestMetric, labels s
893893
v.ServiceConnSentBytes = v.ServiceConnSentBytes + float64(data.sentBytes)
894894
} else {
895895
newServiceMetricInfo := serviceMetricInfo{}
896-
if data.state == TCP_ESTABLISHED && tcpConns[data.conSrcDstInfo].totalReports == 1 {
896+
if data.state == TCP_ESTABLISHED && metric.totalReports == 1 {
897897
newServiceMetricInfo.ServiceConnOpened = 1
898898
}
899899
if data.state == TCP_CLOSTED {

pkg/controller/telemetry/metric_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func TestBuildMetricsToPrometheus(t *testing.T) {
307307
workloadMetricCache: map[workloadMetricLabels]*workloadMetricInfo{},
308308
serviceMetricCache: map[serviceMetricLabels]*serviceMetricInfo{},
309309
}
310-
m.updateWorkloadMetricCache(tt.args.data, tt.args.labels, tt.args.tcpConns)
310+
m.updateWorkloadMetricCache(tt.args.data, tt.args.labels, tt.args.tcpConns[tt.args.data.conSrcDstInfo])
311311
assert.Equal(t, m.workloadMetricCache[tt.args.labels].WorkloadConnClosed, tt.want[0])
312312
assert.Equal(t, m.workloadMetricCache[tt.args.labels].WorkloadConnOpened, tt.want[1])
313313
assert.Equal(t, m.workloadMetricCache[tt.args.labels].WorkloadConnReceivedBytes, tt.want[2])
@@ -441,7 +441,7 @@ func TestBuildServiceMetricsToPrometheus(t *testing.T) {
441441
workloadMetricCache: map[workloadMetricLabels]*workloadMetricInfo{},
442442
serviceMetricCache: map[serviceMetricLabels]*serviceMetricInfo{},
443443
}
444-
m.updateServiceMetricCache(tt.args.data, tt.args.labels, tt.args.tcpConns)
444+
m.updateServiceMetricCache(tt.args.data, tt.args.labels, tt.args.tcpConns[tt.args.data.conSrcDstInfo])
445445
assert.Equal(t, m.serviceMetricCache[tt.args.labels].ServiceConnClosed, tt.want[0])
446446
assert.Equal(t, m.serviceMetricCache[tt.args.labels].ServiceConnOpened, tt.want[1])
447447
assert.Equal(t, m.serviceMetricCache[tt.args.labels].ServiceConnReceivedBytes, tt.want[2])

test/e2e/baseline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ func buildL4Query(src, dst echo.Instance) prometheus.Query {
849849
"source_cluster": "Kubernetes",
850850
}
851851

852-
query.Metric = "kmesh_tcp_connections_opened_total"
852+
query.Metric = "kmesh_tcp_sent_bytes_total"
853853
query.Labels = labels
854854

855855
return query

0 commit comments

Comments
 (0)