Skip to content

[chore] functional_test updates#2255

Open
jinja2 wants to merge 1 commit intomainfrom
fix-expected-sampling
Open

[chore] functional_test updates#2255
jinja2 wants to merge 1 commit intomainfrom
fix-expected-sampling

Conversation

@jinja2
Copy link
Collaborator

@jinja2 jinja2 commented Feb 25, 2026

Description:

  1. Ignore schema URL in trace comparisons across all functional tests - these bump with most upstream SDK release and adds more test fixture maintenance

  2. SelectMetricSet falls back to the most complete payload when no exact count match exists. Also returns a bool indicating whether an exact match was found, logged on failure for diagnostics.

@jinja2 jinja2 marked this pull request as ready for review February 25, 2026 23:01
@jinja2 jinja2 requested a review from a team as a code owner February 25, 2026 23:01
Copilot AI review requested due to automatic review settings February 25, 2026 23:01
@jinja2 jinja2 requested a review from a team as a code owner February 25, 2026 23:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates functional test helpers to reduce golden fixture churn and improve metric-batch selection diagnostics when expected metric counts don’t line up exactly.

Changes:

  • Strip trace schema URLs before comparing traces (and before writing updated golden traces).
  • Update SelectMetricSet to prefer exact count matches, otherwise fall back to the most “complete” metrics batch and return whether an exact match was found.
  • Propagate the exactMatch signal to selected functional tests for better failure logging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
functional_tests/istio/istio_test.go Uses updated metrics selection signature; clears trace schema URLs prior to trace comparisons.
functional_tests/internal/common.go Adds ClearTraceSchemaURLs; changes metrics batch selection API to return fallback + exact-match bool.
functional_tests/functional/functional_test.go Clears trace schema URLs in multiple language trace tests; uses new metrics selection return values and logs when not exact-match.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 444 to +455
for h := len(metricSink.AllMetrics()) - 1; h >= 0; h-- {
m := metricSink.AllMetrics()[h]
foundTargetMetric := false

OUTER:
for i := 0; i < m.ResourceMetrics().Len(); i++ {
for j := 0; j < m.ResourceMetrics().At(i).ScopeMetrics().Len(); j++ {
for k := 0; k < m.ResourceMetrics().At(i).ScopeMetrics().At(j).Metrics().Len(); k++ {
metric := m.ResourceMetrics().At(i).ScopeMetrics().At(j).Metrics().At(k)
if metric.Name() == targetMetric {
foundTargetMetric = true
break OUTER
}
}
}
}

if !foundTargetMetric {
if !containsMetric(m, targetMetric) {
continue
}

if ignoreLen || (m.ResourceMetrics().Len() == expected.ResourceMetrics().Len() && m.MetricCount() == expected.MetricCount()) {
selectedMetrics = &m
t.Logf("Found target metric '%s' in payload with %d total metrics", targetMetric, m.MetricCount())
if m.ResourceMetrics().Len() == expected.ResourceMetrics().Len() && m.MetricCount() == expected.MetricCount() {
exactMatch = &m
break
}
if m.MetricCount() > fallbackCount {
fallback = &m
fallbackCount = m.MetricCount()
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

SelectMetricSet stores &m where m is the loop variable (m := metricSink.AllMetrics()[h]). In Go this results in returning a pointer to the same variable reused across iterations, so exactMatch/fallback can end up pointing at the wrong payload. Create a per-iteration copy before taking the address (or store the index and take the address of a stable slice element).

Copilot uses AI. Check for mistakes.
Comment on lines 490 to 493
require.Eventuallyf(t, func() bool {
selectedMetrics = SelectMetricSet(t, expected, targetMetric, metricSink, ignoreLen)
selectedMetrics, exactMatch = SelectMetricSet(t, expected, targetMetric, metricSink)
return selectedMetrics != nil
}, timeout, interval, "Failed to find target metric %s within timeout period of %v", targetMetric, timeout)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

SelectMetricSetWithTimeout stops polling as soon as any payload containing the target metric exists (return selectedMetrics != nil). Since SelectMetricSet now returns a non-nil fallback even when counts don’t match, this can return early with an incomplete batch and miss a later exact-match / more complete batch that arrives before the timeout. Consider continuing to retry until an exact match is found (tracking the best fallback seen so far) and only returning the fallback after the timeout expires.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

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

LGTM, with a very nit suggestion.

Comment on lines +440 to +441
var exactMatch *pmetric.Metrics
var fallback *pmetric.Metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps I'm being guided by the diff above in which exactMatch was a boolean, but felt that this nit makes more readable:

Suggested change
var exactMatch *pmetric.Metrics
var fallback *pmetric.Metrics
var exactMatchMetrics *pmetric.Metrics
var fallbackMetrics *pmetric.Metrics

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.

4 participants