Skip to content

Commit a2b67d9

Browse files
authored
fix(hostmetricsreceiver): do not duplicate mountpoint metrics (#34635)
Mountpoints can be reported multiple times for each mount into a namespace. This causes duplicate metrics which causes issues with some exporters. Each instance of the mountpoint will have identical metrics, so it is safe to ignore repeated mountpoints. Closes #34512 **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.>
1 parent a4fd3ae commit a2b67d9

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: 'bug_fix'
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: hostmetrics receiver
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Fix duplicate filesystem metrics"
9+
10+
# One or more tracking issues related to the change
11+
issues: [34635, 34512]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: "The hostmetrics exposes duplicate metrics of identical mounts exposed in namespaces. The duplication causes errors in exporters that are sensitive to duplicate metrics. We can safely drop the duplicates as the metrics should be exactly the same."

receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,23 @@ func (s *scraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
9191
}
9292

9393
usages := make([]*deviceUsage, 0, len(partitions))
94+
95+
type mountKey struct {
96+
mountpoint string
97+
device string
98+
}
99+
seen := map[mountKey]struct{}{}
100+
94101
for _, partition := range partitions {
102+
key := mountKey{
103+
mountpoint: partition.Mountpoint,
104+
device: partition.Device,
105+
}
106+
if _, ok := seen[key]; partition.Mountpoint != "" && ok {
107+
continue
108+
}
109+
seen[key] = struct{}{}
110+
95111
if !s.fsFilter.includePartition(partition) {
96112
continue
97113
}

receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,41 @@ func TestScrape(t *testing.T) {
347347
usageFunc: func(context.Context, string) (*disk.UsageStat, error) { return nil, errors.New("err2") },
348348
expectedErr: "err2",
349349
},
350+
{
351+
name: "Do not report duplicate mount points",
352+
config: Config{
353+
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
354+
},
355+
usageFunc: func(context.Context, string) (*disk.UsageStat, error) {
356+
return &disk.UsageStat{
357+
Fstype: "fs_type_a",
358+
}, nil
359+
},
360+
partitionsFunc: func(context.Context, bool) ([]disk.PartitionStat, error) {
361+
return []disk.PartitionStat{
362+
{
363+
Device: "device_a",
364+
Mountpoint: "mount_point_a",
365+
Fstype: "fs_type_a",
366+
},
367+
{
368+
Device: "device_a",
369+
Mountpoint: "mount_point_a",
370+
Fstype: "fs_type_a",
371+
},
372+
}, nil
373+
},
374+
expectMetrics: true,
375+
expectedDeviceDataPoints: 1,
376+
expectedDeviceAttributes: []map[string]pcommon.Value{
377+
{
378+
"device": pcommon.NewValueStr("device_a"),
379+
"mountpoint": pcommon.NewValueStr("mount_point_a"),
380+
"type": pcommon.NewValueStr("fs_type_a"),
381+
"mode": pcommon.NewValueStr("unknown"),
382+
},
383+
},
384+
},
350385
}
351386

352387
for _, test := range testCases {

0 commit comments

Comments
 (0)