From 5ec740e5c70d62d3b24a3d5c99ae76d6c22c190d Mon Sep 17 00:00:00 2001 From: KimMJ Date: Sat, 12 Sep 2026 00:21:50 +0900 Subject: [PATCH 1/2] [connector/spanmetrics] Skip resource iteration in resetState when nothing needs resetting The early-return guard in resetState still required Histogram.Disable, but since #32210 histograms only add work to the loop when exemplars are enabled. With the default configuration (cumulative, histograms enabled, exemplars off, no expiration) every flush iterated over all cached resources under the connector lock without doing anything. Drop the Histogram.Disable condition so the loop only runs when exemplar clearing, series expiration or metrics expiration is configured. Assisted-by: Claude Opus 5 --- .../spanmetrics-skip-reset-iteration.yaml | 28 +++++++++++++++++++ connector/spanmetricsconnector/connector.go | 2 +- .../spanmetricsconnector/connector_test.go | 12 ++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .chloggen/spanmetrics-skip-reset-iteration.yaml diff --git a/.chloggen/spanmetrics-skip-reset-iteration.yaml b/.chloggen/spanmetrics-skip-reset-iteration.yaml new file mode 100644 index 0000000000000..691b831604894 --- /dev/null +++ b/.chloggen/spanmetrics-skip-reset-iteration.yaml @@ -0,0 +1,28 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) +component: connector/span_metrics + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Skip the per-flush resource iteration in cumulative mode when no exemplar clearing or expiration is configured. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +# TODO: fill in the PR number. +issues: [] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/connector/spanmetricsconnector/connector.go b/connector/spanmetricsconnector/connector.go index 6851dfb2ca325..edd2ee5687373 100644 --- a/connector/spanmetricsconnector/connector.go +++ b/connector/spanmetricsconnector/connector.go @@ -379,7 +379,7 @@ func (p *connectorImp) resetState() { // If none of these features are enabled then we can skip the remaining operations. // Enabling either of these features requires to go over resource metrics and do operation on each. - if p.config.Histogram.Disable && p.config.MetricsExpiration == 0 && p.config.SeriesExpiration == 0 && !p.config.Exemplars.Enabled { + if p.config.MetricsExpiration == 0 && p.config.SeriesExpiration == 0 && !p.config.Exemplars.Enabled { return } diff --git a/connector/spanmetricsconnector/connector_test.go b/connector/spanmetricsconnector/connector_test.go index 2669188de30e5..ecf524172e551 100644 --- a/connector/spanmetricsconnector/connector_test.go +++ b/connector/spanmetricsconnector/connector_test.go @@ -1432,6 +1432,18 @@ func TestSeriesExpiration(t *testing.T) { assert.True(t, hasDataPointWithStringAttrValue(exported, "B")) } +func TestResetStateSkipsIterationWhenNothingToReset(t *testing.T) { + p, err := newConnectorImp(new("defaultNullValue"), explicitHistogramsConfig, disabledExemplarsConfig, disabledEventsConfig, cumulative, 0, []string{}, 1000, clockwork.NewFakeClock(), false) + require.NoError(t, err) + require.NoError(t, p.ConsumeTraces(metadata.NewIncomingContext(t.Context(), nil), buildSampleTrace())) + + // With cumulative temporality and no exemplars or expiration configured, resetState has + // nothing to do per resource, so it must not iterate over (and allocate a key slice for) the cache. + allocs := testing.AllocsPerRun(10, p.resetState) + assert.Zero(t, allocs) + assert.Equal(t, 2, p.resourceMetrics.Len()) +} + func TestResourceMetricsKeyAttributes(t *testing.T) { resourceMetricsKeyAttributes := []string{ "service.name", From 6158e62adf0fc7780b08b171e4a96cd1caee41d6 Mon Sep 17 00:00:00 2001 From: KimMJ Date: Sat, 12 Sep 2026 01:36:50 +0900 Subject: [PATCH 2/2] Add PR number to changelog entry Assisted-by: Claude Opus 5 --- .chloggen/spanmetrics-skip-reset-iteration.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.chloggen/spanmetrics-skip-reset-iteration.yaml b/.chloggen/spanmetrics-skip-reset-iteration.yaml index 691b831604894..8b51a4f8425ec 100644 --- a/.chloggen/spanmetrics-skip-reset-iteration.yaml +++ b/.chloggen/spanmetrics-skip-reset-iteration.yaml @@ -10,8 +10,7 @@ component: connector/span_metrics note: Skip the per-flush resource iteration in cumulative mode when no exemplar clearing or expiration is configured. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -# TODO: fill in the PR number. -issues: [] +issues: [50925] # (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.