This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.compile.nullAnalysis.mode": "automatic" | ||
} |
37 changes: 37 additions & 0 deletions
37
labs/automatic-instrumentation/auto-instrumentation/initial/.gitignore
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,37 @@ | ||
HELP.md | ||
**target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
*.jar | ||
|
||
__pycache__ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
opentelemetry-javaagent.jar |
23 changes: 23 additions & 0 deletions
23
.../automatic-instrumentation/auto-instrumentation/initial/todobackend-springboot/Dockerfile
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,23 @@ | ||
FROM docker.io/maven:3-eclipse-temurin-21 as build | ||
WORKDIR /workspace/app | ||
|
||
COPY pom.xml . | ||
COPY src src | ||
|
||
RUN --mount=type=cache,target=/root/.m2 mvn install -DskipTests | ||
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar) | ||
|
||
FROM docker.io/eclipse-temurin:21-jdk-alpine | ||
RUN mkdir -p /opt/todobackend | ||
WORKDIR /opt/todobackend | ||
#RUN addgroup -S demo && adduser -S demo -G demo | ||
#USER demo | ||
VOLUME /tmp | ||
ARG DEPENDENCY=/workspace/app/target/dependency | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /opt/todobackend/app/lib | ||
COPY --from=build ${DEPENDENCY}/META-INF /opt/todobackend/app/META-INF | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app | ||
|
||
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /opt/todobackend | ||
|
||
ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] |
69 changes: 69 additions & 0 deletions
69
labs/automatic-instrumentation/auto-instrumentation/initial/todobackend-springboot/pom.xml
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,69 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.2.2</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<groupId>io.novatec</groupId> | ||
<artifactId>todobackend</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>todobackend</name> | ||
<description>Novatec Demo Application</description> | ||
|
||
<properties> | ||
<java.version>21</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
<version>2.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
139 changes: 139 additions & 0 deletions
139
...l/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.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,139 @@ | ||
package io.novatec.todobackend; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@SpringBootApplication | ||
@RestController | ||
@CrossOrigin(origins = "*") | ||
|
||
public class TodobackendApplication { | ||
|
||
private Logger logger = LoggerFactory.getLogger(TodobackendApplication.class); | ||
|
||
@Value("${HOSTNAME:not_set}") | ||
String hostname; | ||
|
||
@Value("${spring.profiles.active: none}") | ||
String profile; | ||
|
||
@Autowired | ||
TodoRepository todoRepository; | ||
|
||
private String getInstanceId() { | ||
|
||
if (!hostname.equals("not_set")) | ||
return hostname; | ||
return "probably localhost"; | ||
|
||
} | ||
|
||
@GetMapping("/hello") | ||
String hello() { | ||
|
||
return getInstanceId() + " Hallo, Welt ! "; | ||
|
||
} | ||
|
||
@GetMapping("/fail") | ||
String fail() { | ||
|
||
System.exit(1); | ||
return "fixed!"; | ||
} | ||
|
||
@GetMapping("/todos/") | ||
List<String> getTodos(){ | ||
|
||
List<String> todos = new ArrayList<String>(); | ||
|
||
todoRepository.findAll().forEach(todo -> todos.add(todo.getTodo())); | ||
logger.info("GET /todos/ "+todos.toString()); | ||
|
||
|
||
return todos; | ||
} | ||
|
||
@PostMapping("/todos/{todo}") | ||
String addTodo(@PathVariable String todo){ | ||
|
||
this.someInternalMethod(todo); | ||
//todoRepository.save(new Todo(todo)); | ||
logger.info("POST /todos/ "+todo.toString()); | ||
|
||
return todo; | ||
|
||
} | ||
|
||
String someInternalMethod(String todo){ | ||
|
||
todoRepository.save(new Todo(todo)); | ||
if(todo.equals("slow")){ | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
if(todo.equals("fail")){ | ||
|
||
System.out.println("Failing ..."); | ||
throw new RuntimeException(); | ||
|
||
} | ||
return todo; | ||
|
||
} | ||
|
||
@DeleteMapping("/todos/{todo}") | ||
String removeTodo(@PathVariable String todo) { | ||
|
||
todoRepository.deleteById(todo); | ||
logger.info("DELETE /todos/ "+todo.toString()); | ||
return "removed "+todo; | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TodobackendApplication.class, args); | ||
} | ||
} | ||
|
||
@Entity | ||
class Todo{ | ||
|
||
@Id | ||
String todo; | ||
|
||
public Todo(){} | ||
|
||
public Todo(String todo){ | ||
this.todo = todo; | ||
} | ||
|
||
public String getTodo(){ | ||
return todo; | ||
} | ||
|
||
public void setTodo(String todo) { | ||
this.todo = todo; | ||
} | ||
|
||
} | ||
|
||
interface TodoRepository extends CrudRepository<Todo, String> { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...trumentation/initial/todobackend-springboot/src/main/resources/application-dev.properties
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,5 @@ | ||
spring.h2.console.enabled=true | ||
spring.h2.console.path=/h2 | ||
spring.datasource.url=jdbc:h2:mem:testdb | ||
spring.datasource.username=sa | ||
spring.datasource.password= |
3 changes: 3 additions & 0 deletions
3
...rumentation/initial/todobackend-springboot/src/main/resources/application-prod.properties
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,3 @@ | ||
spring.datasource.url= jdbc:postgresql://${POSTGRES_HOST:postgresdb}:5432/mydb | ||
spring.datasource.username=matthias | ||
spring.datasource.password=password |
13 changes: 13 additions & 0 deletions
13
...-instrumentation/initial/todobackend-springboot/src/main/resources/application.properties
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,13 @@ | ||
server.port=8080 | ||
|
||
server.forward-headers-strategy=native | ||
management.endpoints.web.exposure.include=* | ||
|
||
spring.profiles.active=dev | ||
|
||
spring.jpa.hibernate.ddl-auto=update | ||
spring.jpa.show-sql=true | ||
#spring.jpa.properties.hibernate.format_sql=true | ||
|
||
spring.application.name=springboot-backend | ||
otel.exporter.otlp.endpoint=http://${COLLECTOR_HOST:localhost}:4317 |
12 changes: 12 additions & 0 deletions
12
...ringboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.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,12 @@ | ||
package io.novatec.todobackend; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
public class TodobackendApplicationIntegrationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
} |