phet commented on code in PR #3933:
URL: https://github.com/apache/gobblin/pull/3933#discussion_r1578431518


##########
gobblin-api/src/main/java/org/apache/gobblin/configuration/ConfigurationKeys.java:
##########
@@ -913,9 +913,8 @@ public class ConfigurationKeys {
 
   public static final String METRICS_REPORTING_OPENTELEMETRY_ENDPOINT = 
METRICS_REPORTING_OPENTELEMETRY_PREFIX + "endpoint";
 
-  public static final String METRICS_REPORTING_OPENTELEMETRY_HEADER_KEY = 
METRICS_REPORTING_OPENTELEMETRY_PREFIX + "header.key";
-
-  public static final String METRICS_REPORTING_OPENTELEMETRY_HEADER_VALUE = 
METRICS_REPORTING_OPENTELEMETRY_PREFIX + "header.value";
+  // Headers to add to the OpenTelemetry HTTP Exporter, formatted as a JSON 
String

Review Comment:
   specifically is it supposed to be a JSON dictionary of string, to string?



##########
gobblin-metrics-libs/gobblin-metrics/src/test/java/org/apache/gobblin/metrics/OpenTelemetryMetricsTest.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.metrics;
+
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.configuration.State;
+
+
+public class OpenTelemetryMetricsTest  {
+
+  @Test
+  void testInitializeOpenTelemetryFailsWithoutEndpoint() {
+    State opentelemetryState = new State();
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENABLED,
 "true");
+    Assert.assertThrows(IllegalArgumentException.class, () -> {
+      OpenTelemetryMetrics.getInstance(opentelemetryState);
+    });
+  }
+
+  @Test
+  void testInitializeOpenTelemetrySucceedsWithEndpoint() {
+    State opentelemetryState = new State();
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENABLED,
 "true");
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENDPOINT,
 "http://localhost:4317";);
+    OpenTelemetryMetrics metricsProvider = 
OpenTelemetryMetrics.getInstance(opentelemetryState);
+    System.out.println(metricsProvider.metricExporter.toString());

Review Comment:
   shouldn't we assert, not merely print?



##########
gobblin-metrics-libs/gobblin-metrics/src/test/java/org/apache/gobblin/metrics/OpenTelemetryMetricsTest.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.metrics;
+
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.configuration.State;
+
+
+public class OpenTelemetryMetricsTest  {
+
+  @Test
+  void testInitializeOpenTelemetryFailsWithoutEndpoint() {
+    State opentelemetryState = new State();
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENABLED,
 "true");
+    Assert.assertThrows(IllegalArgumentException.class, () -> {
+      OpenTelemetryMetrics.getInstance(opentelemetryState);
+    });
+  }
+
+  @Test
+  void testInitializeOpenTelemetrySucceedsWithEndpoint() {
+    State opentelemetryState = new State();
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENABLED,
 "true");
+    
opentelemetryState.setProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENDPOINT,
 "http://localhost:4317";);
+    OpenTelemetryMetrics metricsProvider = 
OpenTelemetryMetrics.getInstance(opentelemetryState);
+    System.out.println(metricsProvider.metricExporter.toString());
+  }
+
+  @Test
+  void testHeadersParseCorrectly() {
+    Map<String, String> headers = OpenTelemetryMetrics.parseHttpHeaders(
+        
"{\"Content-Type\":\"application/x-protobuf\",\"headerTag\":\"tag1:value1,tag2:value2\"}");
+    Assert.assertEquals(headers.size(), 2);
+    Assert.assertEquals(headers.get("Content-Type"), "application/x-protobuf");
+    Assert.assertEquals(headers.get("headerTag"), "tag1:value1,tag2:value2");

Review Comment:
   `org.hamcrest.Matchers.containsInAnyOrder`?



##########
gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java:
##########
@@ -98,4 +104,14 @@ protected void initialize(State state) {
 
     this.openTelemetry = 
OpenTelemetrySdk.builder().setMeterProvider(meterProvider).buildAndRegisterGlobal();
   }
+
+  static Map<String, String> parseHttpHeaders(String headersString) {
+    try {
+      ObjectMapper mapper = new ObjectMapper();
+      return mapper.readValue(headersString, HashMap.class);
+    } catch (Exception e) {
+      log.error("Failed to parse headers: " + headersString, e);
+      throw new RuntimeException(e);

Review Comment:
   error message should also be added to the `RuntimeException`



##########
gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java:
##########
@@ -60,9 +63,12 @@ protected MetricExporter initializeMetricExporter(State 
state) {
         "OpenTelemetry endpoint must be provided");
     OtlpHttpMetricExporterBuilder httpExporterBuilder = 
OtlpHttpMetricExporter.builder();
     
httpExporterBuilder.setEndpoint(state.getProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENDPOINT));
-    if 
(state.contains(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADER_KEY) 
&& 
state.contains(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADER_VALUE)) 
{
-      
httpExporterBuilder.addHeader(state.getProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADER_KEY),
-          
state.getProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADER_VALUE));
+
+    if 
(state.contains(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADERS)) {
+      Map<String, String> headers = 
parseHttpHeaders(state.getProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_HEADERS));

Review Comment:
   looks like this might pass in `null`, no?
   
   e.g.:
   ```
   Optional.ofNullable(state.getProp(...)).ifPresent(headersMap ->
     headersMap.entrySet().forEach(header ->
       heb.addHeader(...)
     ));
   ```



##########
gobblin-metrics-libs/gobblin-metrics/src/test/java/org/apache/gobblin/metrics/OpenTelemetryMetricsTest.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.metrics;
+
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.configuration.State;
+
+
+public class OpenTelemetryMetricsTest  {
+
+  @Test
+  void testInitializeOpenTelemetryFailsWithoutEndpoint() {

Review Comment:
   `public`?



##########
gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java:
##########
@@ -98,4 +104,14 @@ protected void initialize(State state) {
 
     this.openTelemetry = 
OpenTelemetrySdk.builder().setMeterProvider(meterProvider).buildAndRegisterGlobal();
   }
+
+  static Map<String, String> parseHttpHeaders(String headersString) {

Review Comment:
   package protected?



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

Reply via email to