Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 16, 2025

This PR updates the JmxMetric smoke test to use the new assertion framework introduced in #4141, making the test more readable and maintainable while preserving all existing functionality.

Changes Made

1. Extended MetricAssert Framework

  • Added hasNoInternalAttributes() method to verify that metric properties don't start with "applicationinsights.internal."
  • This provides a cleaner way to validate internal attribute constraints

2. Updated JmxMetricTest

  • Modified verifyJmxMetricsSentToBreeze() method to use MetricAssert instances instead of direct assertThat() calls
  • Replaced manual assertion logic with fluent assertion methods:
    • hasValue(5) for NameWithDot metric
    • hasValue(1.0) for BooleanJmxMetric
    • hasNoInternalAttributes() for all metrics
  • Preserved all existing comments and complex GC metric validation logic
  • Removed unused verifyNoInternalAttributes() helper method

3. Minimal Impact Changes

The changes are surgical and maintain:

  • All existing test coverage and behavior
  • Complex wildcard and GC metric validation logic
  • Java version-specific handling for metrics
  • Existing comments explaining metric behavior

Example of Changes

Before:

if (metricName.equals("NameWithDot")) {
  assertThat(value).isEqualTo(5);
}
if (metricName.equals("BooleanJmxMetric")) {
  assertThat(value).isEqualTo(1.0);
}
assertThat(verifyNoInternalAttributes(envelope)).isTrue();

After:

// Create MetricAssert for this envelope and use it for validation
MetricAssert metricAssert = new MetricAssert(envelope);

// Common validation - all metrics should have no internal attributes
metricAssert.hasNoInternalAttributes();

if (metricName.equals("NameWithDot")) {
  metricAssert.hasValue(5);
}
if (metricName.equals("BooleanJmxMetric")) {
  metricAssert.hasValue(1.0);
}

Testing

  • All JmxMetric smoke tests pass successfully
  • Ran ./gradlew spotlessApply to ensure proper formatting
  • Verified the assertion framework extension works correctly

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@trask trask closed this Jul 16, 2025
Copilot AI changed the title [WIP] Update the JmxMetric smoke test to use the new assertion framework introduced in @microsoft/ApplicationInsights-Java/pull/4141 Keep changes minimal to make it easier to review. Preserve existing comments where possible. Extend the assertion framework... Update JmxMetric smoke test to use new assertion framework Jul 16, 2025
Copilot AI requested a review from trask July 16, 2025 02:33
@trask trask deleted the copilot/fix-48a2280b-03e9-40c0-aefd-5888a966f064 branch July 23, 2025 01:15
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