mlbiscoc commented on code in PR #4917:
URL: https://github.com/apache/solr/pull/4917#discussion_r4030757699
##########
solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java:
##########
@@ -160,65 +160,67 @@ public DoubleGauge doubleGauge(String metricName, String
description, OtelUnit u
public ObservableLongGauge observableLongGauge(
String metricName, String description,
Consumer<ObservableLongMeasurement> callback) {
- var observableLongGauge = observableLongGauge(metricName, description,
callback, null);
- closeables.add(observableLongGauge);
- return observableLongGauge;
+ return observableLongGauge(metricName, description, callback, null);
}
public ObservableLongGauge observableLongGauge(
String metricName,
String description,
Consumer<ObservableLongMeasurement> callback,
OtelUnit unit) {
- return metricManager.observableLongGauge(registryName, metricName,
description, callback, unit);
+ var observableLongGauge =
+ metricManager.observableLongGauge(registryName, metricName,
description, callback, unit);
+ closeables.add(observableLongGauge);
+ return observableLongGauge;
Review Comment:
Ah oh wow this overload made me tripped me up when writing this and I added
the closables in the wrong place! :(
Thank you @janhoy and @mkhludnev for fixing and finding this.
##########
solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java:
##########
@@ -160,65 +160,67 @@ public DoubleGauge doubleGauge(String metricName, String
description, OtelUnit u
public ObservableLongGauge observableLongGauge(
String metricName, String description,
Consumer<ObservableLongMeasurement> callback) {
- var observableLongGauge = observableLongGauge(metricName, description,
callback, null);
- closeables.add(observableLongGauge);
- return observableLongGauge;
+ return observableLongGauge(metricName, description, callback, null);
}
public ObservableLongGauge observableLongGauge(
String metricName,
String description,
Consumer<ObservableLongMeasurement> callback,
OtelUnit unit) {
- return metricManager.observableLongGauge(registryName, metricName,
description, callback, unit);
+ var observableLongGauge =
+ metricManager.observableLongGauge(registryName, metricName,
description, callback, unit);
+ closeables.add(observableLongGauge);
+ return observableLongGauge;
Review Comment:
I think we should better protect devs from this in the future or if new
observable instruments get created and the author forgets to do
`closeables.add` or places it in the wrong place (like I did).
What if these observable instruments here in `SolrMetricsContext` just
return `void` instead so the users of these instruments don't need to remember
to close them or figure out what to do with the object. Each of the observable
instrument goes through a `registerObservable` which takes care of adding to
closeable for the caller. Then make the observable instruments from
metricManager package-private so only SolrMetricsContext can use it. Wdyt?
This is a bigger scoped changed but I think it is worth it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]