From 52d9b62caa0732d493d55e59518522f07b3294d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Tue, 5 Nov 2024 15:06:30 +0100 Subject: [PATCH] removed java excercises --- .../initial/.gitignore | 37 ---- .../initial/todobackend-springboot/Dockerfile | 23 -- .../initial/todobackend-springboot/pom.xml | 89 -------- .../todobackend/TodobackendApplication.java | 149 ------------- .../main/resources/application-dev.properties | 5 - .../resources/application-prod.properties | 3 - .../src/main/resources/application.properties | 13 -- ...odobackendApplicationIntegrationTests.java | 12 -- .../initial/todoui-thymeleaf/Dockerfile | 26 --- .../initial/todoui-thymeleaf/pom.xml | 105 --------- .../todoui/OpenTelemetryConfiguration.java | 60 ------ .../io/novatec/todoui/TodouiApplication.java | 145 ------------- .../src/main/resources/application.properties | 17 -- .../src/main/resources/templates/items.html | 88 -------- .../solution/.gitignore | 37 ---- .../todobackend-springboot/Dockerfile | 23 -- .../solution/todobackend-springboot/pom.xml | 123 ----------- .../OpenTelemetryConfiguration.java | 66 ------ .../todobackend/TodobackendApplication.java | 200 ------------------ .../main/resources/application-dev.properties | 5 - .../resources/application-prod.properties | 3 - .../src/main/resources/application.properties | 13 -- ...odobackendApplicationIntegrationTests.java | 12 -- exercises/manual-instrumentation-java/steps | 156 -------------- 24 files changed, 1410 deletions(-) delete mode 100644 exercises/manual-instrumentation-java/initial/.gitignore delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-dev.properties delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-prod.properties delete mode 100644 exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application.properties delete mode 100755 exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/application.properties delete mode 100644 exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/templates/items.html delete mode 100644 exercises/manual-instrumentation-java/solution/.gitignore delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-dev.properties delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-prod.properties delete mode 100644 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application.properties delete mode 100755 exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java delete mode 100644 exercises/manual-instrumentation-java/steps diff --git a/exercises/manual-instrumentation-java/initial/.gitignore b/exercises/manual-instrumentation-java/initial/.gitignore deleted file mode 100644 index 227a53b..0000000 --- a/exercises/manual-instrumentation-java/initial/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -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 diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile deleted file mode 100644 index 5893092..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -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/download/v2.8.0/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"] \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml deleted file mode 100644 index fb87a78..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 3.2.2 - - - - io.novatec - todobackend-manual - 0.0.1-SNAPSHOT - todobackend-manual - Demo Application - - - 21 - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - com.h2database - h2 - runtime - - - org.postgresql - postgresql - runtime - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.2.0 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.mockito - mockito-core - - - net.bytebuddy - byte-buddy - - - net.bytebuddy - byte-buddy-agent - - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - todobackend-${version} - - - \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java deleted file mode 100644 index fd3bd5a..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ /dev/null @@ -1,149 +0,0 @@ -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.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -@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 getTodos() { - - List todos = new ArrayList(); - - todoRepository.findAll().forEach(todo -> todos.add(todo.getTodo())); - logger.info("GET /todos/ " + todos.toString()); - - return todos; - } - - @PostMapping("/todos/{todo}") - String addTodo(HttpServletRequest request, HttpServletResponse response, @PathVariable String todo){ - - logger.info("POST /todos/ "+todo.toString()); - - this.someInternalMethod(todo); - - 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 { - -} \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-dev.properties b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-dev.properties deleted file mode 100644 index 25d7606..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-dev.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.h2.console.enabled=true -spring.h2.console.path=/h2 -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.username=sa -spring.datasource.password= \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-prod.properties b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-prod.properties deleted file mode 100644 index 6806431..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application-prod.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.datasource.url= jdbc:postgresql://${POSTGRES_HOST:postgresdb}:5432/mydb -spring.datasource.username=matthias -spring.datasource.password=password \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application.properties b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application.properties deleted file mode 100644 index eaa2173..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java deleted file mode 100755 index b18589d..0000000 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.novatec.todobackend; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -public class TodobackendApplicationIntegrationTests { - - @Test - void contextLoads() { - } -} \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile deleted file mode 100644 index be98665..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -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 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/todoui -WORKDIR /opt/todoui -# 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/todoui/app/lib -COPY --from=build ${DEPENDENCY}/META-INF /opt/todoui/app/META-INF -COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todoui/app - -ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todoui - -ENTRYPOINT ["java","-cp","/opt/todoui/app:/opt/todoui/app/lib/*", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "io.novatec.todoui.TodouiApplication"] -#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] - diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml deleted file mode 100644 index 3887156..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - 4.0.0 - - io.novatec - todoui-manual - 0.0.1-SNAPSHOT - jar - - todoui-manual - Demo project for Spring Boot - - - org.springframework.boot - spring-boot-starter-parent - 2.7.16 - - - - - UTF-8 - UTF-8 - 17 - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.mockito - mockito-core - - - net.bytebuddy - byte-buddy - - - net.bytebuddy - byte-buddy-agent - - - - - io.opentelemetry - opentelemetry-api - - - io.opentelemetry - opentelemetry-sdk - - - io.opentelemetry - opentelemetry-exporter-logging - - - io.opentelemetry - opentelemetry-exporter-otlp - - - - io.opentelemetry.semconv - opentelemetry-semconv - 1.26.0-alpha - - - - - - - io.opentelemetry - opentelemetry-bom - 1.40.0 - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java deleted file mode 100644 index 460262c..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.novatec.todoui; - -import java.util.concurrent.TimeUnit; - -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; - -//Basic Otel API & SDK -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.semconv.ResourceAttributes; - -//Tracing and Spans -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; - -import io.opentelemetry.exporter.logging.LoggingSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; - -import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.propagation.ContextPropagators; - - -@SuppressWarnings("deprecation") -@Configuration -public class OpenTelemetryConfiguration { - - @Bean - @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) - public OpenTelemetry openTelemetry(){ - - Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME, "tododui").put(ResourceAttributes.SERVICE_VERSION, "0.1.0").build(); - - OtlpGrpcSpanExporter jaegerOtlpExporter = - OtlpGrpcSpanExporter.builder() - .setEndpoint("http://localhost:4317") - .setTimeout(30, TimeUnit.SECONDS) - .build(); - - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) - .addSpanProcessor(SimpleSpanProcessor.create(jaegerOtlpExporter)) - // .addSpanProcessor(BatchSpanProcessor.builder(LoggingSpanExporter.create()).build()) // same results for now - .setResource(resource) - .build(); - // .buildAndRegisterGlobal(); - - - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) - .build(); - - return openTelemetry; - } - -} diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java deleted file mode 100644 index 4ea1206..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java +++ /dev/null @@ -1,145 +0,0 @@ -package io.novatec.todoui; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.client.RestTemplate; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.Context; - -@SpringBootApplication -@Controller -public class TodouiApplication { - - private Logger logger = LoggerFactory.getLogger(TodouiApplication.class); - - private OpenTelemetry openTelemetry; - private Tracer tracer; - - @Value("${backend.url}") - String endpoint; - RestTemplate template = new RestTemplate(); - - public TodouiApplication(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; - tracer = this.openTelemetry.getTracer(TodouiApplication.class.getName(), "0.1.0"); - } - - @PostConstruct - public void postConstruct(){ - - logger.info(" UI initialized for backend at "+endpoint); - } - - @GetMapping("/stress") - public String stress(){ - - logger.info(java.time.LocalDateTime.now() + " : Starting stress"); - double result = 0; - for (int i = 0; i < 100000000; i++) { - result += System.currentTimeMillis(); - } - logger.info(java.time.LocalDateTime.now() + " : Ending stress, result: " + result); - return "redirect:/"; - - } - - public static List list = new ArrayList<>(); // can never be GC'ed - @GetMapping("/leak") - public String leak(){ - - logger.info(java.time.LocalDateTime.now() + " : Start leaking"); - for (int i = 0; i < 10000000; i++) { - list.add(Math.random()); - } - logger.info(java.time.LocalDateTime.now() + " : End leaking"); - return "redirect:/"; - - } - - @GetMapping("/createcookie") - public String createCookie(HttpServletResponse response) { - - Cookie cookie = new Cookie("featureflag", "on"); - cookie.setPath("/"); - response.addCookie(cookie); - return "redirect:/"; - - } - - @GetMapping("/deletecookie") - public String deleteCookie(HttpServletResponse response) { - - Cookie cookie = new Cookie("featureflag", null); - cookie.setMaxAge(0); - cookie.setPath("/"); - response.addCookie(cookie); - return "redirect:/"; - - } - - - @GetMapping - public String getItems(Model model){ - - logger.info("GET "+ endpoint + "/todos/"); - ResponseEntity response = template.getForEntity(endpoint+"/todos/", String[].class); - if(response != null) model.addAttribute("items", response.getBody()); - return "items"; - - } - - @PostMapping - public String addItem(String toDo){ - - logger.info("POST "+ endpoint + "/todos/"+toDo); - - Span span = tracer.spanBuilder("addItem").setSpanKind(SpanKind.CLIENT).startSpan(); - - Context context = Context.current(); - - System.out.println("Context: "+context); - System.out.println("### Hallo"); - - template.postForEntity(endpoint+"/todos/"+toDo, null, String.class); - - - - span.end(); - - return "redirect:/"; - - } - - @PostMapping("{toDo}") - public String setItemDone(@PathVariable String toDo){ - - logger.info("POST "+ endpoint + "/todos/"+toDo); - template.delete(endpoint+"/todos/"+toDo); - return "redirect:/"; - - } - - public static void main(String[] args) { - SpringApplication.run(TodouiApplication.class, args); - } -} diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/application.properties b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/application.properties deleted file mode 100644 index dad2d1b..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/application.properties +++ /dev/null @@ -1,17 +0,0 @@ -#server port -server.port=8090 - -#todobackend config -backend.host=${BACKEND_HOST:todobackend} -backend.port=${BACKEND_PORT:8080} -backend.url=http://${backend.host}:${backend.port} - -#actuator -management.endpoints.web.exposure.include=* - -#error handling -#server.error.include-exception=true -server.error.include-message=always -#server.error.include-stacktrace=always - - diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/templates/items.html b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/templates/items.html deleted file mode 100644 index 38668aa..0000000 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/resources/templates/items.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - Most beautiful of all Java Todo Lists - - - - - -
- -
-

Most beautiful of all Java Todo Lists

-
- -

Add a ToDo

- -
- - - - - - - - - - - -
ItemAction
- - - - -
-
- -
- -

ToDo List

- -
- - - - - - - - - -
ItemAction
- -
- -
-
-
- -
- - - - - - - - - -
ItemAction
You have no ToDos :-)None
-
-
- - - - - diff --git a/exercises/manual-instrumentation-java/solution/.gitignore b/exercises/manual-instrumentation-java/solution/.gitignore deleted file mode 100644 index 227a53b..0000000 --- a/exercises/manual-instrumentation-java/solution/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -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 diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile deleted file mode 100644 index 5893092..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -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/download/v2.8.0/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"] \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml deleted file mode 100644 index f966fe8..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 3.2.2 - - - - io.novatec - todobackend-manual-solution - 0.0.1-SNAPSHOT - todobackend-manual-solution - Demo Application - - - 21 - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - com.h2database - h2 - runtime - - - org.postgresql - postgresql - runtime - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.2.0 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.mockito - mockito-core - - - net.bytebuddy - byte-buddy - - - net.bytebuddy - byte-buddy-agent - - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - io.opentelemetry - opentelemetry-api - - - io.opentelemetry - opentelemetry-sdk - - - io.opentelemetry - opentelemetry-exporter-logging - - - io.opentelemetry - opentelemetry-exporter-otlp - - - io.opentelemetry.semconv - opentelemetry-semconv - 1.26.0-alpha - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - todobackend-${version} - - - - - - io.opentelemetry - opentelemetry-bom - 1.40.0 - pom - import - - - - - \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java deleted file mode 100644 index e4026e9..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.novatec.todobackend; - -import java.time.Duration; - -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; - -//Basic Otel API & SDK -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.exporter.logging.LoggingMetricExporter; -import io.opentelemetry.exporter.logging.LoggingSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; -import io.opentelemetry.sdk.resources.Resource; -//Tracing and Spans -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; -import io.opentelemetry.semconv.ResourceAttributes; - -@SuppressWarnings("deprecation") -@Configuration -public class OpenTelemetryConfiguration { - - @Bean - @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) - public OpenTelemetry openTelemetry() { - - Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME, "todobackend") - .put(ResourceAttributes.SERVICE_VERSION, "0.1.0").build(); - - OtlpGrpcSpanExporter jaegerOtlpExporter = OtlpGrpcSpanExporter.builder() - .setEndpoint("http://localhost:4317") - .build(); - - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) - .addSpanProcessor(SimpleSpanProcessor.create(jaegerOtlpExporter)) - .setResource(resource) - .build(); - - SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder() - .registerMetricReader( - PeriodicMetricReader - .builder(LoggingMetricExporter.create()) - .setInterval(Duration.ofSeconds(10)) - .build()) - .setResource(resource) - .build(); - - - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) - .setMeterProvider(sdkMeterProvider) - .build(); - - return openTelemetry; - } - -} diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java deleted file mode 100644 index c51907d..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ /dev/null @@ -1,200 +0,0 @@ -package io.novatec.todobackend; - -import static io.opentelemetry.api.common.AttributeKey.stringKey; - -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.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.metrics.LongCounter; -import io.opentelemetry.api.metrics.Meter; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.Scope; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -@SpringBootApplication -@RestController -@CrossOrigin(origins = "*") - -public class TodobackendApplication { - - private Logger logger = LoggerFactory.getLogger(TodobackendApplication.class); - - private OpenTelemetry openTelemetry; - private Tracer tracer; - private Meter meter; - private LongCounter counter; - - @Value("${HOSTNAME:not_set}") - String hostname; - - @Value("${spring.profiles.active: none}") - String profile; - - @Autowired - TodoRepository todoRepository; - - public TodobackendApplication(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; - tracer = this.openTelemetry.getTracer(TodobackendApplication.class.getName(), "0.1.0"); - meter = this.openTelemetry.getMeter(TodobackendApplication.class.getName()); - - counter = meter.counterBuilder("todobackend.requests.counter") - .setDescription("How many times the GET call has been invoked.") - .setUnit("requests") - .build(); - - } - - 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 getTodos() { - - List todos = new ArrayList(); - - todoRepository.findAll().forEach(todo -> todos.add(todo.getTodo())); - logger.info("GET /todos/ " + todos.toString()); - counter.add(1,Attributes.of(stringKey("http.method"), "GET")); - - return todos; - } - - @PostMapping("/todos/{todo}") - String addTodo(HttpServletRequest request, HttpServletResponse response, @PathVariable String todo) { - - logger.info("POST /todos/ " + todo.toString()); - - Span span = tracer.spanBuilder("addTodo").setSpanKind(SpanKind.SERVER).startSpan(); - - span.setAttribute("http.method", request.getMethod()); - span.setAttribute("http.url", request.getRequestURL().toString()); - span.setAttribute("client.address", request.getRemoteAddr()); - span.setAttribute("user.agent", request.getHeader("User-Agent")); - - try (Scope scope = span.makeCurrent()) { - this.someInternalMethod(todo); - response.setStatus(HttpServletResponse.SC_CREATED); - span.setAttribute("response.status", HttpServletResponse.SC_CREATED); - } catch (Throwable t) { - span.setStatus(StatusCode.ERROR, "Error on server side!"); - span.recordException(t); - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - span.setAttribute("response.status", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } finally { - span.end(); - } - - logger.info("Span.toString():" + span.toString()); - return todo; - - } - - String someInternalMethod(String todo) { - - Span childSpan = tracer.spanBuilder("someInternalMethod").setSpanKind(SpanKind.INTERNAL).startSpan(); - - 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(); - - } - - logger.info("childSpan.toString():" + childSpan.toString()); - childSpan.end(); - 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 { - -} \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-dev.properties b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-dev.properties deleted file mode 100644 index 25d7606..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-dev.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.h2.console.enabled=true -spring.h2.console.path=/h2 -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.username=sa -spring.datasource.password= \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-prod.properties b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-prod.properties deleted file mode 100644 index 6806431..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application-prod.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.datasource.url= jdbc:postgresql://${POSTGRES_HOST:postgresdb}:5432/mydb -spring.datasource.username=matthias -spring.datasource.password=password \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application.properties b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application.properties deleted file mode 100644 index eaa2173..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java deleted file mode 100755 index b18589d..0000000 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.novatec.todobackend; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -public class TodobackendApplicationIntegrationTests { - - @Test - void contextLoads() { - } -} \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/steps b/exercises/manual-instrumentation-java/steps deleted file mode 100644 index 05f164a..0000000 --- a/exercises/manual-instrumentation-java/steps +++ /dev/null @@ -1,156 +0,0 @@ -pom.xml - -under project - - - - - io.opentelemetry - opentelemetry-bom - 1.40.0 - pom - import - - - - -under dependencies - - - io.opentelemetry - opentelemetry-api - - -mvn clean package - works - -More packages - - - io.opentelemetry - opentelemetry-sdk - - - io.opentelemetry - opentelemetry-exporter-logging - - - - io.opentelemetry.semconv - opentelemetry-semconv - 1.26.0-alpha - - - -In Java app: - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.Attributes; - -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; - -import io.opentelemetry.semconv.ResourceAttributes; - - @Bean - public OpenTelemetry openTelemetry(){ - - Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME, "todobackend").put(ResourceAttributes.SERVICE_VERSION, "0.1.0").build(); - - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .buildAndRegisterGlobal(); - - return openTelemetry; - } - - -For Tracing: - -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; - -import io.opentelemetry.exporter.logging.LoggingSpanExporter; - -import io.opentelemetry.api.trace.Tracer; - - @Bean - public OpenTelemetry openTelemetry(){ - - Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME, "todobackend").put(ResourceAttributes.SERVICE_VERSION, "0.1.0").build(); - - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) - .setResource(resource) - .build(); - - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .buildAndRegisterGlobal(); - - return openTelemetry; - } - -Acquiring a tracer: - -Creating spans: - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.context.Scope; - - -Frontend: - -export BACKEND_URL=http://localhost:8080 -export BACKEND_URL=http://localhost:8080 - - -Put everything in own Config class: - -package io.novatec.todobackend; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -//Basic Otel -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.exporter.logging.LoggingSpanExporter; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; -//Tracing and Spans -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; -import io.opentelemetry.semconv.ResourceAttributes; - - -@SuppressWarnings("deprecation") -@Configuration -public class OpenTelemetryConfiguration { - - @Bean - public OpenTelemetry openTelemetry(){ - - Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME, "todobackend").put(ResourceAttributes.SERVICE_VERSION, "0.1.0").build(); - - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) - .setResource(resource) - .build(); - - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .buildAndRegisterGlobal(); - - return openTelemetry; - } - -} - - -Tracer: - - TodobackendApplication(OpenTelemetry openTelemetry) { - tracer = openTelemetry.getTracer(TodobackendApplication.class.getName(), "0.1.0"); - } - - -Spans: -