Skip to content

Commit

Permalink
Merge pull request #295 from buerokratt/spring-boot-3
Browse files Browse the repository at this point in the history
Update Ruuter to SpringBoot3
  • Loading branch information
RayDNoper authored May 10, 2024
2 parents d3f7939 + 56ecd12 commit cd1c4a6
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:17-jdk-alpine as build
FROM eclipse-temurin:21-jdk-alpine as build
WORKDIR /workspace/app

COPY gradlew .
Expand All @@ -12,7 +12,7 @@ RUN chmod 754 ./gradlew
RUN ./gradlew -Pprod clean bootJar
RUN mkdir -p build/libs && (cd build/libs; jar -xf *.jar)

FROM eclipse-temurin:17-jdk-alpine
FROM eclipse-temurin:21-jdk-alpine
VOLUME /build/tmp

ARG DEPENDENCY=/workspace/app/build/libs
Expand Down
18 changes: 15 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import org.springframework.boot.loader.tools.LoaderImplementation

plugins {
id 'org.springframework.boot' version '2.7.0'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'java'
id "org.sonarqube" version "3.5.0.2730"
}

bootJar {
loaderImplementation = LoaderImplementation.CLASSIC
}

group = 'ee.buerokratt'
version = '0.0.1-SNAPSHOT'

Expand All @@ -27,7 +33,13 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.1.10'

implementation platform('io.opentelemetry:opentelemetry-bom:1.15.0')
implementation 'io.opentelemetry:opentelemetry-api'
implementation 'io.opentelemetry:opentelemetry-sdk'
implementation 'io.opentelemetry:opentelemetry-context'
implementation 'io.opentelemetry:opentelemetry-exporter-logging'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation 'org.graalvm.js:js:23.0.1'
implementation 'org.graalvm.js:js-scriptengine:23.0.1'
Expand All @@ -45,7 +57,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core:5.6.0'
testImplementation 'org.mockito:mockito-inline:4.9.0'
testImplementation 'org.mockito:mockito-junit-jupiter:5.6.0'
testImplementation "com.github.tomakehurst:wiremock-jre8:2.35.0"
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.1'
}

tasks.named('test') {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ee.buerokratt.ruuter.configuration;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenTelemetryConfig {

@Bean
public OpenTelemetry openTelemetry() {
// Configure the SDK (feel free to replace the exporter with one that suits your needs)
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(new LoggingSpanExporter()).build())
.build();

return OpenTelemetrySdk.builder()
.setTracerProvider(tracerProvider)
.buildAndRegisterGlobal();
}

@Bean
public Tracer tracer() {
// This assumes that a default OpenTelemetry has been configured elsewhere
return OpenTelemetry.noop().getTracer("ee.buerokratt.ruuter");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import ee.buerokratt.ruuter.domain.DslInstance;
import ee.buerokratt.ruuter.domain.RuuterResponse;
import ee.buerokratt.ruuter.service.DslService;
import ee.buerokratt.ruuter.service.exception.StepExecutionException;
import ee.buerokratt.ruuter.util.LoggingUtils;
import io.swagger.v3.core.util.Json;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -17,13 +15,11 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;

import java.util.HashMap;
import java.util.Map;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import ee.buerokratt.ruuter.service.OpenSearchSender;
import ee.buerokratt.ruuter.service.exception.StepExecutionException;
import ee.buerokratt.ruuter.util.LoggingUtils;
import io.opentelemetry.api.trace.Tracer;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.sleuth.Tracer;

import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@Slf4j
@Data
Expand Down Expand Up @@ -59,7 +59,6 @@ public void execute() {
recursions = stepNames.stream().collect(Collectors.toMap(Function.identity(), a -> 0));
try {
executeStep(stepNames.get(0), stepNames);

} catch (Exception e) {
LoggingUtils.logError(log, "Error executing DSL: %s".formatted(name), requestOrigin, "", e);
clearReturnValues();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/ee/buerokratt/ruuter/domain/steps/DslStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import io.opentelemetry.api.trace.Span;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;

Expand All @@ -30,10 +29,10 @@ public abstract class DslStep {
private boolean reloadDsl = false;

public final void execute(DslInstance di) throws StepExecutionException {
Span newSpan = di.getTracer().nextSpan().name(name);
Span newSpan = di.getTracer().spanBuilder(name).startSpan();
long startTime = System.currentTimeMillis();

try (Tracer.SpanInScope ws = di.getTracer().withSpan(newSpan.start())) {
try {
if (sleep != null) {
Thread.sleep(sleep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void executeStepAction(DslInstance di) {
setNextStepName(getOnErrorStep());
}
else {
di.setErrorStatus(response.getStatusCode());
di.setErrorStatus(HttpStatus.valueOf(response.getStatusCodeValue()));
di.setErrorMessage("HTTP returned with non-OK");
throw new IllegalArgumentException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ee/buerokratt/ruuter/service/DslService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.core.util.Yaml;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.sleuth.Tracer;
import io.opentelemetry.api.trace.Tracer;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ application:
# index: ruuterlog
httpResponseSizeLimit: 256

management:
endpoints:
web:
exposure:
include=prometheus:
tracing:
enabled:
true

spring:
application:
name: ruuter
Expand Down

0 comments on commit cd1c4a6

Please sign in to comment.