SameerDevgon commented on code in PR #27966:
URL: https://github.com/apache/flink/pull/27966#discussion_r3268219699
##########
flink-metrics/flink-metrics-otel/src/test/java/org/apache/flink/metrics/otel/OpenTelemetryEventReporterTest.java:
##########
@@ -166,4 +168,79 @@ public void testReportLogRecord() throws Exception {
});
});
}
+
+ @Test
+ public void testServiceNameAndVersionAppliedToResource() {
+ InspectableEventReporter inspectable = new InspectableEventReporter();
+ MetricConfig config = new MetricConfig();
+ config.setProperty(
+ OpenTelemetryReporterOptions.EXPORTER_ENDPOINT.key(),
"http://localhost:4317");
+ config.setProperty(OpenTelemetryReporterOptions.SERVICE_NAME.key(),
"my-flink-job");
+ config.setProperty(OpenTelemetryReporterOptions.SERVICE_VERSION.key(),
"1.2.3");
+ inspectable.open(config);
+ inspectable.close();
+
+ Resource resource = inspectable.getResource();
+ assertThat(resource.getAttribute(ResourceAttributes.SERVICE_NAME))
+ .as(" service.name must be set from config; was null
-super.open() not called")
+ .isEqualTo("my-flink-job");
+ assertThat(resource.getAttribute(ResourceAttributes.SERVICE_VERSION))
+ .as(" service.version must be set from config; was null
-super.open() not called")
+ .isEqualTo("1.2.3");
+ }
+
+ @Test
+ public void testServiceNameAppearsInExportedResourceAttributes() throws
Exception {
+ MetricConfig config = createMetricConfig();
+
+ config.setProperty(
+ OpenTelemetryReporterOptions.SERVICE_NAME.key(),
"exported-service-name");
+
+ reporter.open(config);
+ try {
+ reporter.notifyOfAddedEvent(
+ Event.builder(this.getClass(),
"service-name-verification-event")
+ .setObservedTsMillis(1L)
+ .build());
+ } finally {
+ reporter.close();
+ }
+
+ eventuallyConsumeJson(
+ (json) -> {
+ JsonNode resourceAttributes =
+ json.findPath("resourceLogs")
+ .findPath("resource")
+ .findPath("attributes");
+
+ assertThat(resourceAttributes.isArray())
+ .as("resource attributes should be a JSON array")
+ .isTrue();
+
+ boolean found = false;
+
+ for (JsonNode attr : resourceAttributes) {
+ if
("service.name".equals(attr.findPath("key").asText())) {
+ assertThat(attr.at("/value/stringValue").asText())
+ .as("service.name attribute value")
+ .isEqualTo("exported-service-name");
+ found = true;
+ break;
+ }
+ }
+
+ assertThat(found)
+ .as(
+ "service.name was absent from exported
resource attributes - "
+ + "super.open() was not called in
OpenTelemetryEventReporter.open()")
+ .isTrue();
+ });
+ }
+
+ private static class InspectableEventReporter extends
OpenTelemetryEventReporter {
Review Comment:
yeah i agree good to have it in `@BeforeEach` , i'll make the change
--
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]