Skip to content

Commit

Permalink
Chore/add pyroscope (#712)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Bulcke <[email protected]>
  • Loading branch information
rorlic and jobulcke authored Dec 5, 2024
1 parent 41eaf2f commit 6a1c2b2
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/ldio.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

FROM amazoncorretto:21-alpine-jdk

## Dependency for pyroscope
RUN apk --no-cache add libstdc++

RUN adduser -D -u 2000 ldio
USER ldio
WORKDIR /ldio

COPY ./ldi-orchestrator/ldio-application/target/ldio-application.jar ./
COPY ./ldi-orchestrator/ldio-instrumentation/target/ldio-instrumentation.jar ./lib/

COPY ./ldi-orchestrator/ldio-connectors/ldio-http-in/target/ldio-http-in-jar-with-dependencies.jar ./lib/
COPY ./ldi-orchestrator/ldio-connectors/ldio-http-in-poller/target/ldio-http-in-poller-jar-with-dependencies.jar ./lib/
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/1.a-build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
**/*with-dependencies.jar
**/*application.jar
**/ldes-discoverer.jar
**/ldio-instrumentation.jar
build-ldio-image:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
**/*with-dependencies.jar
**/*application.jar
**/ldes-discoverer.jar
**/ldio-instrumentation.jar
create-ldio-image:
Expand Down
40 changes: 40 additions & 0 deletions ldi-orchestrator/ldio-application-instrumentation/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ldi-orchestrator</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<version>2.9.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ldio-application-instrumentation</artifactId>

<dependencies>
<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>agent</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package be.vlaanderen.informatievlaanderen.ldes.ldio.instrumentation;

import io.pyroscope.javaagent.PyroscopeAgent;
import io.pyroscope.javaagent.config.Config;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PyroscopeInitialiser {

@Value("${pyroscope.agent.enabled:false}")
private boolean usePyroscope;
@PostConstruct
public void init() {
if(usePyroscope) {
PyroscopeAgent.start(
Config.build()
);
}
}
}
14 changes: 12 additions & 2 deletions ldi-orchestrator/ldio-application/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-orchestrator</artifactId>
Expand Down Expand Up @@ -47,6 +48,14 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldio-instrumentation</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down Expand Up @@ -237,7 +246,8 @@
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldio</groupId>
<artifactId>ldio-rml-adapter</artifactId>
<version>${project.version}</version>
</dependency></dependencies>
</dependency>
</dependencies>
</profile>
<profile>
<id>ldio-ngsiv2-to-ld-adapter</id>
Expand Down
55 changes: 55 additions & 0 deletions ldi-orchestrator/ldio-instrumentation/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ldi-orchestrator</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<version>2.11.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ldio-instrumentation</artifactId>

<dependencies>
<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>agent</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package be.vlaanderen.informatievlaanderen.ldes.ldio.instrumentation;

import io.pyroscope.javaagent.PyroscopeAgent;
import io.pyroscope.javaagent.config.Config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(value = "pyroscope.agent.enabled", havingValue = "true")
public class PyroscopeInitialiser {

@EventListener(ApplicationReadyEvent.class)
public void init() {
PyroscopeAgent.start(Config.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package be.vlaanderen.informatievlaanderen.ldes.ldio.instrumentation;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static org.assertj.core.api.Assertions.assertThat;

class PyroscopeInitialiserTest {
private ApplicationContextRunner runner;

@BeforeEach
void setUp() {
runner = new ApplicationContextRunner()
.withUserConfiguration(PyroscopeInitialiser.class);
}

@Test
void given_EnabledIsTrue_when_RunContext_then_BeanIsPresent() {
runner
.withPropertyValues("pyroscope.agent.enabled=true")
.run(context -> assertThat(context).hasSingleBean(PyroscopeInitialiser.class));
}

@Test
void given_EnabledIsFalse_when_RunContext_then_BeanIsAbsent() {
runner
.withPropertyValues("pyroscope.agent.enabled=false")
.run(context -> assertThat(context).doesNotHaveBean(PyroscopeInitialiser.class));
}

@Test
void given_MissingEnabledProperty_when_RunContext_then_BeanIsAbsent() {
runner.run(context -> assertThat(context).doesNotHaveBean(PyroscopeInitialiser.class));
}
}
10 changes: 10 additions & 0 deletions ldi-orchestrator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>ldio-common</module>
<module>ldio-application</module>
<module>ldio-connectors</module>
<module>ldio-instrumentation</module>
</modules>

<properties>
Expand All @@ -24,6 +25,7 @@
<cucumber.version>7.13.0</cucumber.version>
<junit-platform-suite.version>1.9.3</junit-platform-suite.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
<pyroscope.version>0.13.0</pyroscope.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -67,6 +69,14 @@
<artifactId>zipkin-reporter-brave</artifactId>
<version>${zipkin-reporter.version}</version>
</dependency>

<!-- INSTRUMENTATION -->
<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>agent</artifactId>
<version>${pyroscope.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 6a1c2b2

Please sign in to comment.