Skip to content

Commit

Permalink
fix: jetzt auch mit Postgres und Traces für Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
trutzonline committed Apr 17, 2024
1 parent cf9675e commit 71917c2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
8 changes: 8 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
version: '3'
services:
postgres:
image: postgres:16
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
prometheus:
image: prom/prometheus
command:
Expand Down
22 changes: 16 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand All @@ -36,7 +52,6 @@
<artifactId>micrometer-tracing-bridge-otel</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
Expand All @@ -50,11 +65,6 @@
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/trutzio/devopstools/EchoController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package trutzio.devopstools;

import java.util.UUID;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import io.opentelemetry.instrumentation.annotations.WithSpan;

@RestController
public class EchoController {

private final PersonRepository personRepository;

public EchoController(PersonRepository personRepository) {
this.personRepository = personRepository;
}

@GetMapping("/")
@WithSpan(value = "test span")
// @WithSpan(value = "test span")
public String echo() throws InterruptedException {
for (int i = 0; i < 10; i++) {
Person person = new Person();
person.id = UUID.randomUUID().toString();
person.name = "John Doe " + i;
personRepository.save(person);
}
return "OK";
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/trutzio/devopstools/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package trutzio.devopstools;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
public class Person {

@Id
String id;
String name;

}
7 changes: 7 additions & 0 deletions src/main/java/trutzio/devopstools/PersonRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package trutzio.devopstools;

import org.springframework.data.jpa.repository.JpaRepository;

public interface PersonRepository extends JpaRepository<Person, String> {

}
8 changes: 8 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
spring:
application:
name: devops-tools
datasource:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: postgres
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: update
management:
tracing:
enabled: true
Expand Down

0 comments on commit 71917c2

Please sign in to comment.