From 7834c0733e18033dc87f79484c5c97a20103bf12 Mon Sep 17 00:00:00 2001 From: Eduard Schander <66794307+EddeCCC@users.noreply.github.com> Date: Wed, 21 Jun 2023 11:23:15 +0200 Subject: [PATCH] Spring 3 and Java 17 migration (#41) * update versions * replace javax with jakarta * replace SocketUtils with TestSocketUtils * refactor SecurityConfig without WebSecurityConfigurerAdapter * update comments in gradle.properties * update workflow java version * adjust GzipCompressionMethodIntTest * change download location for OpenTelemetryPlugin --- .github/workflows/eumserver_test.yml | 2 +- build.gradle | 7 ++- gradle.properties | 23 +++----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ClientHeaderBeaconProcessor.java | 2 +- .../ResourceTimingBeaconRecorder.java | 2 +- .../model/BeanConfiguration.java | 7 +++ .../model/EumServerConfiguration.java | 6 +- .../model/ResourceTimingSettings.java | 4 +- .../model/exporters/ExportersSettings.java | 2 +- .../beacon/BeaconExporterSettings.java | 2 +- .../beacon/BeaconHttpExporterSettings.java | 8 +-- .../metrics/InfluxExporterSettings.java | 4 +- .../metrics/MetricsExportersSettings.java | 2 +- .../metrics/OtlpMetricsExporterSettings.java | 1 - .../metrics/PrometheusExporterSettings.java | 6 +- .../trace/TraceExportersSettings.java | 2 +- .../BeaconMetricDefinitionSettings.java | 10 ++-- .../metric/definition/BeaconRequirement.java | 4 +- .../definition/MetricDefinitionSettings.java | 6 +- .../definition/ViewDefinitionSettings.java | 2 +- .../model/security/SecuritySettings.java | 4 +- .../AuthenticationProviderSettings.java | 2 +- ...piTokenAuthenticationProviderSettings.java | 2 +- .../SelfMonitoringSettings.java | 6 +- .../model/tags/BeaconTagSettings.java | 4 +- .../model/tags/TagsSettings.java | 8 +-- .../tags/providers/TagsProvidersSettings.java | 2 +- .../exporters/InfluxExporterService.java | 4 +- .../exporters/OtlpMetricsExporterService.java | 7 +-- .../exporters/PrometheusExporterService.java | 4 +- .../exporters/beacon/BeaconHttpExporter.java | 4 +- .../exporters/beacon/ExportWorkerFactory.java | 2 +- .../TraceExportersConfiguration.java | 2 +- .../metrics/SelfMonitoringMetricManager.java | 2 +- .../percentiles/TimeWindowViewManager.java | 4 +- .../oce/eum/server/rest/BeaconController.java | 4 +- .../oce/eum/server/rest/TraceController.java | 2 +- .../eum/server/security/ApiTokenFilter.java | 4 +- .../eum/server/security/SecurityConfig.java | 58 ++++++++++--------- .../SimpleApiTokenAuthenticationProvider.java | 4 +- .../OpenTelemetryProtoConverter.java | 5 +- .../eum/server/utils/GeolocationResolver.java | 4 +- .../oce/eum/server/utils/IPUtils.java | 2 +- .../oce/eum/server/utils/RequestUtils.java | 2 +- .../ExporterIntTestBaseWithOtelCollector.java | 19 ++++-- .../GzipCompressionMethodIntTest.java | 5 +- .../PrometheusExporterServiceIntTest.java | 4 +- .../SelfMonitoringMetricManagerTest.java | 2 +- .../OpenTelemetryProtoConverterTest.java | 2 +- 50 files changed, 144 insertions(+), 134 deletions(-) diff --git a/.github/workflows/eumserver_test.yml b/.github/workflows/eumserver_test.yml index b9edc7e..de9fb48 100644 --- a/.github/workflows/eumserver_test.yml +++ b/.github/workflows/eumserver_test.yml @@ -15,7 +15,7 @@ jobs: test: name: Run Tests runs-on: ubuntu-latest - container: openjdk:8-jdk + container: openjdk:17-jdk-slim steps: - uses: actions/checkout@v3 - name: Grant execute permission for gradlew diff --git a/build.gradle b/build.gradle index 5c19e9a..44b6cf6 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,8 @@ apply plugin: "java" apply plugin: "jacoco" group = "rocks.inspectit.ocelot" -sourceCompatibility = "1.8" +sourceCompatibility = "17" +targetCompatibility = "17" if (!project.hasProperty("buildVersion") || project.getProperty("buildVersion").empty) { ext.buildVersion = "SNAPSHOT" @@ -55,7 +56,7 @@ tasks.register('generateVersionFile') { } tasks.register('downloadOpenTelemetryPlugin') { - ext.dest = new File(buildDir, "boomerang-opentelemetry.js") + ext.dest = new File(buildDir, "boomerangjs-${boomerangVersion}/package/plugins/boomerang-opentelemetry.js") outputs.files(ext.dest) doLast { def f = ext.dest @@ -158,7 +159,7 @@ dependencies { testImplementation( "org.springframework.boot:spring-boot-starter-test", "io.opencensus:opencensus-impl:${openCensusVersion}", - "org.apache.httpcomponents:httpclient", + "org.apache.httpcomponents:httpclient:4.5.14", "org.mockito:mockito-core", "org.junit.jupiter:junit-jupiter-api", "org.awaitility:awaitility", diff --git a/gradle.properties b/gradle.properties index c792463..8c6fc91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,27 +2,21 @@ boomerangVersion=1.737.0 # The open-telemetry-boomerang version to ship with the EUM server boomerangOpenTelemetryPluginVersion=0.25.0-6 -# 2.7 is the latest release line which runs on Java 8 -springBootVersion=2.7.11 -# We do not really use snakeyaml directly. We overwrite the version of -# spring due to a security report -# For 1.33 CVE-2022-1471 is still identified. Since EUM-Server -# does not read yaml from untrusted sources, it is not affected. -# We cannot use 2.0 because EUM-Server actually parses a YAML file via Jackson. -# Jackson uses SnakeYaml and cannot deal with version 2.0 -snakeYamlVersion=1.33 +# Upgrade to Spring 3.* and Java 17 +springBootVersion=3.1.0 +# CVE-2022-1471 was resolved with SnakeYAML 2.0 +snakeYamlVersion=2.0 # Ensure to adapt the netty version (inspectit-ocelot-core/build.gradle) when changing the OpenCensus version openCensusVersion=0.31.1 # pin Prometheus client to 0.6.0 to prevent auto prefixing counter metrics with "_total" # see: https://github.com/prometheus/client_java/issues/640, https://github.com/prometheus/client_java/pull/653 prometheusClientVersion = 0.6.0 -openTelemetryVersion=1.25.0 -openTelemetryAlphaVersion=1.25.0-alpha +openTelemetryVersion=1.27.0 +openTelemetryAlphaVersion=1.27.0-alpha openTelemetryProtoVersion=1.7.1-alpha protobufVersion=3.22.3 guavaVersion=31.1-jre -# there are newer version, but they are not compatible with Java 8 -geoip2Version=2.16.1 +geoip2Version=4.0.1 commonsNetVersion=3.9.0 commonsMath3Version=3.6.1 commonsIoVersion=2.11.0 @@ -40,5 +34,4 @@ owaspDependencyCheckVersion=8.2.1 # org.cyclonedx.bom cyclonedxBomVersion=1.7.4 # com.palantir.docker -# There is a newer Version 0.35.0, but it is not Java 8 compatible -palantirDockerVersion=0.34.0 +palantirDockerVersion=0.35.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69a9715..070cb70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/ClientHeaderBeaconProcessor.java b/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/ClientHeaderBeaconProcessor.java index cb8d93c..16b624a 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/ClientHeaderBeaconProcessor.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/ClientHeaderBeaconProcessor.java @@ -6,7 +6,7 @@ import rocks.inspectit.oce.eum.server.beacon.Beacon; import rocks.inspectit.oce.eum.server.utils.RequestUtils; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import java.util.Collections; import java.util.Map; import java.util.function.Supplier; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/beacon/recorder/ResourceTimingBeaconRecorder.java b/src/main/java/rocks/inspectit/oce/eum/server/beacon/recorder/ResourceTimingBeaconRecorder.java index 1bda500..16baf9c 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/beacon/recorder/ResourceTimingBeaconRecorder.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/beacon/recorder/ResourceTimingBeaconRecorder.java @@ -21,7 +21,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.metric.definition.ViewDefinitionSettings; import rocks.inspectit.oce.eum.server.metrics.MeasuresAndViewsManager; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.io.IOException; import java.util.*; import java.util.function.Function; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/BeanConfiguration.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/BeanConfiguration.java index 37587c9..1c7db7e 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/BeanConfiguration.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/BeanConfiguration.java @@ -6,6 +6,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.ConversionService; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import rocks.inspectit.oce.eum.server.configuration.conversion.InspectitConfigConversionService; import java.util.concurrent.Executors; @@ -45,4 +47,9 @@ public ScheduledExecutorService scheduledExecutor() { public ConversionService getConversionService() { return InspectitConfigConversionService.getInstance(); } + + @Bean + public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { + return config.getAuthenticationManager(); + } } diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/EumServerConfiguration.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/EumServerConfiguration.java index ae0f093..5136dab 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/EumServerConfiguration.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/EumServerConfiguration.java @@ -10,9 +10,9 @@ import rocks.inspectit.oce.eum.server.configuration.model.selfmonitoring.SelfMonitoringSettings; import rocks.inspectit.oce.eum.server.configuration.model.tags.TagsSettings; -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.util.Collections; import java.util.Map; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/ResourceTimingSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/ResourceTimingSettings.java index 6d8ed42..0e88520 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/ResourceTimingSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/ResourceTimingSettings.java @@ -3,8 +3,8 @@ import lombok.Data; import org.springframework.validation.annotation.Validated; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.util.Map; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/ExportersSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/ExportersSettings.java index ea2ee9d..fae9555 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/ExportersSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/ExportersSettings.java @@ -6,7 +6,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.exporters.metrics.MetricsExportersSettings; import rocks.inspectit.oce.eum.server.configuration.model.exporters.trace.TraceExportersSettings; -import javax.validation.Valid; +import jakarta.validation.Valid; /** * Extended exporter settings. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconExporterSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconExporterSettings.java index d194afd..ba423d9 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconExporterSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconExporterSettings.java @@ -3,7 +3,7 @@ import lombok.Data; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; /** * Beacon exporter settings. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconHttpExporterSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconHttpExporterSettings.java index 0744be4..d2993fe 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconHttpExporterSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/beacon/BeaconHttpExporterSettings.java @@ -4,10 +4,10 @@ import org.springframework.validation.annotation.Validated; import rocks.inspectit.oce.eum.server.configuration.model.exporters.ExporterEnabledState; -import javax.validation.constraints.AssertTrue; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.time.Duration; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/InfluxExporterSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/InfluxExporterSettings.java index 6e6a017..5a89926 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/InfluxExporterSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/InfluxExporterSettings.java @@ -4,8 +4,8 @@ import org.hibernate.validator.constraints.time.DurationMin; import rocks.inspectit.oce.eum.server.configuration.model.exporters.ExporterEnabledState; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; import java.time.Duration; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/MetricsExportersSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/MetricsExportersSettings.java index 0e60518..f8b9597 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/MetricsExportersSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/MetricsExportersSettings.java @@ -3,7 +3,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.Valid; +import jakarta.validation.Valid; /** * Settings for metrics exporters. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/OtlpMetricsExporterSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/OtlpMetricsExporterSettings.java index 1b4b436..b01f548 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/OtlpMetricsExporterSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/OtlpMetricsExporterSettings.java @@ -8,7 +8,6 @@ import rocks.inspectit.oce.eum.server.configuration.model.exporters.ExporterEnabledState; import rocks.inspectit.oce.eum.server.configuration.model.exporters.TransportProtocol; -import javax.annotation.PostConstruct; import java.time.Duration; import java.util.Map; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/PrometheusExporterSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/PrometheusExporterSettings.java index 8f696e6..1f95958 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/PrometheusExporterSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/metrics/PrometheusExporterSettings.java @@ -4,9 +4,9 @@ import lombok.NoArgsConstructor; import rocks.inspectit.oce.eum.server.configuration.model.exporters.ExporterEnabledState; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; /** * Settings for the OpenCensus Prometheus metrics exporter. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/trace/TraceExportersSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/trace/TraceExportersSettings.java index 1a65b1a..211a5aa 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/trace/TraceExportersSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/exporters/trace/TraceExportersSettings.java @@ -3,7 +3,7 @@ import lombok.Data; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; @Data @Validated diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconMetricDefinitionSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconMetricDefinitionSettings.java index 6b6d208..6728a81 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconMetricDefinitionSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconMetricDefinitionSettings.java @@ -4,11 +4,11 @@ import rocks.inspectit.oce.eum.server.arithmetic.RawExpression; import rocks.inspectit.oce.eum.server.beacon.Beacon; -import javax.validation.Valid; -import javax.validation.constraints.AssertTrue; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import java.util.List; import java.util.Map; import java.util.function.Function; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconRequirement.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconRequirement.java index 06234f8..98a5f60 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconRequirement.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/BeaconRequirement.java @@ -7,8 +7,8 @@ import rocks.inspectit.oce.eum.server.beacon.Beacon; import rocks.inspectit.oce.eum.server.configuration.model.exporters.beacon.InitiatorType; -import javax.validation.constraints.AssertTrue; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.NotNull; import java.util.Collection; import java.util.List; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/MetricDefinitionSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/MetricDefinitionSettings.java index 3be6c64..631742a 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/MetricDefinitionSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/MetricDefinitionSettings.java @@ -3,9 +3,9 @@ import lombok.*; import org.springframework.util.CollectionUtils; -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.time.Duration; import java.util.Map; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/ViewDefinitionSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/ViewDefinitionSettings.java index 55e6536..5bd9bb5 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/ViewDefinitionSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/metric/definition/ViewDefinitionSettings.java @@ -4,7 +4,7 @@ import org.hibernate.validator.constraints.time.DurationMin; import org.springframework.util.CollectionUtils; -import javax.validation.constraints.*; +import jakarta.validation.constraints.*; import java.time.Duration; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/SecuritySettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/SecuritySettings.java index 0ab6623..617b003 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/SecuritySettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/SecuritySettings.java @@ -4,8 +4,8 @@ import org.springframework.validation.annotation.Validated; import rocks.inspectit.oce.eum.server.configuration.model.security.authProvider.AuthenticationProviderSettings; -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; import java.util.List; @Data diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/AuthenticationProviderSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/AuthenticationProviderSettings.java index de8fa75..2b85a31 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/AuthenticationProviderSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/AuthenticationProviderSettings.java @@ -3,7 +3,7 @@ import lombok.Data; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; @Data @Validated diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/SimpleApiTokenAuthenticationProviderSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/SimpleApiTokenAuthenticationProviderSettings.java index 4e52f01..9db2ee7 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/SimpleApiTokenAuthenticationProviderSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/security/authProvider/SimpleApiTokenAuthenticationProviderSettings.java @@ -5,7 +5,7 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; -import javax.validation.constraints.AssertTrue; +import jakarta.validation.constraints.AssertTrue; import java.time.Duration; @Data diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/selfmonitoring/SelfMonitoringSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/selfmonitoring/SelfMonitoringSettings.java index 935c339..2b915e6 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/selfmonitoring/SelfMonitoringSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/selfmonitoring/SelfMonitoringSettings.java @@ -5,9 +5,9 @@ import org.springframework.validation.annotation.Validated; import rocks.inspectit.oce.eum.server.configuration.model.metric.definition.MetricDefinitionSettings; -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.util.Collections; import java.util.Map; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/BeaconTagSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/BeaconTagSettings.java index 989f030..5640b50 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/BeaconTagSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/BeaconTagSettings.java @@ -5,8 +5,8 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/TagsSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/TagsSettings.java index 4dc565a..4268d00 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/TagsSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/TagsSettings.java @@ -5,10 +5,10 @@ import rocks.inspectit.oce.eum.server.configuration.model.tags.providers.TagsProvidersSettings; import rocks.inspectit.oce.eum.server.utils.IPUtils; -import javax.validation.Valid; -import javax.validation.constraints.AssertFalse; -import javax.validation.constraints.AssertTrue; -import javax.validation.constraints.Pattern; +import jakarta.validation.Valid; +import jakarta.validation.constraints.AssertFalse; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Pattern; import java.util.*; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/providers/TagsProvidersSettings.java b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/providers/TagsProvidersSettings.java index 2198e4e..3b55546 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/providers/TagsProvidersSettings.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/configuration/model/tags/providers/TagsProvidersSettings.java @@ -3,7 +3,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.Valid; +import jakarta.validation.Valid; @Data @NoArgsConstructor diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/InfluxExporterService.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/InfluxExporterService.java index 3f2a587..82187d9 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/InfluxExporterService.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/InfluxExporterService.java @@ -10,8 +10,8 @@ import rocks.inspectit.oce.eum.server.metrics.percentiles.TimeWindowViewManager; import rocks.inspectit.opencensus.influx.InfluxExporter; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/OtlpMetricsExporterService.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/OtlpMetricsExporterService.java index 3126ac7..8c7ffd4 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/OtlpMetricsExporterService.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/OtlpMetricsExporterService.java @@ -31,14 +31,13 @@ import rocks.inspectit.oce.eum.server.configuration.model.exporters.TransportProtocol; import rocks.inspectit.oce.eum.server.configuration.model.exporters.metrics.OtlpMetricsExporterSettings; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.validation.Valid; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.validation.Valid; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/PrometheusExporterService.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/PrometheusExporterService.java index 51a01ba..09aa3c6 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/PrometheusExporterService.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/PrometheusExporterService.java @@ -10,8 +10,8 @@ import org.springframework.stereotype.Component; import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; /** * Service for the Prometheus OpenCensus exporters. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/BeaconHttpExporter.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/BeaconHttpExporter.java index 45b33da..2394e9a 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/BeaconHttpExporter.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/BeaconHttpExporter.java @@ -9,8 +9,8 @@ import rocks.inspectit.oce.eum.server.configuration.model.exporters.beacon.BeaconHttpExporterSettings; import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.util.concurrent.*; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/ExportWorkerFactory.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/ExportWorkerFactory.java index b7f10d8..c4d8884 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/ExportWorkerFactory.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/beacon/ExportWorkerFactory.java @@ -18,7 +18,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; import rocks.inspectit.oce.eum.server.metrics.SelfMonitoringMetricManager; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.net.URI; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/exporters/configuration/TraceExportersConfiguration.java b/src/main/java/rocks/inspectit/oce/eum/server/exporters/configuration/TraceExportersConfiguration.java index f957fa1..28ff260 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/exporters/configuration/TraceExportersConfiguration.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/exporters/configuration/TraceExportersConfiguration.java @@ -22,7 +22,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.exporters.trace.TraceExportersSettings; import rocks.inspectit.oce.eum.server.configuration.model.exporters.trace.JaegerExporterSettings; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.util.Map; import java.util.Optional; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/metrics/SelfMonitoringMetricManager.java b/src/main/java/rocks/inspectit/oce/eum/server/metrics/SelfMonitoringMetricManager.java index 39bbbea..d6b7e26 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/metrics/SelfMonitoringMetricManager.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/metrics/SelfMonitoringMetricManager.java @@ -9,7 +9,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.selfmonitoring.SelfMonitoringSettings; import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.util.Collections; import java.util.Map; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/metrics/percentiles/TimeWindowViewManager.java b/src/main/java/rocks/inspectit/oce/eum/server/metrics/percentiles/TimeWindowViewManager.java index a2150f1..83de5c6 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/metrics/percentiles/TimeWindowViewManager.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/metrics/percentiles/TimeWindowViewManager.java @@ -10,8 +10,8 @@ import io.opencensus.tags.Tags; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.time.Duration; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/rest/BeaconController.java b/src/main/java/rocks/inspectit/oce/eum/server/rest/BeaconController.java index ad4eb38..26fe0a8 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/rest/BeaconController.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/rest/BeaconController.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; @@ -31,9 +32,10 @@ public class BeaconController { private BeaconHttpExporter beaconHttpExporter; @ExceptionHandler({Exception.class}) - public void handleException(Exception exception) { + public ResponseEntity handleException(Exception exception) { selfMonitoringService.record("beacons_received", 1, Collections.singletonMap("is_error", "true")); log.error("Error while receiving beacon", exception); + return new ResponseEntity<>("There was an error", HttpStatus.BAD_REQUEST); } @CrossOrigin diff --git a/src/main/java/rocks/inspectit/oce/eum/server/rest/TraceController.java b/src/main/java/rocks/inspectit/oce/eum/server/rest/TraceController.java index c5b67fc..0b65168 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/rest/TraceController.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/rest/TraceController.java @@ -19,7 +19,7 @@ import rocks.inspectit.oce.eum.server.metrics.SelfMonitoringMetricManager; import rocks.inspectit.oce.eum.server.tracing.opentelemtry.OpenTelemetryProtoConverter; -import javax.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotBlank; import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/security/ApiTokenFilter.java b/src/main/java/rocks/inspectit/oce/eum/server/security/ApiTokenFilter.java index 7e0aa9b..f7e197e 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/security/ApiTokenFilter.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/security/ApiTokenFilter.java @@ -5,8 +5,8 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; /** diff --git a/src/main/java/rocks/inspectit/oce/eum/server/security/SecurityConfig.java b/src/main/java/rocks/inspectit/oce/eum/server/security/SecurityConfig.java index a9afaf3..e80a082 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/security/SecurityConfig.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/security/SecurityConfig.java @@ -2,12 +2,15 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; import rocks.inspectit.oce.eum.server.configuration.model.security.SecuritySettings; @@ -17,11 +20,12 @@ @Slf4j @Configuration -public class SecurityConfig extends WebSecurityConfigurerAdapter { +public class SecurityConfig { + @Autowired + private AuthenticationManager authenticationManager; @Autowired private EumServerConfiguration configuration; - @Autowired(required = false) private List apiTokenAuthProviders = Collections.emptyList(); @@ -30,7 +34,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { * * @param auth the {@link AuthenticationManagerBuilder} to use */ - @Override + @Autowired protected void configure(AuthenticationManagerBuilder auth) { if (configuration.getSecurity().isEnabled()) { apiTokenAuthProviders.forEach(auth::authenticationProvider); @@ -38,38 +42,36 @@ protected void configure(AuthenticationManagerBuilder auth) { } /** - * Configures {@link HttpSecurity} if security is enabeld by + * Configures {@link HttpSecurity} if security is enabled by * * * @param http the {@link HttpSecurity} to modify - * * @throws Exception In case of any error */ - @Override - protected void configure(HttpSecurity http) throws Exception { - http.cors().and().csrf().disable(); + @Bean + protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.cors(AbstractHttpConfigurer::disable).csrf(AbstractHttpConfigurer::disable); if (configuration.getSecurity().isEnabled()) { - http.authorizeRequests() - .antMatchers(configuration.getSecurity().getPermittedUrls().toArray(new String[]{})) - .permitAll() - .anyRequest() - .authenticated() - .and() - .addFilterAt(new ApiTokenFilter(authenticationManagerBean(), configuration.getSecurity() - .getAuthorizationHeader()), BasicAuthenticationFilter.class); - - } else { - http.authorizeRequests().anyRequest().permitAll(); + http.authorizeHttpRequests( + authz -> authz + .requestMatchers(configuration.getSecurity().getPermittedUrls().toArray(new String[]{})) + .permitAll() + .anyRequest() + .authenticated() + ).addFilterAt( + new ApiTokenFilter(authenticationManager, configuration.getSecurity().getAuthorizationHeader()), + BasicAuthenticationFilter.class + ); } + else { + http.authorizeHttpRequests( + authz -> authz.anyRequest().permitAll() + ).httpBasic(Customizer.withDefaults()); + } + return http.build(); } - - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - -} +} \ No newline at end of file diff --git a/src/main/java/rocks/inspectit/oce/eum/server/security/authprovider/SimpleApiTokenAuthenticationProvider.java b/src/main/java/rocks/inspectit/oce/eum/server/security/authprovider/SimpleApiTokenAuthenticationProvider.java index a880ee6..8385dab 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/security/authprovider/SimpleApiTokenAuthenticationProvider.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/security/authprovider/SimpleApiTokenAuthenticationProvider.java @@ -21,8 +21,8 @@ import rocks.inspectit.oce.eum.server.security.ApiTokenAuthentication; import rocks.inspectit.oce.eum.server.utils.DirectoryPoller; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/tracing/opentelemtry/OpenTelemetryProtoConverter.java b/src/main/java/rocks/inspectit/oce/eum/server/tracing/opentelemtry/OpenTelemetryProtoConverter.java index 784cc8c..7029f91 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/tracing/opentelemtry/OpenTelemetryProtoConverter.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/tracing/opentelemtry/OpenTelemetryProtoConverter.java @@ -7,10 +7,7 @@ import io.opentelemetry.proto.common.v1.InstrumentationLibrary; import io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans; import io.opentelemetry.proto.trace.v1.ResourceSpans; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.common.InstrumentationScopeInfoBuilder; -import io.opentelemetry.sdk.internal.InstrumentationScopeUtil; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.OcelotSpanUtils; import io.opentelemetry.sdk.trace.data.SpanData; @@ -20,7 +17,7 @@ import rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration; import rocks.inspectit.oce.eum.server.utils.RequestUtils; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import java.util.*; import java.util.function.Supplier; import java.util.stream.Stream; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/utils/GeolocationResolver.java b/src/main/java/rocks/inspectit/oce/eum/server/utils/GeolocationResolver.java index 90a2089..5f5f962 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/utils/GeolocationResolver.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/utils/GeolocationResolver.java @@ -6,8 +6,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; diff --git a/src/main/java/rocks/inspectit/oce/eum/server/utils/IPUtils.java b/src/main/java/rocks/inspectit/oce/eum/server/utils/IPUtils.java index 56edbc2..9286cc5 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/utils/IPUtils.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/utils/IPUtils.java @@ -4,7 +4,7 @@ import org.springframework.security.web.util.matcher.IpAddressMatcher; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; /** * Util to extract the origin IP from the given request. diff --git a/src/main/java/rocks/inspectit/oce/eum/server/utils/RequestUtils.java b/src/main/java/rocks/inspectit/oce/eum/server/utils/RequestUtils.java index 6242325..561a7bb 100644 --- a/src/main/java/rocks/inspectit/oce/eum/server/utils/RequestUtils.java +++ b/src/main/java/rocks/inspectit/oce/eum/server/utils/RequestUtils.java @@ -5,7 +5,7 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class RequestUtils { diff --git a/src/test/java/rocks/inspectit/oce/eum/server/exporters/ExporterIntTestBaseWithOtelCollector.java b/src/test/java/rocks/inspectit/oce/eum/server/exporters/ExporterIntTestBaseWithOtelCollector.java index 23212b6..8f7e1d0 100644 --- a/src/test/java/rocks/inspectit/oce/eum/server/exporters/ExporterIntTestBaseWithOtelCollector.java +++ b/src/test/java/rocks/inspectit/oce/eum/server/exporters/ExporterIntTestBaseWithOtelCollector.java @@ -47,7 +47,7 @@ public class ExporterIntTestBaseWithOtelCollector extends ExporterIntMockMvcTest protected static final String OTLP_HTTP_METRICS_PATH = "/v1/metrics"; - static final String COLLECTOR_TAG = "0.58.0"; + static final String COLLECTOR_TAG = "0.70.0"; static final String COLLECTOR_IMAGE = "otel/opentelemetry-collector-contrib:" + COLLECTOR_TAG; @@ -223,6 +223,16 @@ protected void awaitMetricsExported(String metricName, double value, ViewDefinit * @param expected whether the value is expected or not */ protected void assertMetric(double value, boolean expected) { + assertMetric(value, expected, ViewDefinitionSettings.Aggregation.SUM); + } + + /** + * Checks if a metric with the given value has been recorded or not + * + * @param value the value + * @param expected whether the value is expected or not + */ + protected void assertMetric(double value, boolean expected, ViewDefinitionSettings.Aggregation aggregation) { assertThat(grpcServer.metricRequests.stream() .anyMatch(mReq -> mReq.getResourceMetricsList() .stream() @@ -230,10 +240,11 @@ protected void assertMetric(double value, boolean expected) { .stream() .anyMatch(iml -> iml.getMetricsList() .stream() - .anyMatch(metric -> metric.getSum() - .getDataPointsList() + .anyMatch(metric -> (aggregation == ViewDefinitionSettings.Aggregation.LAST_VALUE ? + metric.getGauge().getDataPointsList() : metric.getSum().getDataPointsList()) .stream() - .anyMatch(d -> expected ? d.getAsDouble() == value : d.getAsDouble() != value)))))).isTrue(); + .anyMatch(d -> expected ? d.getAsDouble() == value : d.getAsDouble() != value + )))))).isTrue(); } /** diff --git a/src/test/java/rocks/inspectit/oce/eum/server/exporters/GzipCompressionMethodIntTest.java b/src/test/java/rocks/inspectit/oce/eum/server/exporters/GzipCompressionMethodIntTest.java index ff37fe8..babeaf7 100644 --- a/src/test/java/rocks/inspectit/oce/eum/server/exporters/GzipCompressionMethodIntTest.java +++ b/src/test/java/rocks/inspectit/oce/eum/server/exporters/GzipCompressionMethodIntTest.java @@ -95,7 +95,6 @@ void verifyOtlpGrpcMetrics() throws Exception { sendBeacon(beacon); // wait until metrics have been exported awaitMetricsExported(METRIC_END_TIMESTAMP_KEY_NAME, 41, ViewDefinitionSettings.Aggregation.LAST_VALUE); - assertMetric(1334, false); + assertMetric(1334, false, ViewDefinitionSettings.Aggregation.LAST_VALUE); } - -} +} \ No newline at end of file diff --git a/src/test/java/rocks/inspectit/oce/eum/server/exporters/metrics/PrometheusExporterServiceIntTest.java b/src/test/java/rocks/inspectit/oce/eum/server/exporters/metrics/PrometheusExporterServiceIntTest.java index a1848c3..0bbca76 100644 --- a/src/test/java/rocks/inspectit/oce/eum/server/exporters/metrics/PrometheusExporterServiceIntTest.java +++ b/src/test/java/rocks/inspectit/oce/eum/server/exporters/metrics/PrometheusExporterServiceIntTest.java @@ -17,7 +17,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.util.SocketUtils; +import org.springframework.test.util.TestSocketUtils; import rocks.inspectit.oce.eum.server.exporters.ExporterIntMockMvcTestBase; import java.util.Map; @@ -41,7 +41,7 @@ static class EnvInitializer implements ApplicationContextInitializer