Skip to content

SOLR-18455: actually disable metrics on <metrics enabled="false"/> - #4902

Merged
mkhludnev merged 7 commits into
apache:mainfrom
mkhludnev:copilot/analyze-leak-issue
Sep 21, 2026
Merged

mkhludnev merged 7 commits into
apache:mainfrom
mkhludnev:copilot/analyze-leak-issue

Conversation

@mkhludnev

@mkhludnev mkhludnev commented Sep 10, 2026

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/SOLR-18455

Description

Please provide a short description of the changes you're making with this pull request.

Solution

Please provide a short description of the approach taken to implement your solution.
We appreciate transparent disclosure of significant AI Coding assistants usage.

Tests

Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

Copilot AI and others added 2 commits September 10, 2026 22:08
Co-authored-by: mkhludnev <807522+mkhludnev@users.noreply.github.com>
Co-authored-by: mkhludnev <807522+mkhludnev@users.noreply.github.com>
assertU(adoc("id", "1000000", "field1_s", "foo"));
openNewSearcherAndWait();

assertEventuallyReleased(replacedSearcher);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

too heavy test. Put it into Nightly or drop?

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.

If a test take a while depending on the person environment, probably nightly makes sense if that is the case in this test.

@mkhludnev mkhludnev Sep 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dsmiley
dsmiley requested a review from mlbiscoc September 11, 2026 01:14
@mkhludnev

Copy link
Copy Markdown
Member Author

at least this patch let to disable metrics and it let me pass the benchmark for #4749

@dsmiley dsmiley changed the title SolrIndexSearcher is retained for the life of the node by OpenTelemetry observable gauges SOLR-18422: SolrIndexSearcher OpenTelemetry observable gauges memory leak Sep 11, 2026
public void testReplacedSearcherCanBeGarbageCollected() throws Exception {
WeakReference<SolrIndexSearcher> replacedSearcher = registerCurrentSearcherForGcCheck();

assertU(adoc("id", "1000000", "field1_s", "foo"));

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 doc needs to be deleted at the end of the test to avoid index pollution for other tests.

@sigram

sigram commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Running with metricsEnabled=false produces this exception:

2026-09-14 12:01:09.161 ERROR (qtp1465346452-42-localhost-12) [ t:localhost-12] o.a.s.s.HttpSolrCall 500 Exception
java.io.IOException: No metrics found in response
        at org.apache.solr.response.PrometheusResponseWriter.write(PrometheusResponseWriter.java:66)
        at org.apache.solr.servlet.HttpSolrCall.writeResponse(HttpSolrCall.java:814)
        at org.apache.solr.servlet.HttpSolrCall.logAndFlushAdminRequest(HttpSolrCall.java:730)
        at org.apache.solr.servlet.HttpSolrCall.handleAdminRequest(HttpSolrCall.java:712)
        at org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:478)
        at org.apache.solr.servlet.SolrServlet.dispatch(SolrServlet.java:114)

Edit: this looks like a pre-existing bug, it happens also on main.

}
});
// size of the currently opened commit
solrMetricsContext.observableDoubleGauge(

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.

Based on this PR is what caused the leak. Do we need the rest of this stuff then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's up you. #4902 is just a draft by claude, which unblocked my longevity test.

assertU(adoc("id", "1000000", "field1_s", "foo"));
openNewSearcherAndWait();

assertEventuallyReleased(replacedSearcher);

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.

If a test take a while depending on the person environment, probably nightly makes sense if that is the case in this test.

Comment on lines +376 to +381
private Meter meter(String registry) {
if (!enabled) {
return OpenTelemetry.noop().getMeterProvider().get(OTEL_SCOPE_NAME);
}
return meterProvider(registry).get(OTEL_SCOPE_NAME);
}

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 think this PR should be rescoped and titled to fixing this disabling of metrics.

@mkhludnev mkhludnev Sep 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 like the changes for this on disabling metrics. Can you change the title to SOLR-18455 and rip out the searcher changes? The other PR should be the actual fix for the leak.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@mkhludnev mkhludnev changed the title SOLR-18422: SolrIndexSearcher OpenTelemetry observable gauges memory leak SOLR-18455: actually disable metrics on <metrics enabled="false"/> Sep 17, 2026
@mkhludnev

Copy link
Copy Markdown
Member Author

it seems to cause the fail

10426 INFO  (TEST-TestPullReplicaWithAuth.testPKIAuthWorksForPullReplication-seed#[E8AE82F6E427848D]) [n:127.0.0.1:42647_solr] o.a.s.SolrTestCaseJ4 ###Ending testPKIAuthWorksForPullReplication
   >     java.lang.NullPointerException: Cannot invoke "io.opentelemetry.exporter.prometheus.PrometheusMetricReader.collect()" because "reader" is null
   >         at __randomizedtesting.SeedInfo.seed([E8AE82F6E427848D:BD9471DA03F7D9BB]:0)
   >         at org.apache.solr.util.SolrMetricTestUtils.getDataPointSnapshot(SolrMetricTestUtils.java:85)
   >         at org.apache.solr.util.SolrMetricTestUtils.getDataPoint(SolrMetricTestUtils.java:141)
   >         at org.apache.solr.util.SolrMetricTestUtils.getDatapoint(SolrMetricTestUtils.java:136)
   >         at org.apache.solr.util.SolrMetricTestUtils.getCounterDatapoint(SolrMetricTestUtils.java:151)
   >         at org.apache.solr.cloud.TestPullReplicaWithAuth.testPKIAuthWorksForPullReplication(TestPullReplicaWithAuth.java:111)

@mkhludnev mkhludnev added this to the 10.x milestone Sep 18, 2026
@mkhludnev
mkhludnev marked this pull request as ready for review September 18, 2026 17:49
Comment on lines +41 to +42
previousMetricsEnabled = System.getProperty("metricsEnabled");
System.setProperty("metricsEnabled", "false");

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.

why do this? Solr's test infrastructure ensures that each test suite (class) starts with the same set of system properties, thus making it impossible for one test suite to mess with system properties in a way affecting another test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks @dsmiley

@mkhludnev
mkhludnev requested a review from dsmiley September 20, 2026 11:01
return builder;
}

private Meter meter(String registry) {

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.

why introduce this... couldn't you modify the meterProvider method here to do this enabled check and respond similarly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right! Thanks @dsmiley

@mkhludnev
mkhludnev merged commit 4ceaa32 into apache:main Sep 21, 2026
5 of 7 checks passed
dsmiley pushed a commit that referenced this pull request Sep 22, 2026
…4902)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mkhludnev <807522+mkhludnev@users.noreply.github.com>
(cherry picked from commit 4ceaa32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants