-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clean up ldi inputs ctors (#590)
- Loading branch information
Showing
22 changed files
with
303 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldio/types/LdioObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package be.vlaanderen.informatievlaanderen.ldes.ldio.types; | ||
|
||
import be.vlaanderen.informatievlaanderen.ldes.ldio.config.ObserveConfiguration; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
|
||
import static be.vlaanderen.informatievlaanderen.ldes.ldio.config.PipelineConfig.PIPELINE_NAME; | ||
|
||
public class LdioObserver { | ||
private static final String LDIO_DATA_IN = "ldio_data_in"; | ||
private static final String LDIO_COMPONENT_NAME = "ldio_type"; | ||
private static final Logger log = LoggerFactory.getLogger(LdioObserver.class); | ||
private final String componentName; | ||
private final String pipelineName; | ||
private final ObservationRegistry observationRegistry; | ||
|
||
private LdioObserver(String componentName, String pipelineName, ObservationRegistry observationRegistry) { | ||
this.componentName = componentName; | ||
this.pipelineName = pipelineName; | ||
this.observationRegistry = observationRegistry; | ||
} | ||
|
||
@SafeVarargs | ||
public final void observe(Runnable observable, String location, Supplier<String>... additionalLoggingContent) { | ||
final String errorLocation = pipelineName + ":" + location; | ||
Observation.createNotStarted(this.componentName, observationRegistry) | ||
.observe(() -> { | ||
try { | ||
observable.run(); | ||
} catch (Exception e) { | ||
log.atError().log(ObserveConfiguration.ERROR_TEMPLATE, errorLocation, e.getMessage()); | ||
Arrays.stream(additionalLoggingContent) | ||
.forEach(content -> | ||
log.atError().log(ObserveConfiguration.ERROR_TEMPLATE, errorLocation, content.get()) | ||
); | ||
throw e; | ||
} | ||
}); | ||
} | ||
|
||
public void increment() { | ||
Metrics.counter(LDIO_DATA_IN, PIPELINE_NAME, pipelineName, LDIO_COMPONENT_NAME, componentName).increment(); | ||
} | ||
|
||
public static LdioObserver register(String componentName, String pipelineName, ObservationRegistry observationRegistry) { | ||
Metrics.counter(LDIO_DATA_IN, PIPELINE_NAME, pipelineName, LDIO_COMPONENT_NAME, componentName).increment(0); | ||
return new LdioObserver(componentName, pipelineName, observationRegistry); | ||
} | ||
|
||
public String getPipelineName() { | ||
return pipelineName; | ||
} | ||
|
||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...on/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldio/types/LdioObserverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package be.vlaanderen.informatievlaanderen.ldes.ldio.types; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.*; | ||
|
||
class LdioObserverTest { | ||
private static final String COMPONENT_NAME = "Ldio:ComponentName"; | ||
private static final String PIPELINE_NAME = "pipeline-name"; | ||
private LdioObserver ldioObserver; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
ldioObserver = LdioObserver.register(COMPONENT_NAME, PIPELINE_NAME, null); | ||
} | ||
|
||
@Test | ||
void when_ObservableDoesNotThrowException_then_DoNotLog() { | ||
final Supplier<String> additionalLogSupplier = mock(); | ||
final Runnable observable = () -> {}; | ||
|
||
ldioObserver.observe(observable, "test", additionalLogSupplier); | ||
|
||
verifyNoInteractions(additionalLogSupplier); | ||
} | ||
|
||
@Test | ||
void when_ObservableDoesThrowsException_then_Log() { | ||
final Supplier<String> additionalLogSupplier = mock(); | ||
final Runnable observable = () -> { | ||
throw new RuntimeException(); | ||
}; | ||
|
||
assertThatThrownBy(() -> ldioObserver.observe(observable, "test", additionalLogSupplier)) | ||
.isInstanceOf(RuntimeException.class); | ||
|
||
verify(additionalLogSupplier).get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../java/be/vlaanderen/informatievlaanderen/ldes/ldio/valueobjects/LdioAmpqInProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects; | ||
|
||
import be.vlaanderen.informatievlaanderen.ldes.ldio.config.JmsConfig; | ||
|
||
public record LdioAmpqInProperties(String pipelineName, String defaultContentType, JmsConfig jmsConfig) { | ||
} |
Oops, something went wrong.