Skip to content

Paramadon/instance store metrics - #1801

Closed
Paramadon wants to merge 11 commits into
mainfrom
paramadon/InstanceStoreMetrics
Closed

Paramadon/instance store metrics#1801
Paramadon wants to merge 11 commits into
mainfrom
paramadon/InstanceStoreMetrics

Conversation

@Paramadon

Copy link
Copy Markdown
Contributor

Description of the issue

Describe the problem or feature in addition to a link to the issues.

Description of changes

How does this change address the problem?

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Describe what tests you have done.

Requirements

Before commiting your code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

Integration Tests

To run integration tests against this PR, add the ready for testing label.

@duhminick duhminick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming that awsnvmereceiver is the final receiver for both EBS and instance store

Comment thread receiver/awsnvmereceiver/config.go Outdated
Comment on lines +62 to +123
// Sanitize input by trimming whitespace and null bytes
device = strings.TrimSpace(device)
if strings.Contains(device, "\x00") {
return errors.New("device path cannot contain null bytes")
}

// Validate device path format first
if !strings.HasPrefix(device, "/dev/") {
return errors.New("device path must start with /dev/")
}

// Check for path traversal attempts - multiple patterns
if strings.Contains(device, "..") {
return errors.New("device path cannot contain '..'")
}
if strings.Contains(device, "./") {
return errors.New("device path cannot contain relative path components")
}
if strings.Contains(device, "//") {
return errors.New("device path cannot contain double slashes")
}

// Prevent directory traversal attacks
cleanPath := filepath.Clean(device)
if cleanPath != device {
return errors.New("device path contains invalid characters")
}

// Validate absolute path doesn't escape /dev
absPath, err := filepath.Abs(device)
if err != nil {
return errors.New("device path is not a valid absolute path")
}
if !strings.HasPrefix(absPath, "/dev/") {
return errors.New("device path must resolve to /dev/ directory")
}

// Validate NVMe device naming pattern with stricter regex-like validation
if !strings.HasPrefix(device, "/dev/nvme") {
return errors.New("device path must be an NVMe device (/dev/nvme*)")
}

// Additional validation for NVMe device name format
deviceName := strings.TrimPrefix(device, "/dev/nvme")
if len(deviceName) == 0 {
return errors.New("invalid NVMe device name format")
}

// Check for suspicious characters that could be used in attacks
for _, char := range deviceName {
if !isValidNVMeDeviceChar(char) {
return errors.New("device path contains invalid characters for NVMe device")
}
}

// Validate maximum path length to prevent buffer overflow attacks
if len(device) > 255 {
return errors.New("device path exceeds maximum allowed length")
}

return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we do this for the other diskio related receivers. We could add it (?) though I don't know if we really wanna fail by returning an error. Maybe just a log message

@@ -0,0 +1,182 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will need to get updated by using mdatagen

Comment thread receiver/awsnvmereceiver/scraper.go Outdated
Comment on lines +91 to +96
// Get InstanceId from EC2 metadata service
instanceID, err := s.metadataProvider.InstanceID(ctx)
if err != nil {
s.logger.Warn("unable to get instance ID from metadata service, using placeholder", zap.Error(err))
instanceID = "unknown"
}

@duhminick duhminick Aug 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a processor in the pipeline that should handle this already. User can specify that they want instance ID in the append dimensions

Comment thread receiver/awsnvmereceiver/scraper.go Outdated
zap.Int("controllerID", device.Controller()),
zap.Error(err))
// Use a placeholder serial number to allow metrics collection
serial = fmt.Sprintf("unknown-controller-%d", device.Controller())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't think of what I want here but unknown-controller-%d is bit iffy to me

Comment thread receiver/awsnvmereceiver/scraper.go Outdated
}

// For EBS devices, format the serial as volume ID
if deviceType == "ebs" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would make ebs/InstanceStore an enum or something

@@ -0,0 +1,20 @@
//go:build !linux

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should rename these instance_store_metrics_* files to be related to be broadly NVMe instead

@@ -1,31 +1,116 @@
# Maximum buffer size in MB (minimum 3). Choose 0 to use 1% of host memory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This needs to be changed back.

@@ -52,7 +54,9 @@ func NewTranslators(conf *confmap.Conf, configSection, os string) (common.Transl
})
}

if shouldAddEbsReceiver(conf, configSection) {
if shouldAddUnifiedNvmeReceiver(conf, configSection) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This needs to be just one receiver.

@Paramadon
Paramadon force-pushed the paramadon/InstanceStoreMetrics branch from 58cf3c6 to bfe1fdf Compare August 4, 2025 16:36
}

// validateDevice validates a single device path with comprehensive security checks
func (cfg *Config) validateDevice(device string) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's not fail outright nor do we need to have a lot of error handling here, let's look at what we did for ebsnvme


// InstanceStoreMetrics represents the parsed metrics from the Instance Store NVMe log page 0xC0.
// Similar to EBS but skips EBS-specific fields (EBSIOPSExceeded, EBSThroughputExceeded).
type InstanceStoreMetrics struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Change this to have bins and update the reserved to 888. And you can add some debug statements to see output.

@@ -0,0 +1,385 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need all the error handling

@@ -0,0 +1,108 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should basically be the same awsebsnvme receiver.

@Paramadon Paramadon closed this Aug 8, 2025
@Paramadon
Paramadon deleted the paramadon/InstanceStoreMetrics branch August 8, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants