janhoy commented on code in PR #5245:
URL: https://github.com/apache/solr/pull/5245#discussion_r4697314932


##########
solr/core/src/java/org/apache/solr/metrics/otel/MetricExporterFactory.java:
##########
@@ -17,24 +17,78 @@
 package org.apache.solr.metrics.otel;
 
 import io.opentelemetry.sdk.metrics.export.MetricExporter;
+import java.util.Locale;
 import org.apache.solr.common.util.EnvUtils;
 
+/**
+ * Configuration of Solr's OTLP metric exporter. Each setting is resolved from 
its Solr-specific
+ * property first, then from the equivalent standard OpenTelemetry environment 
variable (or {@code
+ * otel.*} system property), then from a default.
+ */
 public interface MetricExporterFactory {
 
-  Boolean OTLP_EXPORTER_ENABLED =
-      
Boolean.parseBoolean(EnvUtils.getProperty("solr.metrics.otlpExporterEnabled", 
"false"));
+  Boolean OTLP_EXPORTER_ENABLED = resolveEnabled();
 
-  String OTLP_EXPORTER_PROTOCOL = 
EnvUtils.getProperty("solr.metrics.otlpExporterProtocol", "http");
+  String OTLP_EXPORTER_PROTOCOL = resolveProtocol();
 
-  int OTLP_EXPORTER_INTERVAL =
-      
Integer.parseInt(EnvUtils.getProperty("solr.metrics.otlpExporterInterval", 
"60000"));
+  int OTLP_EXPORTER_INTERVAL = resolveInterval();
 
   String OTLP_EXPORTER_GRPC_ENDPOINT =
-      EnvUtils.getProperty("solr.metrics.otlpGrpcExporterEndpoint", 
"http://localhost:4317";);
+      resolveEndpoint("solr.metrics.otlpGrpcExporterEndpoint", false);
 
   String OTLP_EXPORTER_HTTP_ENDPOINT =
-      EnvUtils.getProperty(
-          "solr.metrics.otlpHttpExporterEndpoint", 
"http://localhost:4318/v1/metrics";);
+      resolveEndpoint("solr.metrics.otlpHttpExporterEndpoint", true);
 
   MetricExporter getExporter();
+
+  /**
+   * Also enabled by {@code OTEL_METRICS_EXPORTER} naming {@code otlp}, the 
only one Solr exports,
+   * but only while the Solr property is unset, so an explicit {@code false} 
still disables export.
+   */
+  private static boolean resolveEnabled() {
+    String solrEnabled = 
EnvUtils.getProperty("solr.metrics.otlpExporterEnabled");
+    if (solrEnabled != null) return Boolean.parseBoolean(solrEnabled);
+    String configured = otelConfig("OTEL_METRICS_EXPORTER");
+    return configured != null && configured.contains("otlp");
+  }
+
+  private static String resolveProtocol() {
+    String solrProtocol = 
EnvUtils.getProperty("solr.metrics.otlpExporterProtocol");
+    if (solrProtocol != null) return solrProtocol;
+    String otelProtocol = otelConfig("OTEL_EXPORTER_OTLP_METRICS_PROTOCOL");
+    if (otelProtocol == null) otelProtocol = 
otelConfig("OTEL_EXPORTER_OTLP_PROTOCOL");
+    if (otelProtocol == null) return "http";
+    // The OTEL spec spells the HTTP transports http/protobuf and http/json
+    return otelProtocol.startsWith("http") ? "http" : otelProtocol;
+  }
+
+  private static int resolveInterval() {
+    String solrInterval = 
EnvUtils.getProperty("solr.metrics.otlpExporterInterval");
+    if (solrInterval != null) return Integer.parseInt(solrInterval);
+    String otelInterval = otelConfig("OTEL_METRIC_EXPORT_INTERVAL");
+    return otelInterval != null ? Integer.parseInt(otelInterval) : 60000;

Review Comment:
   Fixed in dc0fd08bd7c. A blank `OTEL_*` value now counts as unset for every 
lookup, the interval also accepts the SDK's `ms`/`s`/`m`/`h`/`d` suffixes, and 
an invalid value warns and uses the default instead of failing startup.



-- 
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]

Reply via email to