diff --git a/Makefile b/Makefile index 63972623..814e4ad4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=1.8.7 +VERSION=1.8.8 default: compile @@ -63,4 +63,4 @@ refresh: ./gradlew --refresh-dependencies upgrade-wrapper: - ./gradlew wrapper --gradle-version=6.7.1 --distribution-type=bin \ No newline at end of file + ./gradlew wrapper --gradle-version=6.8.1 --distribution-type=bin \ No newline at end of file diff --git a/README.md b/README.md index e73fe24d..2a99b473 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,8 @@ scrape_configs: The docker images are available via: ```bash -docker pull pambrose/prometheus-proxy:1.8.7 -docker pull pambrose/prometheus-agent:1.8.7 +docker pull pambrose/prometheus-proxy:1.8.8 +docker pull pambrose/prometheus-agent:1.8.8 ``` Start a proxy container with: @@ -110,7 +110,7 @@ Start a proxy container with: docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \ --env ADMIN_ENABLED=true \ --env METRICS_ENABLED=true \ - pambrose/prometheus-proxy:1.8.7 + pambrose/prometheus-proxy:1.8.8 ``` Start an agent container with: @@ -118,7 +118,7 @@ Start an agent container with: ```bash docker run --rm -p 8083:8083 -p 8093:8093 \ --env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \ - pambrose/prometheus-agent:1.8.7 + pambrose/prometheus-agent:1.8.8 ``` Using the config file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf), @@ -134,7 +134,7 @@ is in your current directory, run an agent container with: docker run --rm -p 8083:8083 -p 8093:8093 \ --mount type=bind,source="$(pwd)"/prom-agent.conf,target=/app/prom-agent.conf \ --env AGENT_CONFIG=prom-agent.conf \ - pambrose/prometheus-agent:1.8.7 + pambrose/prometheus-agent:1.8.8 ``` **Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure @@ -255,7 +255,7 @@ docker run --rm -p 8082:8082 -p 8092:8092 -p 50440:50440 -p 8080:8080 \ --env PROXY_CONFIG=tls-no-mutual-auth.conf \ --env ADMIN_ENABLED=true \ --env METRICS_ENABLED=true \ - pambrose/prometheus-proxy:1.8.7 + pambrose/prometheus-proxy:1.8.8 docker run --rm -p 8083:8083 -p 8093:8093 \ --mount type=bind,source="$(pwd)"/testing/certs,target=/app/testing/certs \ @@ -263,7 +263,7 @@ docker run --rm -p 8083:8083 -p 8093:8093 \ --env AGENT_CONFIG=tls-no-mutual-auth.conf \ --env PROXY_HOSTNAME=mymachine.lan:50440 \ --name docker-agent \ - pambrose/prometheus-agent:1.8.7 + pambrose/prometheus-agent:1.8.8 ``` **Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure diff --git a/bin/docker-agent.sh b/bin/docker-agent.sh index 71cdf17b..3b729074 100755 --- a/bin/docker-agent.sh +++ b/bin/docker-agent.sh @@ -3,4 +3,4 @@ docker run --rm -p 8083:8083 -p 8093:8093 \ --env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \ --env PROXY_HOSTNAME=mymachine.lan \ - pambrose/prometheus-agent:1.8.7 + pambrose/prometheus-agent:1.8.8 diff --git a/bin/docker-proxy.sh b/bin/docker-proxy.sh index ec47b38e..077650ec 100755 --- a/bin/docker-proxy.sh +++ b/bin/docker-proxy.sh @@ -2,4 +2,4 @@ docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \ --env PROXY_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \ - pambrose/prometheus-proxy:1.8.7 + pambrose/prometheus-proxy:1.8.8 diff --git a/build.gradle b/build.gradle index c86a06dc..fcd009d9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,17 @@ plugins { id 'idea' id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.4.10' + id 'org.jetbrains.kotlin.jvm' version '1.4.30' id 'com.google.protobuf' version '0.8.14' id "com.github.ben-manes.versions" version '0.36.0' id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'com.github.gmazzo.buildconfig' version '2.0.2' id 'jacoco' id 'com.github.kt3k.coveralls' version '2.10.2' } group = 'io.prometheus' -version = '1.8.7' +version = '1.8.8' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -74,6 +75,12 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" } +buildConfig { + buildConfigField('String', 'APP_NAME', "\"${project.name}\"") + buildConfigField('String', 'APP_VERSION', "\"${project.version}\"") + buildConfigField('String', 'APP_RELEASE_DATE', "\"2/3/21\"") +} + /* sourceSets { main.java.srcDirs += ['src/main/java'] diff --git a/etc/compose/proxy.yml b/etc/compose/proxy.yml index 1d2b9dbc..e23023b2 100644 --- a/etc/compose/proxy.yml +++ b/etc/compose/proxy.yml @@ -1,6 +1,6 @@ prometheus-proxy: autoredeploy: true - image: 'pambrose/prometheus-proxy:1.8.7' + image: 'pambrose/prometheus-proxy:1.8.8' ports: - '8080:8080' - '8082:8082' diff --git a/gradle.properties b/gradle.properties index df28ac54..d9b6b598 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,19 +7,19 @@ org.gradle.caching=true org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 annotation_version=1.3.2 coroutines_version=1.4.2 -dropwizard_version=4.1.16 -gengrpc_version=0.2.1 -grpc_version=1.34.0 +dropwizard_version=4.1.17 +gengrpc_version=1.0.0 +grpc_version=1.35.0 jcommander_version=1.78 jetty_version=9.4.32.v20200930 junit_version=5.7.0 -kluent_version=1.64 -ktor_version=1.4.2 +kluent_version=1.65 +ktor_version=1.5.0 logback_version=1.2.3 -logging_version=2.0.3 -prometheus_version=0.9.0 +logging_version=2.0.4 +prometheus_version=0.10.0 protoc_version=3.12.4 slf4j_version=1.7.30 typesafe_version=1.4.1 -utils_version=1.5.0 +utils_version=1.7.0 zipkin_version=5.12.7 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca164..28ff446a 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-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/io/prometheus/Agent.kt b/src/main/kotlin/io/prometheus/Agent.kt index 3ce09511..4889e59c 100644 --- a/src/main/kotlin/io/prometheus/Agent.kt +++ b/src/main/kotlin/io/prometheus/Agent.kt @@ -38,6 +38,7 @@ import io.prometheus.common.ConfigWrappers.newAdminConfig import io.prometheus.common.ConfigWrappers.newMetricsConfig import io.prometheus.common.ConfigWrappers.newZipkinConfig import io.prometheus.common.getVersionDesc +import io.prometheus.prometheus_proxy.BuildConfig import kotlinx.coroutines.* import mu.KLogging import java.util.concurrent.CountDownLatch @@ -50,7 +51,7 @@ import kotlin.time.TimeSource.Monotonic import kotlin.time.milliseconds import kotlin.time.seconds -@Version(version = "1.8.7", date = "12/4/20") +@Version(version = BuildConfig.APP_VERSION, date = BuildConfig.APP_RELEASE_DATE) class Agent(val options: AgentOptions, inProcessServerName: String = "", testMode: Boolean = false, diff --git a/src/main/kotlin/io/prometheus/Proxy.kt b/src/main/kotlin/io/prometheus/Proxy.kt index d9178a0d..9036608d 100644 --- a/src/main/kotlin/io/prometheus/Proxy.kt +++ b/src/main/kotlin/io/prometheus/Proxy.kt @@ -38,6 +38,7 @@ import io.prometheus.common.ConfigWrappers.newMetricsConfig import io.prometheus.common.ConfigWrappers.newZipkinConfig import io.prometheus.common.GrpcObjects.EMPTY_AGENT_ID import io.prometheus.common.getVersionDesc +import io.prometheus.prometheus_proxy.BuildConfig import io.prometheus.proxy.* import kotlinx.coroutines.runBlocking import mu.KLogging @@ -45,7 +46,7 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter import kotlin.time.milliseconds -@Version(version = "1.8.7", date = "12/4/20") +@Version(version = BuildConfig.APP_VERSION, date = BuildConfig.APP_RELEASE_DATE) class Proxy(val options: ProxyOptions, proxyHttpPort: Int = options.proxyHttpPort, inProcessServerName: String = "", @@ -158,6 +159,7 @@ class Proxy(val options: ProxyOptions, agentContextManager.agentContextMap.entries .filter { it.value.scrapeRequestBacklogSize >= unhealthySize } .map { "${it.value} ${it.value.scrapeRequestBacklogSize}" } + .toMutableList() if (vals.isEmpty()) { HealthCheck.Result.healthy() } diff --git a/src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt b/src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt index 7de29569..1b085c98 100644 --- a/src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt +++ b/src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt @@ -129,6 +129,7 @@ internal class AgentGrpcService(internal val agent: Agent, channel = channel(hostName = hostName, port = port, + enableRetry = true, tlsContext = tlsContext, overrideAuthority = agent.options.overrideAuthority, inProcessServerName = inProcessServerName) { diff --git a/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt b/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt index c4a2abe3..6617d793 100644 --- a/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt +++ b/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt @@ -74,7 +74,10 @@ internal class AgentHttpService(val agent: Agent) { val timeout = agent.configVals.agent.internal.cioTimeoutSecs.seconds CIO.create { requestTimeout = timeout.toLongMilliseconds() } .use { engine -> - HttpClient(engine) { install(HttpTimeout) } + HttpClient(engine) { + expectSuccess = false + install(HttpTimeout) + } .use { client -> client.get(url, { diff --git a/src/main/kotlin/io/prometheus/agent/AgentOptions.kt b/src/main/kotlin/io/prometheus/agent/AgentOptions.kt index d95ccf24..7d223bc0 100644 --- a/src/main/kotlin/io/prometheus/agent/AgentOptions.kt +++ b/src/main/kotlin/io/prometheus/agent/AgentOptions.kt @@ -30,7 +30,7 @@ class AgentOptions(argv: Array, exitOnMissingConfig: Boolean) : BaseOptions(Agent::class.java.name, argv, AGENT_CONFIG.name, exitOnMissingConfig) { constructor(args: List, exitOnMissingConfig: Boolean) : - this(Iterables.toArray(args, String::class.java), exitOnMissingConfig) + this(Iterables.toArray(args.toMutableList(), String::class.java), exitOnMissingConfig) constructor(configFilename: String, exitOnMissingConfig: Boolean) : this(listOf("--config", configFilename), exitOnMissingConfig) diff --git a/src/main/kotlin/io/prometheus/proxy/ProxyOptions.kt b/src/main/kotlin/io/prometheus/proxy/ProxyOptions.kt index 6b9b604d..45fc7fdb 100644 --- a/src/main/kotlin/io/prometheus/proxy/ProxyOptions.kt +++ b/src/main/kotlin/io/prometheus/proxy/ProxyOptions.kt @@ -27,7 +27,7 @@ import kotlin.time.seconds class ProxyOptions(argv: Array) : BaseOptions(Proxy::class.java.simpleName, argv, PROXY_CONFIG.name) { - constructor(args: List) : this(Iterables.toArray(args, String::class.java)) + constructor(args: List) : this(Iterables.toArray(args.toMutableList(), String::class.java)) @Parameter(names = ["-p", "--port"], description = "Proxy listen port") var proxyHttpPort = -1 diff --git a/src/test/kotlin/io/prometheus/AdminDefaultPathTest.kt b/src/test/kotlin/io/prometheus/AdminDefaultPathTest.kt index a00be68b..381f25c0 100644 --- a/src/test/kotlin/io/prometheus/AdminDefaultPathTest.kt +++ b/src/test/kotlin/io/prometheus/AdminDefaultPathTest.kt @@ -40,7 +40,7 @@ class AdminDefaultPathTest { fun proxyPingPathTest() { proxyConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.pingPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.pingPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldStartWith "pong" } @@ -51,7 +51,7 @@ class AdminDefaultPathTest { fun agentPingPathTest() { agentConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.pingPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.pingPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldStartWith "pong" } @@ -62,7 +62,7 @@ class AdminDefaultPathTest { fun proxyVersionPathTest() { agentConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.versionPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.versionPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldContain "Version" } @@ -73,7 +73,7 @@ class AdminDefaultPathTest { fun agentVersionPathTest() { agentConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.versionPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.versionPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldContain "Version" } @@ -84,7 +84,7 @@ class AdminDefaultPathTest { fun proxyHealthCheckPathTest() { proxyConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.healthCheckPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.healthCheckPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText().length shouldBeGreaterThan 10 } @@ -95,7 +95,7 @@ class AdminDefaultPathTest { fun agentHealthCheckPathTest() { agentConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.healthCheckPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.healthCheckPath}".withPrefix()) { response -> response.readText().length shouldBeGreaterThan 10 } } @@ -105,7 +105,7 @@ class AdminDefaultPathTest { fun proxyThreadDumpPathTest() { proxyConfigVals.admin .also { admin -> - blockingGet("${admin.port}/${admin.threadDumpPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.threadDumpPath}".withPrefix()) { response -> response.readText().length shouldBeGreaterThan 10 } } @@ -113,7 +113,7 @@ class AdminDefaultPathTest { @Test fun agentThreadDumpPathTest() { - blockingGet("${agentConfigVals.admin.port}/${agentConfigVals.admin.threadDumpPath}".addPrefix()) { response -> + blockingGet("${agentConfigVals.admin.port}/${agentConfigVals.admin.threadDumpPath}".withPrefix()) { response -> response.readText().length shouldBeGreaterThan 10 } } diff --git a/src/test/kotlin/io/prometheus/AdminEmptyPathTest.kt b/src/test/kotlin/io/prometheus/AdminEmptyPathTest.kt index 084519b5..1e3a6355 100644 --- a/src/test/kotlin/io/prometheus/AdminEmptyPathTest.kt +++ b/src/test/kotlin/io/prometheus/AdminEmptyPathTest.kt @@ -39,7 +39,7 @@ class AdminEmptyPathTest { admin.port shouldBeEqualTo 8098 admin.pingPath shouldBeEqualTo "" - blockingGet("${admin.port}/${admin.pingPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.pingPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } @@ -52,7 +52,7 @@ class AdminEmptyPathTest { admin.port shouldBeEqualTo 8098 admin.versionPath shouldBeEqualTo "" - blockingGet("${admin.port}/${admin.versionPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.versionPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } @@ -64,7 +64,7 @@ class AdminEmptyPathTest { .also { admin -> admin.healthCheckPath shouldBeEqualTo "" - blockingGet("${admin.port}/${admin.healthCheckPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.healthCheckPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } @@ -76,7 +76,7 @@ class AdminEmptyPathTest { .also { admin -> admin.threadDumpPath shouldBeEqualTo "" - blockingGet("${admin.port}/${admin.threadDumpPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.threadDumpPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } diff --git a/src/test/kotlin/io/prometheus/AdminNonDefaultPathTest.kt b/src/test/kotlin/io/prometheus/AdminNonDefaultPathTest.kt index 795d5267..c02cd96c 100644 --- a/src/test/kotlin/io/prometheus/AdminNonDefaultPathTest.kt +++ b/src/test/kotlin/io/prometheus/AdminNonDefaultPathTest.kt @@ -43,7 +43,7 @@ class AdminNonDefaultPathTest { admin.port shouldBeEqualTo 8099 admin.pingPath shouldBeEqualTo "pingPath2" - blockingGet("${admin.port}/${admin.pingPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.pingPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldStartWith "pong" } @@ -57,7 +57,7 @@ class AdminNonDefaultPathTest { admin.port shouldBeEqualTo 8099 admin.versionPath shouldBeEqualTo "versionPath2" - blockingGet("${admin.port}/${admin.versionPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.versionPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText() shouldContain "Version" } @@ -70,7 +70,7 @@ class AdminNonDefaultPathTest { .also { admin -> admin.healthCheckPath shouldBeEqualTo "healthCheckPath2" - blockingGet("${admin.port}/${admin.healthCheckPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.healthCheckPath}".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.OK response.readText().length shouldBeGreaterThan 10 } @@ -83,7 +83,7 @@ class AdminNonDefaultPathTest { .also { admin -> admin.threadDumpPath shouldBeEqualTo "threadDumpPath2" - blockingGet("${admin.port}/${admin.threadDumpPath}".addPrefix()) { response -> + blockingGet("${admin.port}/${admin.threadDumpPath}".withPrefix()) { response -> response.readText().length shouldBeGreaterThan 10 } } diff --git a/src/test/kotlin/io/prometheus/NettyTestWithAdminMetricsTest.kt b/src/test/kotlin/io/prometheus/NettyTestWithAdminMetricsTest.kt index 2ecfd12d..2f4a7180 100644 --- a/src/test/kotlin/io/prometheus/NettyTestWithAdminMetricsTest.kt +++ b/src/test/kotlin/io/prometheus/NettyTestWithAdminMetricsTest.kt @@ -44,7 +44,7 @@ class NettyTestWithAdminMetricsTest : CommonTests(ProxyCallTestArgs(agent = agen fun adminDebugCallsTest() { runBlocking { withHttpClient { - get("8093/debug".addPrefix()) { response -> + get("8093/debug".withPrefix()) { response -> val body = response.readText() body.length shouldBeGreaterThan 100 response.status shouldBeEqualTo HttpStatusCode.OK @@ -52,7 +52,7 @@ class NettyTestWithAdminMetricsTest : CommonTests(ProxyCallTestArgs(agent = agen } withHttpClient { - get("8092/debug".addPrefix()) { response -> + get("8092/debug".withPrefix()) { response -> val body = response.readText() body.length shouldBeGreaterThan 100 response.status shouldBeEqualTo HttpStatusCode.OK diff --git a/src/test/kotlin/io/prometheus/ProxyTests.kt b/src/test/kotlin/io/prometheus/ProxyTests.kt index a50ed8c3..633565b3 100644 --- a/src/test/kotlin/io/prometheus/ProxyTests.kt +++ b/src/test/kotlin/io/prometheus/ProxyTests.kt @@ -91,9 +91,9 @@ internal object ProxyTests : KLogging() { } delay(2.seconds) // Give http server a chance to start - pathManager.registerPath("/$proxyPath", "$agentPort/$agentPath".addPrefix()) + pathManager.registerPath("/$proxyPath", "$agentPort/$agentPath".withPrefix()) - blockingGet("$PROXY_PORT/$proxyPath".addPrefix()) { response -> + blockingGet("$PROXY_PORT/$proxyPath".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.RequestTimeout } @@ -166,7 +166,7 @@ internal object ProxyTests : KLogging() { logger.debug { "Registering paths" } repeat(args.pathCount) { i -> val index = httpServers.size.random() - args.agent.pathManager.registerPath("proxy-$i", "${args.startPort + index}/agent-$index".addPrefix()) + args.agent.pathManager.registerPath("proxy-$i", "${args.startPort + index}/agent-$index".withPrefix()) pathMap[i] = index } @@ -260,7 +260,7 @@ internal object ProxyTests : KLogging() { httpIndex.shouldNotBeNull() withHttpClient(httpClient) { - get("$PROXY_PORT/proxy-$index".addPrefix()) { response -> + get("$PROXY_PORT/proxy-$index".withPrefix()) { response -> val body = response.readText() body shouldBeEqualTo contentMap[httpIndex] response.status shouldBeEqualTo HttpStatusCode.OK diff --git a/src/test/kotlin/io/prometheus/SimpleTests.kt b/src/test/kotlin/io/prometheus/SimpleTests.kt index 6a3fd640..0315147e 100644 --- a/src/test/kotlin/io/prometheus/SimpleTests.kt +++ b/src/test/kotlin/io/prometheus/SimpleTests.kt @@ -19,7 +19,7 @@ package io.prometheus import com.github.pambrose.common.dsl.KtorDsl.blockingGet -import io.ktor.http.HttpStatusCode +import io.ktor.http.* import io.prometheus.TestConstants.PROXY_PORT import io.prometheus.agent.AgentPathManager import kotlinx.coroutines.Dispatchers @@ -37,14 +37,14 @@ internal object SimpleTests : KLogging() { fun missingPathTest(caller: String) { logger.debug { "Calling missingPathTest() from $caller" } - blockingGet("$PROXY_PORT/".addPrefix()) { response -> + blockingGet("$PROXY_PORT/".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } fun invalidPathTest(caller: String) { logger.debug { "Calling invalidPathTest() from $caller" } - blockingGet("$PROXY_PORT/invalid_path".addPrefix()) { response -> + blockingGet("$PROXY_PORT/invalid_path".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } } @@ -59,7 +59,7 @@ internal object SimpleTests : KLogging() { repeat(TestConstants.REPS) { i -> val path = "test-$i" pathManager.let { manager -> - manager.registerPath(path, "$PROXY_PORT/$path".addPrefix()) + manager.registerPath(path, "$PROXY_PORT/$path".withPrefix()) cnt++ manager.pathMapSize() shouldBeEqualTo originalSize + cnt manager.unregisterPath(path) @@ -72,8 +72,8 @@ internal object SimpleTests : KLogging() { suspend fun invalidAgentUrlTest(pathManager: AgentPathManager, caller: String, badPath: String = "badPath") { logger.debug { "Calling invalidAgentUrlTest() from $caller" } - pathManager.registerPath(badPath, "33/metrics".addPrefix()) - blockingGet("$PROXY_PORT/$badPath".addPrefix()) { response -> + pathManager.registerPath(badPath, "33/metrics".withPrefix()) + blockingGet("$PROXY_PORT/$badPath".withPrefix()) { response -> response.status shouldBeEqualTo HttpStatusCode.NotFound } pathManager.unregisterPath(badPath) @@ -92,7 +92,7 @@ internal object SimpleTests : KLogging() { List(TestConstants.REPS) { i -> launch(Dispatchers.Default + exceptionHandler(logger)) { val path = "test-$i}" - val url = "$PROXY_PORT/$path".addPrefix() + val url = "$PROXY_PORT/$path".withPrefix() mutex.withLock { paths += path } pathManager.registerPath(path, url) } diff --git a/src/test/kotlin/io/prometheus/TestUtils.kt b/src/test/kotlin/io/prometheus/TestUtils.kt index 5ba268f3..8cc50d74 100644 --- a/src/test/kotlin/io/prometheus/TestUtils.kt +++ b/src/test/kotlin/io/prometheus/TestUtils.kt @@ -92,7 +92,5 @@ fun exceptionHandler(logger: KLogger) = logger.warn(e) { "CoroutineExceptionHandler caught: $e" } } -fun String.addPrefix(): String { - val prefix = "http://localhost:" - return if (this.startsWith(prefix)) this else (prefix + this) -} \ No newline at end of file +fun String.withPrefix(prefix: String = "http://localhost:") = + if (this.startsWith(prefix)) this else (prefix + this) \ No newline at end of file diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 00000000..28c7009c --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%file:%line] - %msg%n + + + + + + + +