Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hostmetricsreceiver): do not duplicate mountpoint metrics #34635

Merged
merged 6 commits into from
Oct 9, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'bug_fix'

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: hostmetrics receiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix duplicate filesystem metrics"

# One or more tracking issues related to the change
issues: [34635, 34512]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
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."
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,23 @@ func (s *scraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
}

usages := make([]*deviceUsage, 0, len(partitions))

type mountKey struct {
mountpoint string
device string
}
seen := map[mountKey]struct{}{}

for _, partition := range partitions {
key := mountKey{
mountpoint: partition.Mountpoint,
device: partition.Device,
}
if _, ok := seen[key]; partition.Mountpoint != "" && ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify to me why the check for Mountpoint being an empty string is here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Virtual partitions" test fails without that as virtual partitions don't have mount points. See test Include device filtering that includes virtual partitions (I'm not really convinced about the validity of that particular feature/test, you get mount entries without devices, where only a filesystem type like procfs is used, but they do get mounted somewhere)

continue
}
seen[key] = struct{}{}

if !s.fsFilter.includePartition(partition) {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,41 @@ func TestScrape(t *testing.T) {
usageFunc: func(context.Context, string) (*disk.UsageStat, error) { return nil, errors.New("err2") },
expectedErr: "err2",
},
{
name: "Do not report duplicate mount points",
config: Config{
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
usageFunc: func(context.Context, string) (*disk.UsageStat, error) {
return &disk.UsageStat{
Fstype: "fs_type_a",
}, nil
},
partitionsFunc: func(context.Context, bool) ([]disk.PartitionStat, error) {
return []disk.PartitionStat{
{
Device: "device_a",
Mountpoint: "mount_point_a",
Fstype: "fs_type_a",
},
{
Device: "device_a",
Mountpoint: "mount_point_a",
Fstype: "fs_type_a",
},
}, nil
},
expectMetrics: true,
expectedDeviceDataPoints: 1,
expectedDeviceAttributes: []map[string]pcommon.Value{
{
"device": pcommon.NewValueStr("device_a"),
"mountpoint": pcommon.NewValueStr("mount_point_a"),
"type": pcommon.NewValueStr("fs_type_a"),
"mode": pcommon.NewValueStr("unknown"),
},
},
},
}

for _, test := range testCases {
Expand Down