sigram commented on a change in pull request #959: SOLR-13677 fix & cleanup
URL: https://github.com/apache/lucene-solr/pull/959#discussion_r335845830
##########
File path: solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java
##########
@@ -19,17 +19,72 @@
/**
* Used by objects that expose metrics through {@link SolrMetricManager}.
*/
-public interface SolrMetricProducer {
+public interface SolrMetricProducer extends AutoCloseable {
+
+ /**
+ * Unique metric tag identifies components with the same life-cycle, which
should
+ * be registered / unregistered together. It is in the format of A:B:C, where
+ * A is the parent of B is the parent of C and so on.
+ * If object "B" is unregistered C also must get unregistered.
+ * If object "A" is unregistered B and C also must get unregistered.
+ * @param o object to create a tag for
+ * @param parentName parent object name, or null if no parent
+ */
+ static String getUniqueMetricTag(Object o, String parentName) {
+ String name = o.getClass().getSimpleName() + "@" +
Integer.toHexString(o.hashCode());
+ if (parentName != null && parentName.contains(name)) {
+ throw new RuntimeException("Parent already includes this component?
parent=" + parentName + ", this=" + name);
+ }
+ return parentName == null ?
+ name :
+ parentName + ":" + name;
+ }
+
/**
* Initializes metrics specific to this producer
- * @param manager an instance of {@link SolrMetricManager}
+ *
+ * @param manager an instance of {@link SolrMetricManager}
* @param registry registry name where metrics are registered
- * @param tag a symbolic tag that represents this instance of the producer,
- * or a group of related instances that have the same life-cycle. This tag is
- * used when managing life-cycle of some metrics and is set when
- * {@link #initializeMetrics(SolrMetricManager, String, String, String)} is
called.
- * @param scope scope of the metrics (eg. handler name) to separate metrics
of
+ * @param tag a symbolic tag that represents this instance of the
producer,
+ * or a group of related instances that have the same
life-cycle. This tag is
+ * used when managing life-cycle of some metrics and is set
when
+ * {@link #initializeMetrics(SolrMetricManager, String,
String, String)} is called.
+ * @param scope scope of the metrics (eg. handler name) to separate
metrics of components with
+ * the same implementation but different scope
+ * @deprecated use {@link #initializeMetrics(SolrMetricsContext, String)}
instead
*/
- void initializeMetrics(SolrMetricManager manager, String registry, String
tag, String scope);
+ @Deprecated
+ default void initializeMetrics(SolrMetricManager manager, String registry,
String tag, String scope) {
+ initializeMetrics(new SolrMetricsContext(manager, registry, tag), scope);
+
+ }
+
+ /**
+ * Initialize metrics specific to this producer.
+ * @param context
+ * @param scope
+ */
+ default void initializeMetrics(SolrMetricsContext context, String scope) {
+ throw new RuntimeException("In class " + getClass().getName() +
+ " you must implement either initializeMetrics(SolrMetricsContext,
String) or " +
+ "initializeMetrics(SolrMetricManager, String, String, String)");
+
+ }
+
+ default SolrMetricsContext getSolrMetricsContext() {
+ return null;
+ }
+
+ @Override
+ default void close() throws Exception {
+ SolrMetricsContext context = getSolrMetricsContext();
+ if (context == null) {
+ return;
+ } else {
+ context.unregister();
+ }
+ // ??? (ab) no idea what this was supposed to avoid
Review comment:
Some insight into this, please - maybe I'm missing something.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]