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
12 changes: 6 additions & 6 deletions pkg/controller/telemetry/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@
}
m.updateServiceMetricCache(reqMetric, serviceLabels, tcpConns[reqMetric.conSrcDstInfo])
if m.EnableConnectionMetric.Load() && reqMetric.duration > LONG_CONN_METRIC_THRESHOLD {
m.updateConnectionMetricCache(reqMetric, tcpConns[reqMetric.conSrcDstInfo], connectionLabels)
m.updateConnectionMetricCache(reqMetric, connectionLabels)

Check warning on line 524 in pkg/controller/telemetry/metric.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/telemetry/metric.go#L524

Added line #L524 was not covered by tests
}
m.mutex.Unlock()

Expand Down Expand Up @@ -907,7 +907,7 @@
}
}

func (m *MetricController) updateConnectionMetricCache(reqMetric requestMetric, connMetric connMetric, labels connectionMetricLabels) {
func (m *MetricController) updateConnectionMetricCache(reqMetric requestMetric, labels connectionMetricLabels) {
v, ok := m.connectionMetricCache[labels]
if ok {
v.ConnSentBytes = v.ConnSentBytes + float64(reqMetric.sentBytes)
Expand All @@ -916,10 +916,10 @@
v.ConnTotalRetrans = v.ConnTotalRetrans + float64(reqMetric.totalRetrans)
} else {
newConnectionMetricInfo := connectionMetricInfo{}
newConnectionMetricInfo.ConnSentBytes = float64(connMetric.sentBytes)
newConnectionMetricInfo.ConnReceivedBytes = float64(connMetric.receivedBytes)
newConnectionMetricInfo.ConnPacketLost = float64(connMetric.packetLost)
newConnectionMetricInfo.ConnTotalRetrans = float64(connMetric.totalRetrans)
newConnectionMetricInfo.ConnSentBytes = float64(reqMetric.sentBytes)
newConnectionMetricInfo.ConnReceivedBytes = float64(reqMetric.receivedBytes)
newConnectionMetricInfo.ConnPacketLost = float64(reqMetric.packetLost)
newConnectionMetricInfo.ConnTotalRetrans = float64(reqMetric.totalRetrans)
m.connectionMetricCache[labels] = &newConnectionMetricInfo
}
if reqMetric.state == TCP_CLOSED {
Expand Down
47 changes: 3 additions & 44 deletions pkg/controller/telemetry/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,8 @@ func TestBuildServiceMetricsToPrometheus(t *testing.T) {

func TestBuildConnectionMetricsToPrometheus(t *testing.T) {
type args struct {
data requestMetric
labels connectionMetricLabels
tcpConns map[connectionSrcDst]connMetric
data requestMetric
labels connectionMetricLabels
}
tests := []struct {
id int32
Expand Down Expand Up @@ -542,26 +541,6 @@ func TestBuildConnectionMetricsToPrometheus(t *testing.T) {
responseFlags: "-",
connectionSecurityPolicy: "mutual_tls",
},
tcpConns: map[connectionSrcDst]connMetric{
{
src: [4]uint32{183763210, 0, 0, 0},
dst: [4]uint32{183762951, 0, 0, 0},
direction: constants.INBOUND,
}: {
sentBytes: 0x0000003,
receivedBytes: 0x0000004,
packetLost: 0x0000001,
totalRetrans: 0x0000002,
totalReports: 1,
},
{
src: [4]uint32{183763210, 0, 0, 0},
dst: [4]uint32{183762951, 0, 0, 0},
direction: constants.OUTBOUND,
}: {
totalReports: 3,
},
},
},
want: []float64{
3,
Expand Down Expand Up @@ -611,26 +590,6 @@ func TestBuildConnectionMetricsToPrometheus(t *testing.T) {
responseFlags: "-",
connectionSecurityPolicy: "mutual_tls",
},
tcpConns: map[connectionSrcDst]connMetric{
{
src: [4]uint32{183763210, 0, 0, 0},
dst: [4]uint32{183762951, 0, 0, 0},
direction: constants.INBOUND,
}: {
sentBytes: 0x0000003,
receivedBytes: 0x0000004,
packetLost: 0x0000001,
totalRetrans: 0x0000002,
totalReports: 1,
},
{
src: [4]uint32{183763210, 0, 0, 0},
dst: [4]uint32{183762951, 0, 0, 0},
direction: constants.OUTBOUND,
}: {
totalReports: 3,
},
},
},
want: []float64{
4,
Expand Down Expand Up @@ -681,7 +640,7 @@ func TestBuildConnectionMetricsToPrometheus(t *testing.T) {
}

deleteConnection = []*connectionMetricLabels{}
m.updateConnectionMetricCache(tt.args.data, tt.args.tcpConns[tt.args.data.conSrcDstInfo], tt.args.labels)
m.updateConnectionMetricCache(tt.args.data, tt.args.labels)
assert.Equal(t, m.connectionMetricCache[tt.args.labels].ConnSentBytes, tt.want[0])
assert.Equal(t, m.connectionMetricCache[tt.args.labels].ConnReceivedBytes, tt.want[1])
assert.Equal(t, m.connectionMetricCache[tt.args.labels].ConnPacketLost, tt.want[2])
Expand Down
Loading