From 19437d38313746a0e9549a627d9b47c5da52c8f4 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Wed, 31 Aug 2022 16:23:41 +0900 Subject: [PATCH 1/2] HTTP server instrumentation TCK Similar to the http client instrumentation tests, these tests are meant for http server instrumentation to ensure they include the expected tags in a minimal set of scenarios that should be supported. --- config/checkstyle/checkstyle-suppressions.xml | 1 + dependencies.gradle | 1 + .../gradle.lockfile | 2 + .../micrometer-registry-atlas/gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../micrometer-registry-humio/gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../micrometer-registry-jmx/gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + micrometer-jersey2/gradle.lockfile | 2 + micrometer-test/build.gradle | 7 + micrometer-test/gradle.lockfile | 31 +++++ ...imingInstrumentationVerificationTests.java | 120 ++++++++++++++++++ ...imingInstrumentationVerificationTests.java | 88 +++++++++++++ ...imingInstrumentationVerificationTests.java | 87 +++++++++++++ .../gradle.lockfile | 2 + .../gradle.lockfile | 2 + 31 files changed, 383 insertions(+) create mode 100644 micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java create mode 100644 micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java create mode 100644 micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java diff --git a/config/checkstyle/checkstyle-suppressions.xml b/config/checkstyle/checkstyle-suppressions.xml index abb7a4ca38..78defbd99c 100644 --- a/config/checkstyle/checkstyle-suppressions.xml +++ b/config/checkstyle/checkstyle-suppressions.xml @@ -8,6 +8,7 @@ + diff --git a/dependencies.gradle b/dependencies.gradle index 52c7728e83..562846e72e 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -53,6 +53,7 @@ def VERSIONS = [ 'org.awaitility:awaitility:latest.release', 'org.eclipse.jetty:jetty-client:9.+', 'org.eclipse.jetty:jetty-server:9.+', + 'org.eclipse.jetty:jetty-servlet:9.+', 'org.ehcache:ehcache:latest.release', 'org.glassfish.jersey.core:jersey-server:2.+', 'org.glassfish.jersey.inject:jersey-hk2:2.+', diff --git a/implementations/micrometer-registry-appoptics/gradle.lockfile b/implementations/micrometer-registry-appoptics/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-appoptics/gradle.lockfile +++ b/implementations/micrometer-registry-appoptics/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-atlas/gradle.lockfile b/implementations/micrometer-registry-atlas/gradle.lockfile index 04f1526ceb..fa73ac9102 100644 --- a/implementations/micrometer-registry-atlas/gradle.lockfile +++ b/implementations/micrometer-registry-atlas/gradle.lockfile @@ -39,8 +39,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-azure-monitor/gradle.lockfile b/implementations/micrometer-registry-azure-monitor/gradle.lockfile index c0bcc702b5..ac4c1c0b44 100644 --- a/implementations/micrometer-registry-azure-monitor/gradle.lockfile +++ b/implementations/micrometer-registry-azure-monitor/gradle.lockfile @@ -38,8 +38,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-cloudwatch/gradle.lockfile b/implementations/micrometer-registry-cloudwatch/gradle.lockfile index 085b939660..20a640b3ca 100644 --- a/implementations/micrometer-registry-cloudwatch/gradle.lockfile +++ b/implementations/micrometer-registry-cloudwatch/gradle.lockfile @@ -47,8 +47,10 @@ org.apache.httpcomponents:httpclient:4.5.13=compileClasspath,default,runtimeClas org.apache.httpcomponents:httpcore:4.4.13=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-cloudwatch2/gradle.lockfile b/implementations/micrometer-registry-cloudwatch2/gradle.lockfile index f6fe18c8c0..33cd0685da 100644 --- a/implementations/micrometer-registry-cloudwatch2/gradle.lockfile +++ b/implementations/micrometer-registry-cloudwatch2/gradle.lockfile @@ -48,8 +48,10 @@ org.apache.httpcomponents:httpclient:4.5.13=default,runtimeClasspath,testRuntime org.apache.httpcomponents:httpcore:4.4.13=default,runtimeClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-datadog/gradle.lockfile b/implementations/micrometer-registry-datadog/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-datadog/gradle.lockfile +++ b/implementations/micrometer-registry-datadog/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-dynatrace/gradle.lockfile b/implementations/micrometer-registry-dynatrace/gradle.lockfile index 451e42c56c..1ac924aa0c 100644 --- a/implementations/micrometer-registry-dynatrace/gradle.lockfile +++ b/implementations/micrometer-registry-dynatrace/gradle.lockfile @@ -40,8 +40,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-elastic/gradle.lockfile b/implementations/micrometer-registry-elastic/gradle.lockfile index 7f1c49da37..2ce4ff7cf6 100644 --- a/implementations/micrometer-registry-elastic/gradle.lockfile +++ b/implementations/micrometer-registry-elastic/gradle.lockfile @@ -47,9 +47,11 @@ org.antlr:antlr4-runtime:4.9.2=checkstyle org.apache.commons:commons-compress:1.21=testCompileClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.jetbrains:annotations:17.0.0=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-ganglia/gradle.lockfile b/implementations/micrometer-registry-ganglia/gradle.lockfile index 6dac1839e8..dd4db2c3a4 100644 --- a/implementations/micrometer-registry-ganglia/gradle.lockfile +++ b/implementations/micrometer-registry-ganglia/gradle.lockfile @@ -38,8 +38,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-graphite/gradle.lockfile b/implementations/micrometer-registry-graphite/gradle.lockfile index 23db4dd200..ccc8830b72 100644 --- a/implementations/micrometer-registry-graphite/gradle.lockfile +++ b/implementations/micrometer-registry-graphite/gradle.lockfile @@ -56,8 +56,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-health/gradle.lockfile b/implementations/micrometer-registry-health/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-health/gradle.lockfile +++ b/implementations/micrometer-registry-health/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-humio/gradle.lockfile b/implementations/micrometer-registry-humio/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-humio/gradle.lockfile +++ b/implementations/micrometer-registry-humio/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-influx/gradle.lockfile b/implementations/micrometer-registry-influx/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-influx/gradle.lockfile +++ b/implementations/micrometer-registry-influx/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-jmx/gradle.lockfile b/implementations/micrometer-registry-jmx/gradle.lockfile index 7b50df65dd..4db9d8e4c8 100644 --- a/implementations/micrometer-registry-jmx/gradle.lockfile +++ b/implementations/micrometer-registry-jmx/gradle.lockfile @@ -39,8 +39,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-kairos/gradle.lockfile b/implementations/micrometer-registry-kairos/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-kairos/gradle.lockfile +++ b/implementations/micrometer-registry-kairos/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-new-relic/gradle.lockfile b/implementations/micrometer-registry-new-relic/gradle.lockfile index cb5bcee067..94ed903f46 100644 --- a/implementations/micrometer-registry-new-relic/gradle.lockfile +++ b/implementations/micrometer-registry-new-relic/gradle.lockfile @@ -36,8 +36,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-opentsdb/gradle.lockfile b/implementations/micrometer-registry-opentsdb/gradle.lockfile index bd14e2e62b..52a4b1d934 100644 --- a/implementations/micrometer-registry-opentsdb/gradle.lockfile +++ b/implementations/micrometer-registry-opentsdb/gradle.lockfile @@ -35,8 +35,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-prometheus/gradle.lockfile b/implementations/micrometer-registry-prometheus/gradle.lockfile index 05eb78bc9a..bafe7cd5d1 100644 --- a/implementations/micrometer-registry-prometheus/gradle.lockfile +++ b/implementations/micrometer-registry-prometheus/gradle.lockfile @@ -40,8 +40,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-signalfx/gradle.lockfile b/implementations/micrometer-registry-signalfx/gradle.lockfile index d8ef17b8d9..f616c9241a 100644 --- a/implementations/micrometer-registry-signalfx/gradle.lockfile +++ b/implementations/micrometer-registry-signalfx/gradle.lockfile @@ -36,8 +36,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-stackdriver/gradle.lockfile b/implementations/micrometer-registry-stackdriver/gradle.lockfile index 36f109661c..3a517757fb 100644 --- a/implementations/micrometer-registry-stackdriver/gradle.lockfile +++ b/implementations/micrometer-registry-stackdriver/gradle.lockfile @@ -70,10 +70,12 @@ org.apache.httpcomponents:httpclient:4.5.13=compileClasspath,default,runtimeClas org.apache.httpcomponents:httpcore:4.4.14=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle,compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.codehaus.mojo:animal-sniffer-annotations:1.20=default,runtimeClasspath,testRuntimeClasspath org.conscrypt:conscrypt-openjdk-uber:2.5.1=default,runtimeClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/implementations/micrometer-registry-wavefront/gradle.lockfile b/implementations/micrometer-registry-wavefront/gradle.lockfile index 918e9d06ec..544b48725f 100644 --- a/implementations/micrometer-registry-wavefront/gradle.lockfile +++ b/implementations/micrometer-registry-wavefront/gradle.lockfile @@ -41,8 +41,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle,compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/micrometer-jersey2/gradle.lockfile b/micrometer-jersey2/gradle.lockfile index 4fa34d2972..1114a594ce 100644 --- a/micrometer-jersey2/gradle.lockfile +++ b/micrometer-jersey2/gradle.lockfile @@ -44,6 +44,7 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle org.glassfish.hk2.external:aopalliance-repackaged:2.6.1=testRuntimeClasspath @@ -61,6 +62,7 @@ org.glassfish.jersey.media:jersey-media-jaxb:2.35=testCompileClasspath,testRunti org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory:2.35=testCompileClasspath,testRuntimeClasspath org.glassfish.jersey.test-framework:jersey-test-framework-core:2.35=testCompileClasspath,testRuntimeClasspath org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.25.0-GA=testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle diff --git a/micrometer-test/build.gradle b/micrometer-test/build.gradle index e9e8b7d29b..2caaaf53dd 100644 --- a/micrometer-test/build.gradle +++ b/micrometer-test/build.gradle @@ -10,6 +10,7 @@ dependencies { api 'ru.lanwen.wiremock:wiremock-junit5' api 'com.github.tomakehurst:wiremock-jre8-standalone' api 'org.mockito:mockito-core' + implementation 'org.awaitility:awaitility' testImplementation 'org.jsr107.ri:cache-ri-impl' @@ -24,4 +25,10 @@ dependencies { testImplementation 'io.projectreactor.netty:reactor-netty-http' testImplementation 'org.apache.httpcomponents:httpclient' testImplementation 'org.eclipse.jetty:jetty-client' + testImplementation 'org.eclipse.jetty:jetty-server' + testImplementation 'org.eclipse.jetty:jetty-servlet' + testImplementation 'org.glassfish.jersey.core:jersey-server' + testImplementation 'org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jdk-http:2.+' + // necessary for Jersey test framework + testRuntimeOnly 'org.glassfish.jersey.inject:jersey-hk2' } diff --git a/micrometer-test/gradle.lockfile b/micrometer-test/gradle.lockfile index 9c48fdeca1..bda21f7088 100644 --- a/micrometer-test/gradle.lockfile +++ b/micrometer-test/gradle.lockfile @@ -52,10 +52,18 @@ io.spring.javaformat:spring-javaformat-config:0.0.31=checkstyle io.spring.nohttp:nohttp-checkstyle:0.0.10=checkstyle,nohttp io.spring.nohttp:nohttp-cli:0.0.10=nohttp-cli io.spring.nohttp:nohttp:0.0.10=checkstyle,nohttp,nohttp-cli +jakarta.activation:jakarta.activation-api:1.2.2=testCompileClasspath,testRuntimeClasspath +jakarta.annotation:jakarta.annotation-api:1.3.5=testCompileClasspath,testRuntimeClasspath +jakarta.servlet:jakarta.servlet-api:4.0.4=testCompileClasspath,testRuntimeClasspath +jakarta.validation:jakarta.validation-api:2.0.2=testCompileClasspath,testRuntimeClasspath +jakarta.ws.rs:jakarta.ws.rs-api:2.1.6=testCompileClasspath,testRuntimeClasspath +jakarta.xml.bind:jakarta.xml.bind-api:2.3.3=testCompileClasspath,testRuntimeClasspath javax.annotation:jsr250-api:1.0=testCompileClasspath,testRuntimeClasspath javax.cache:cache-api:1.1.1=testCompileClasspath,testRuntimeClasspath javax.enterprise:cdi-api:1.0-SP4=testCompileClasspath,testRuntimeClasspath javax.inject:javax.inject:1=testCompileClasspath,testRuntimeClasspath +javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath +junit:junit:4.13.1=testCompileClasspath,testRuntimeClasspath net.bytebuddy:byte-buddy-agent:1.12.9=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath net.bytebuddy:byte-buddy:1.12.9=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath net.sf.ehcache:ehcache:2.10.9.2=testCompileClasspath,testRuntimeClasspath @@ -67,13 +75,36 @@ org.apache.httpcomponents:httpclient:4.5.13=testCompileClasspath,testRuntimeClas org.apache.httpcomponents:httpcore:4.4.13=testCompileClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=compileClasspath,testCompileClasspath org.assertj:assertj-core:3.22.0=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle,testCompileClasspath,testRuntimeClasspath org.eclipse.jetty:jetty-client:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath org.eclipse.jetty:jetty-http:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath org.eclipse.jetty:jetty-io:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath +org.eclipse.jetty:jetty-security:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath +org.eclipse.jetty:jetty-server:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath +org.eclipse.jetty:jetty-servlet:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath +org.eclipse.jetty:jetty-util-ajax:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath org.eclipse.jetty:jetty-util:9.4.48.v20220622=testCompileClasspath,testRuntimeClasspath +org.glassfish.hk2.external:aopalliance-repackaged:2.6.1=testRuntimeClasspath +org.glassfish.hk2.external:jakarta.inject:2.6.1=testCompileClasspath,testRuntimeClasspath +org.glassfish.hk2:hk2-api:2.6.1=testRuntimeClasspath +org.glassfish.hk2:hk2-locator:2.6.1=testRuntimeClasspath +org.glassfish.hk2:hk2-utils:2.6.1=testRuntimeClasspath +org.glassfish.hk2:osgi-resource-locator:1.0.3=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.containers:jersey-container-jdk-http:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.containers:jersey-container-servlet-core:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.core:jersey-client:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.core:jersey-common:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.core:jersey-server:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.inject:jersey-hk2:2.36=testRuntimeClasspath +org.glassfish.jersey.media:jersey-media-jaxb:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jdk-http:2.36=testCompileClasspath,testRuntimeClasspath +org.glassfish.jersey.test-framework:jersey-test-framework-core:2.36=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.javassist:javassist:3.25.0-GA=testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:1.0.0.Beta1=testCompileClasspath,testRuntimeClasspath org.jetbrains.kotlin:kotlin-stdlib-common:1.4.21=testCompileClasspath,testRuntimeClasspath diff --git a/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java new file mode 100644 index 0000000000..de08672784 --- /dev/null +++ b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java @@ -0,0 +1,120 @@ +/* + * Copyright 2022 VMware, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micrometer.core.instrument; + +import io.micrometer.core.annotation.Incubating; +import io.micrometer.core.instrument.search.RequiredSearch; +import io.micrometer.core.ipc.http.HttpSender; +import io.micrometer.core.ipc.http.HttpUrlConnectionSender; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.URI; +import java.time.Duration; +import java.util.function.Function; + +import static org.awaitility.Awaitility.await; + +/** + * Verify the instrumentation of an HTTP server has the minimum expected results. See + * {@link #startInstrumentedServer()} for the required specification the instrumented HTTP + * server must handle. + */ +@Incubating(since = "1.8.9") +public abstract class HttpServerTimingInstrumentationVerificationTests extends InstrumentationVerificationTests { + + private final HttpSender sender = new HttpUrlConnectionSender(); + + private URI baseUri; + + /** + * A default is provided that should be preferred by new instrumentations. Existing + * instrumentations that use a different value to maintain backwards compatibility may + * override this method to run tests with a different name used in assertions. + * @return name of the meter timing http client requests + */ + protected String timerName() { + return "http.server.requests"; + } + + /** + * Start the instrumented HTTP server to be tested. No request body or query + * parameters will be sent, and any response body will be ignored. The server MUST + * serve the following routes: + *
    + *
  • {@code GET /}
  • + *
  • {@code GET /hello/{name}} (templated path parameter)
  • + *
  • {@code GET /foundRedirect} (redirects to the root {@code /} with status code + * 302)
  • + *
  • {@code POST /error} (500 error response)
  • + *
+ * The server MUST NOT have a route for the following: + *
    + *
  • {@code GET /notFound} (returns 404 response)
  • + *
+ * @return base URI where the instrumented server is receiving requests. Must end with + * a slash (/). + */ + protected abstract URI startInstrumentedServer() throws Exception; + + /** + * Stop the instrumented server that was started with + * {@link #startInstrumentedServer()}. + */ + protected abstract void stopInstrumentedServer() throws Exception; + + @BeforeEach + void beforeEach() throws Exception { + baseUri = startInstrumentedServer(); + } + + @AfterEach + void afterEach() throws Exception { + stopInstrumentedServer(); + } + + @Test + void uriIsNotFound_whenRouteIsUnmapped() throws Throwable { + sender.get(baseUri + "notFound").send(); + checkTimer(rs -> rs.tags("uri", "NOT_FOUND", "status", "404", "method", "GET").timer().count() == 1); + } + + @Test + void uriTemplateIsTagged() throws Throwable { + sender.get(baseUri + "hello/world").send(); + checkTimer(rs -> rs.tags("uri", "/hello/{name}", "status", "200", "method", "GET").timer().count() == 1); + } + + @Test + void redirect() throws Throwable { + sender.get(baseUri + "foundRedirect").send(); + checkTimer(rs -> rs.tags("uri", "/foundRedirect", "status", "302", "method", "GET").timer().count() == 1); + } + + @Test + void errorResponse() throws Throwable { + sender.post(baseUri + "error").send(); + checkTimer(rs -> rs.tags("uri", "/error", "status", "500", "method", "POST").timer().count() == 1); + } + + private void checkTimer(Function timerCheck) { + // jersey instrumentation finishes after response is sent, creating a race + await().atLeast(Duration.ofMillis(25)).atMost(Duration.ofMillis(150)) + .until(() -> timerCheck.apply(getRegistry().get(timerName()))); + } + +} diff --git a/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java new file mode 100644 index 0000000000..8bf75686f1 --- /dev/null +++ b/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java @@ -0,0 +1,88 @@ +/* + * Copyright 2022 VMware, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micrometer.core.instrument; + +import io.micrometer.core.instrument.binder.jersey.server.DefaultJerseyTagsProvider; +import io.micrometer.core.instrument.binder.jersey.server.MetricsApplicationEventListener; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; + +import javax.ws.rs.*; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +class JerseyServerTimingInstrumentationVerificationTests extends HttpServerTimingInstrumentationVerificationTests { + + JerseyTest jerseyTest; + + @Override + protected URI startInstrumentedServer() throws Exception { + jerseyTest = new JerseyTest() { + @Override + protected Application configure() { + MetricsApplicationEventListener listener = new MetricsApplicationEventListener(getRegistry(), + new DefaultJerseyTagsProvider(), timerName(), true); + + ResourceConfig config = new ResourceConfig(); + config.register(listener); + config.register(TestResource.class); + + return config; + } + }; + + jerseyTest.setUp(); + + return jerseyTest.target().getUri(); + } + + @Override + protected void stopInstrumentedServer() throws Exception { + jerseyTest.tearDown(); + } + + @Path("/") + @Produces(MediaType.TEXT_PLAIN) + public static class TestResource { + + @GET + public String root() { + return "hello"; + } + + @GET + @Path("hello/{name}") + public String hello(@PathParam("name") String name) { + return "hello " + name; + } + + @GET + @Path("foundRedirect") + public Response redirect() { + return Response.status(302).location(URI.create("/")).build(); + } + + @POST + @Path("error") + public Response error() { + return Response.serverError().build(); + } + + } + +} diff --git a/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java new file mode 100644 index 0000000000..c1ed3ef092 --- /dev/null +++ b/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java @@ -0,0 +1,87 @@ +/* + * Copyright 2022 VMware, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micrometer.core.instrument; + +import io.micrometer.core.instrument.binder.jetty.TimedHandler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHandler; +import org.junit.jupiter.api.Disabled; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URI; + +@Disabled("URI is not tagged in generic Jetty servlet instrumentation") +class JettyServerTimingInstrumentationVerificationTests extends HttpServerTimingInstrumentationVerificationTests { + + private Server server; + + @Override + protected String timerName() { + return "jetty.server.requests"; + } + + @Override + protected URI startInstrumentedServer() throws Exception { + server = new Server(0); + TimedHandler timedHandler = new TimedHandler(getRegistry(), Tags.empty()); + ServletContextHandler servletContextHandler = new ServletContextHandler(); + servletContextHandler.setContextPath("/"); + servletContextHandler.addServlet(ServletHandler.Default404Servlet.class, "/notFound"); + servletContextHandler.addServlet(MyWebServlet.class, "/*"); + server.setHandler(servletContextHandler); + server.insertHandler(timedHandler); + server.start(); + return server.getURI(); + } + + @Override + protected void stopInstrumentedServer() throws Exception { + server.stop(); + } + + public static class MyWebServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if (req.getPathInfo().contentEquals("/")) { + resp.setStatus(200); + resp.getWriter().print("hello"); + } + else if (req.getPathInfo().startsWith("/home/")) { + resp.setStatus(200); + resp.getWriter().print("hello " + "world"); + } + else if (req.getPathInfo().contentEquals("/foundRedirect")) { + resp.sendRedirect("/"); + } + else { + resp.sendError(400); + } + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + super.doPost(req, resp); + } + + } + +} diff --git a/samples/micrometer-samples-hazelcast3/gradle.lockfile b/samples/micrometer-samples-hazelcast3/gradle.lockfile index cb84eb1b7a..a6090734c4 100644 --- a/samples/micrometer-samples-hazelcast3/gradle.lockfile +++ b/samples/micrometer-samples-hazelcast3/gradle.lockfile @@ -38,8 +38,10 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle org.junit.jupiter:junit-jupiter-api:5.8.2=testCompileClasspath,testRuntimeClasspath diff --git a/samples/micrometer-samples-jersey3/gradle.lockfile b/samples/micrometer-samples-jersey3/gradle.lockfile index 5593c0d667..87ccf0c737 100644 --- a/samples/micrometer-samples-jersey3/gradle.lockfile +++ b/samples/micrometer-samples-jersey3/gradle.lockfile @@ -43,6 +43,7 @@ org.antlr:antlr4-runtime:4.8-1=nohttp org.antlr:antlr4-runtime:4.9.2=checkstyle org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath org.assertj:assertj-core:3.22.0=testCompileClasspath,testRuntimeClasspath +org.awaitility:awaitility:4.2.0=testRuntimeClasspath org.checkerframework:checker-qual:2.11.1=nohttp org.checkerframework:checker-qual:3.12.0=checkstyle org.glassfish.hk2.external:aopalliance-repackaged:3.0.1=default,runtimeClasspath,testRuntimeClasspath @@ -60,6 +61,7 @@ org.glassfish.jersey.media:jersey-media-jaxb:3.0.3=testCompileClasspath,testRunt org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jdk-http:3.0.3=testCompileClasspath,testRuntimeClasspath org.glassfish.jersey.test-framework:jersey-test-framework-core:3.0.3=testCompileClasspath,testRuntimeClasspath org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:2.1=testRuntimeClasspath org.hdrhistogram:HdrHistogram:2.1.12=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.javassist:javassist:3.25.0-GA=default,runtimeClasspath,testRuntimeClasspath org.javassist:javassist:3.26.0-GA=checkstyle From 3ae1a6f62bf341ae181bce21bad1e4b42adb6bed Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Mon, 12 Sep 2022 16:28:48 +0900 Subject: [PATCH 2/2] Provide constants for routes to instrument --- ...imingInstrumentationVerificationTests.java | 61 +++++++++++++++---- ...imingInstrumentationVerificationTests.java | 7 ++- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java index de08672784..4c33f2b1fd 100644 --- a/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java +++ b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java @@ -54,20 +54,15 @@ protected String timerName() { /** * Start the instrumented HTTP server to be tested. No request body or query * parameters will be sent, and any response body will be ignored. The server MUST - * serve the following routes: - *
    - *
  • {@code GET /}
  • - *
  • {@code GET /hello/{name}} (templated path parameter)
  • - *
  • {@code GET /foundRedirect} (redirects to the root {@code /} with status code - * 302)
  • - *
  • {@code POST /error} (500 error response)
  • - *
- * The server MUST NOT have a route for the following: + * serve the routes described by {@link InstrumentedRoutes}. Constants are available + * in that class for the routes that will have requests sent to them as part of the + * TCK. The server MUST NOT have a route for the following: *
    *
  • {@code GET /notFound} (returns 404 response)
  • *
* @return base URI where the instrumented server is receiving requests. Must end with * a slash (/). + * @see InstrumentedRoutes */ protected abstract URI startInstrumentedServer() throws Exception; @@ -96,19 +91,22 @@ void uriIsNotFound_whenRouteIsUnmapped() throws Throwable { @Test void uriTemplateIsTagged() throws Throwable { sender.get(baseUri + "hello/world").send(); - checkTimer(rs -> rs.tags("uri", "/hello/{name}", "status", "200", "method", "GET").timer().count() == 1); + checkTimer(rs -> rs.tags("uri", InstrumentedRoutes.TEMPLATED_ROUTE, "status", "200", "method", "GET").timer() + .count() == 1); } @Test void redirect() throws Throwable { sender.get(baseUri + "foundRedirect").send(); - checkTimer(rs -> rs.tags("uri", "/foundRedirect", "status", "302", "method", "GET").timer().count() == 1); + checkTimer(rs -> rs.tags("uri", InstrumentedRoutes.REDIRECT, "status", "302", "method", "GET").timer() + .count() == 1); } @Test void errorResponse() throws Throwable { sender.post(baseUri + "error").send(); - checkTimer(rs -> rs.tags("uri", "/error", "status", "500", "method", "POST").timer().count() == 1); + checkTimer( + rs -> rs.tags("uri", InstrumentedRoutes.ERROR, "status", "500", "method", "POST").timer().count() == 1); } private void checkTimer(Function timerCheck) { @@ -117,4 +115,43 @@ private void checkTimer(Function timerCheck) { .until(() -> timerCheck.apply(getRegistry().get(timerName()))); } + /** + * Class containing constants that can be used for implementing the HTTP routes that + * the instrumented server needs to serve to pass the + * {@link HttpServerTimingInstrumentationVerificationTests}. The HTTP server MUST + * serve the following: + *
    + *
  • {@link #ROOT}: {@code GET /}
  • + *
  • {@link #TEMPLATED_ROUTE}: {@code GET /hello/{name}}
  • + *
  • {@link #REDIRECT}: {@code GET /foundRedirect}
  • + *
  • {@link #ERROR}: {@code POST /error}
  • + *
+ */ + public static class InstrumentedRoutes { + + /** + * Path for the route with a path variable. The templated route is expected to be + * used in the URI tag. + */ + public static final String TEMPLATED_ROUTE = "/hello/{name}"; + + /** + * Path for the root route. + */ + public static final String ROOT = "/"; + + /** + * Path for the route that will respond with a 500 server error to a POST method + * request. + */ + public static final String ERROR = "/error"; + + /** + * Path for the route that will redirect with status code 302 to the {@link #ROOT} + * route. + */ + public static final String REDIRECT = "/foundRedirect"; + + } + } diff --git a/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java index 8bf75686f1..04708a9793 100644 --- a/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java +++ b/micrometer-test/src/test/java/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java @@ -61,24 +61,25 @@ protected void stopInstrumentedServer() throws Exception { public static class TestResource { @GET + @Path(InstrumentedRoutes.ROOT) public String root() { return "hello"; } @GET - @Path("hello/{name}") + @Path(InstrumentedRoutes.TEMPLATED_ROUTE) public String hello(@PathParam("name") String name) { return "hello " + name; } @GET - @Path("foundRedirect") + @Path(InstrumentedRoutes.REDIRECT) public Response redirect() { return Response.status(302).location(URI.create("/")).build(); } @POST - @Path("error") + @Path(InstrumentedRoutes.ERROR) public Response error() { return Response.serverError().build(); }