From 38c796db7da4e3a86fe2c76dbb6c0c8627faa9d5 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 16 Dec 2023 22:11:33 +0000 Subject: [PATCH] Telemetry settings were not being picked up Fix: https://github.com/io7m/idstore/issues/98 --- .../configuration/v1/IdC1Telemetry.java | 33 +++++++++++++++++-- .../IdServerConfigurationServiceTest.java | 17 +++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/com.io7m.idstore.server.service.configuration/src/main/java/com/io7m/idstore/server/service/configuration/v1/IdC1Telemetry.java b/com.io7m.idstore.server.service.configuration/src/main/java/com/io7m/idstore/server/service/configuration/v1/IdC1Telemetry.java index 9ba86330..26d3107c 100644 --- a/com.io7m.idstore.server.service.configuration/src/main/java/com/io7m/idstore/server/service/configuration/v1/IdC1Telemetry.java +++ b/com.io7m.idstore.server.service.configuration/src/main/java/com/io7m/idstore/server/service/configuration/v1/IdC1Telemetry.java @@ -22,6 +22,9 @@ import com.io7m.blackthorne.core.BTElementParsingContextType; import com.io7m.blackthorne.core.BTQualifiedName; import com.io7m.idstore.server.api.IdServerOpenTelemetryConfiguration; +import com.io7m.idstore.server.api.IdServerOpenTelemetryConfiguration.IdLogs; +import com.io7m.idstore.server.api.IdServerOpenTelemetryConfiguration.IdMetrics; +import com.io7m.idstore.server.api.IdServerOpenTelemetryConfiguration.IdTraces; import org.xml.sax.Attributes; import java.util.Map; @@ -34,9 +37,9 @@ final class IdC1Telemetry implements BTElementHandlerType { private String serviceName; - private Optional logs; - private Optional metrics; - private Optional traces; + private Optional logs; + private Optional metrics; + private Optional traces; IdC1Telemetry( final BTElementParsingContextType context) @@ -55,6 +58,30 @@ public void onElementStart( attributes.getValue("LogicalServiceName"); } + @Override + public void onChildValueProduced( + final BTElementParsingContextType context, + final Object result) + throws Exception + { + switch (result) { + case final IdLogs l -> { + this.logs = Optional.of(l); + } + case final IdMetrics m -> { + this.metrics = Optional.of(m); + } + case final IdTraces t -> { + this.traces = Optional.of(t); + } + default -> { + throw new IllegalStateException( + "Unexpected value: %s".formatted(result) + ); + } + } + } + @Override public Map> onChildHandlersRequested( diff --git a/com.io7m.idstore.tests/src/main/java/com/io7m/idstore/tests/server/service/configuration/IdServerConfigurationServiceTest.java b/com.io7m.idstore.tests/src/main/java/com/io7m/idstore/tests/server/service/configuration/IdServerConfigurationServiceTest.java index b1bd5e7e..28671fe1 100644 --- a/com.io7m.idstore.tests/src/main/java/com/io7m/idstore/tests/server/service/configuration/IdServerConfigurationServiceTest.java +++ b/com.io7m.idstore.tests/src/main/java/com/io7m/idstore/tests/server/service/configuration/IdServerConfigurationServiceTest.java @@ -18,6 +18,7 @@ package com.io7m.idstore.tests.server.service.configuration; import com.io7m.anethum.slf4j.ParseStatusLogging; +import com.io7m.idstore.server.api.IdServerConfiguration; import com.io7m.idstore.server.api.IdServerConfigurationFile; import com.io7m.idstore.server.api.IdServerConfigurations; import com.io7m.idstore.server.service.configuration.IdServerConfigurationParsers; @@ -34,15 +35,14 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.time.Clock; import java.util.Locale; import static com.io7m.blackthorne.core.BTPreserveLexical.DISCARD_LEXICAL_INFORMATION; -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.WRITE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public final class IdServerConfigurationServiceTest extends IdServiceContract @@ -77,10 +77,15 @@ public void testConfig0() public void testConfig2() throws Exception { - this.roundTrip("server-config-2.xml"); + final var c = this.roundTrip("server-config-2.xml"); + + final var ot = c.openTelemetry().orElseThrow(); + assertTrue(ot.logs().isPresent()); + assertTrue(ot.metrics().isPresent()); + assertTrue(ot.traces().isPresent()); } - private void roundTrip( + private IdServerConfiguration roundTrip( final String name) throws Exception { @@ -136,6 +141,8 @@ private void roundTrip( assertEquals(parsed0.rateLimit(), parsed1.rateLimit()); assertEquals(parsed0.sessionConfiguration(), parsed1.sessionConfiguration()); assertEquals(parsed0, parsed1); + + return parsedConfig0; } @Override