Skip to content

Commit a285d8e

Browse files
committed
fix network interfaces
1 parent 76f42de commit a285d8e

8 files changed

+1638
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: kubeletstatsreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: scrape network metrics for all interfaces of k8s pods and nodes
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [30196]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/kubeletstatsreceiver/internal/kubelet/network.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ import (
1010
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver/internal/metadata"
1111
)
1212

13-
type getNetworkDataFunc func(s *stats.NetworkStats) (rx *uint64, tx *uint64)
13+
type getNetworkDataFunc func(s *stats.InterfaceStats) (rx *uint64, tx *uint64)
1414

1515
func addNetworkMetrics(mb *metadata.MetricsBuilder, networkMetrics metadata.NetworkMetrics, s *stats.NetworkStats, currentTime pcommon.Timestamp) {
1616
if s == nil {
1717
return
1818
}
1919

20-
recordNetworkDataPoint(mb, networkMetrics.IO, s, getNetworkIO, currentTime)
21-
recordNetworkDataPoint(mb, networkMetrics.Errors, s, getNetworkErrors, currentTime)
20+
for i := range s.Interfaces {
21+
recordNetworkDataPoint(mb, networkMetrics.IO, &s.Interfaces[i], getNetworkIO, currentTime)
22+
recordNetworkDataPoint(mb, networkMetrics.Errors, &s.Interfaces[i], getNetworkErrors, currentTime)
23+
}
2224
}
2325

24-
func recordNetworkDataPoint(mb *metadata.MetricsBuilder, recordDataPoint metadata.RecordIntDataPointWithDirectionFunc, s *stats.NetworkStats, getData getNetworkDataFunc, currentTime pcommon.Timestamp) {
26+
func recordNetworkDataPoint(mb *metadata.MetricsBuilder, recordDataPoint metadata.RecordIntDataPointWithDirectionFunc, s *stats.InterfaceStats, getData getNetworkDataFunc, currentTime pcommon.Timestamp) {
2527
rx, tx := getData(s)
2628

2729
if rx != nil {
@@ -33,10 +35,10 @@ func recordNetworkDataPoint(mb *metadata.MetricsBuilder, recordDataPoint metadat
3335
}
3436
}
3537

36-
func getNetworkIO(s *stats.NetworkStats) (*uint64, *uint64) {
38+
func getNetworkIO(s *stats.InterfaceStats) (*uint64, *uint64) {
3739
return s.RxBytes, s.TxBytes
3840
}
3941

40-
func getNetworkErrors(s *stats.NetworkStats) (*uint64, *uint64) {
42+
func getNetworkErrors(s *stats.InterfaceStats) (*uint64, *uint64) {
4143
return s.RxErrors, s.TxErrors
4244
}

receiver/kubeletstatsreceiver/scraper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const (
3333
numVolumes = 8
3434

3535
// Number of metrics by resource
36-
nodeMetrics = 15
37-
podMetrics = 15
36+
nodeMetrics = 19
37+
podMetrics = 19
3838
containerMetrics = 11
3939
volumeMetrics = 5
4040
)

0 commit comments

Comments
 (0)