Skip to content

Comments

feat: Add append_dimensions tests for collectd, ethtool, and cpu plugins#647

Open
TravisStark wants to merge 2 commits intomainfrom
tjstark/collectd-append
Open

feat: Add append_dimensions tests for collectd, ethtool, and cpu plugins#647
TravisStark wants to merge 2 commits intomainfrom
tjstark/collectd-append

Conversation

@TravisStark
Copy link
Contributor

@TravisStark TravisStark commented Feb 9, 2026

Description of the issue

The CloudWatch Agent supports append_dimensions at two configuration levels with different behaviors:

  • Global level (metrics.append_dimensions): Adds EC2 metadata dimensions and drops the host dimension
  • Plugin level (metrics_collected.<plugin>.append_dimensions): Adds dimensions while keeping the host dimension

There were no integration tests validating this behavioral difference for collectd, CPU, or ethtool plugins. This gap made it difficult to catch regressions in dimension handling logic.

Description of changes

Added comprehensive integration tests for append_dimensions support across multiple plugins:

Collectd tests:

  • CollectdNoAppendDimensions - Baseline: verifies host is present and InstanceId is absent without configuration
  • CollectdGlobalAppendDimensions - Verifies global config adds InstanceId/InstanceType and drops host
  • CollectdAppendDimensions - Verifies plugin-level config adds dimensions while keeping host
  • CollectdFleetAggregation - Verifies plugin-level config works with aggregation_dimensions

CPU tests:

  • CpuGlobalAppendDimensions - Verifies global config behavior for CPU metrics

Ethtool tests:

  • EthtoolAppendDimensions - Verifies global config drops host
  • EthtoolPluginAppendDimensions - Verifies plugin-level config keeps host

Infrastructure improvements:

  • Added ethtool_test_helpers.go
  • Updated metrics_dimension_test.go with dynamic column widths in summary table
  • Added test descriptions map for CI-friendly output

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

  • Test Run
  • Passing Metric Dimensions Test
  • All new test files compile successfully with go build ./...
  • Tests follow existing patterns in the metric_dimension test suite
  • Each test validates both positive cases (expected dimensions present) and negative cases (unexpected dimensions absent)
  • Collectd tests use common.SendCollectDMetrics() to generate test data


Screenshot 2026-02-09 at 2 41 35 PM

@TravisStark TravisStark requested a review from a team as a code owner February 9, 2026 14:54
@TravisStark TravisStark force-pushed the tjstark/collectd-append branch from b9614ef to a5deece Compare February 9, 2026 17:31
Copy link
Contributor

@the-mann the-mann left a comment

Choose a reason for hiding this comment

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

Can you extract the common validation logic? The 7 test files have significant duplication. A shared helper function for dimension validation would reduce this.

@TravisStark TravisStark force-pushed the tjstark/collectd-append branch from a5deece to 9dbae34 Compare February 16, 2026 19:16
@the-mann
Copy link
Contributor

code review agent:

Code Review: PR #647

PR: feat: Add append_dimensions tests for collectd, ethtool, and cpu plugins
Author: TravisStark
Branch: tjstark/collectd-appendmain
Changes: 19 files, +1138/-109 lines

CI Status

⚠️ No workflow runs found for current commit SHA (9dbae34)


Findings

Major

1. CollectdFleetAggregationTestRunner doesn't use shared helpers

File: collectd_fleet_aggregation_test.go:68-179

This test manually constructs dimensions instead of using the new DimensionSpec helpers that all other tests use. This defeats the refactoring purpose and creates inconsistency.

Suggested fix:

func (t *CollectdFleetAggregationTestRunner) validateCollectdFleetAggregationMetric(metricName string) status.TestResult {
    metricType := metric.GetCollectDMetricType(metricName)
    ns := "CollectdFleetAggregationTest"

    // Test 1: Fleet-aggregated dimensions
    fleetSpecs := []DimensionSpec{
        ExactDim("Component", "WebServer"),
        ExactDim("type", metricType),
    }
    result := ValidateDimensionsPresent(&t.BaseTestRunner, ns, metricName, fleetSpecs)
    if result.Status != status.SUCCESSFUL {
        return result
    }

    // Test 2: Per-instance dimensions
    instanceSpecs := []DimensionSpec{
        ExactDim("Component", "WebServer"),
        ExactDim("type", metricType),
        {Key: "InstanceId"},
    }
    result = ValidateDimensionsPresent(&t.BaseTestRunner, ns, metricName, instanceSpecs)
    if result.Status != status.SUCCESSFUL {
        return result
    }

    // Test 3: Host dimension kept
    hostSpecs := []DimensionSpec{
        ExactDim("Component", "WebServer"),
        ExactDim("type", metricType),
        HostDim(),
    }
    return ValidateDimensionsPresent(&t.BaseTestRunner, ns, metricName, hostSpecs)
}

Minor

2. Hardcoded driver name "ena"

File: ethtool_append_dimensions_test.go:68-69

ExactDim("driver", "ena"),

Consider adding a comment noting this is EC2-specific.

3. Changed log.Printf to fmt.Printf

File: metrics_dimension_test.go:190-200

This removes timestamps from output. Verify this is intentional.

4. printTestSummaryTable adds 70+ lines to test file

File: metrics_dimension_test.go:55-127

Consider moving to a separate helper file.


Positive Observations

  • Good test coverage (positive and negative cases)
  • Excellent documentation of global vs plugin-level append_dimensions behavior
  • Refactoring reduces duplication via dimension_validation_helpers.go
  • Follows existing ITestRunner patterns
  • Correct //go:build !windows tags

Verdict

Approve with minor suggestions

Main concern: CollectdFleetAggregationTestRunner should use shared helpers for consistency.

Copy link
Contributor

@the-mann the-mann left a comment

Choose a reason for hiding this comment

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

please rerun tests with refactor and i'll approve

@the-mann
Copy link
Contributor

you can ignore the other stuff kiro mentioned btw i think it's all too minor to act on

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.

3 participants