Skip to content

Commit

Permalink
Telemetry settings were not being picked up
Browse files Browse the repository at this point in the history
Fix: #98
  • Loading branch information
io7m committed Dec 16, 2023
1 parent 75c72a7 commit 38c796d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,9 +37,9 @@ final class IdC1Telemetry
implements BTElementHandlerType<Object, IdServerOpenTelemetryConfiguration>
{
private String serviceName;
private Optional<IdServerOpenTelemetryConfiguration.IdLogs> logs;
private Optional<IdServerOpenTelemetryConfiguration.IdMetrics> metrics;
private Optional<IdServerOpenTelemetryConfiguration.IdTraces> traces;
private Optional<IdLogs> logs;
private Optional<IdMetrics> metrics;
private Optional<IdTraces> traces;

IdC1Telemetry(
final BTElementParsingContextType context)
Expand All @@ -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<BTQualifiedName, BTElementHandlerConstructorType<?, ?>>
onChildHandlersRequested(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IdServerConfigurationService>
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -136,6 +141,8 @@ private void roundTrip(
assertEquals(parsed0.rateLimit(), parsed1.rateLimit());
assertEquals(parsed0.sessionConfiguration(), parsed1.sessionConfiguration());
assertEquals(parsed0, parsed1);

return parsedConfig0;
}

@Override
Expand Down

0 comments on commit 38c796d

Please sign in to comment.