diff --git a/examples/simple.conf b/examples/simple.conf index 3d9acf0b..8f7651f6 100644 --- a/examples/simple.conf +++ b/examples/simple.conf @@ -4,7 +4,7 @@ proxy { } agent { - proxy.hostname = ${HOSTNAME} + proxy.hostname = localhost admin.enabled: true metrics.enabled: true @@ -12,12 +12,12 @@ agent { { name: proxy path: proxy_metrics - url: "http://"${HOSTNAME}":8082/metrics" + url: "http://localhost:8082/metrics" } { name: agent path: agent_metrics - url: "http://"${HOSTNAME}":8083/metrics" + url: "http://localhost:8083/metrics" } ] } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 01bf8a6e..3a414e8a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ grpc_version=1.28.1 jcommander_version=1.78 jetty_version=9.4.22.v20191022 junit_version=5.6.1 -kluent_version=1.60 +kluent_version=1.61 ktor_version=1.3.2 logback_version=1.2.3 logging_version=1.7.9 @@ -14,5 +14,5 @@ protoc_version=3.11.4 serialization_version=0.20.0-1.3.70-eap-274-2 slf4j_version=1.7.28 typesafe_version=1.4.0 -utils_version=5e83440 +utils_version=b107c71 zipkin_version=5.11.2 diff --git a/src/main/java/io/prometheus/package-info.java b/src/main/java/io/prometheus/package-info.java index 6e240d04..5d6461ed 100644 --- a/src/main/java/io/prometheus/package-info.java +++ b/src/main/java/io/prometheus/package-info.java @@ -14,7 +14,7 @@ * limitations under the License. */ -@VersionAnnotation(version = "1.6.4", date = "3/6/20") +@VersionAnnotation(version = "1.6.4", date = "4/29/20") package io.prometheus; import io.prometheus.common.VersionAnnotation; \ No newline at end of file diff --git a/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt b/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt index 0c57aa7f..05354bcd 100644 --- a/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt +++ b/src/main/kotlin/io/prometheus/agent/AgentHttpService.kt @@ -33,6 +33,7 @@ import io.prometheus.common.ScrapeResults import io.prometheus.grpc.ScrapeRequest import mu.KLogging import java.io.IOException +import java.net.URLDecoder import java.util.concurrent.atomic.AtomicReference class AgentHttpService(val agent: Agent) { @@ -41,6 +42,7 @@ class AgentHttpService(val agent: Agent) { ScrapeResults(agentId = request.agentId, scrapeId = request.scrapeId).also { scrapeResults -> val scrapeMsg = AtomicReference("") val path = request.path + val encodedQueryParams = request.encodedQueryParams val pathContext = agent.pathManager[path] if (pathContext == null) { @@ -51,7 +53,10 @@ class AgentHttpService(val agent: Agent) { } else { val requestTimer = if (agent.isMetricsEnabled) agent.startTimer() else null - val url = pathContext.url + val url = pathContext.url + + (if (encodedQueryParams.isNotEmpty()) + "?${URLDecoder.decode(encodedQueryParams, Charsets.UTF_8)}" + else "") logger.debug { "Fetching $pathContext" } // Content is fetched here diff --git a/src/main/kotlin/io/prometheus/common/GrpcObjects.kt b/src/main/kotlin/io/prometheus/common/GrpcObjects.kt index b75b5e63..d2ac33a8 100644 --- a/src/main/kotlin/io/prometheus/common/GrpcObjects.kt +++ b/src/main/kotlin/io/prometheus/common/GrpcObjects.kt @@ -115,6 +115,7 @@ object GrpcObjects { fun newScrapeRequest(agentId: String, scrapeId: Long, path: String, + encodedQueryParams: String, accept: String?, debugEnabled: Boolean): ScrapeRequest { require(agentId.isNotEmpty()) { EMPTY_AGENTID } @@ -122,6 +123,7 @@ object GrpcObjects { builder.agentId = agentId builder.scrapeId = scrapeId builder.path = path + builder.encodedQueryParams = encodedQueryParams builder.debugEnabled = debugEnabled if (!accept.isNullOrBlank()) builder.accept = accept diff --git a/src/main/kotlin/io/prometheus/proxy/ProxyHttpService.kt b/src/main/kotlin/io/prometheus/proxy/ProxyHttpService.kt index 7a20f3a7..704b0e3a 100644 --- a/src/main/kotlin/io/prometheus/proxy/ProxyHttpService.kt +++ b/src/main/kotlin/io/prometheus/proxy/ProxyHttpService.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -@file:Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction") +@file:Suppress("UndocumentedPublicClass", "UndocumentedPublicFunction", "UnstableApiUsage") package io.prometheus.proxy @@ -36,6 +36,7 @@ import io.ktor.features.minimumSize import io.ktor.http.ContentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode +import io.ktor.http.formUrlEncode import io.ktor.http.isSuccess import io.ktor.request.ApplicationRequest import io.ktor.request.header @@ -82,10 +83,15 @@ class ProxyHttpService(private val proxy: Proxy, val httpPort: Int) : GenericIdl call.response.header(HttpHeaders.CacheControl, "must-revalidate,no-cache,no-store") val path = call.request.path().drop(1) - logger.debug { "Servicing request for path: $path" } + val encodedQueryParams = call.request.queryParameters.formUrlEncode() val agentContext = proxy.pathManager[path] val responseResults = ResponseResults() + logger.debug { + "Servicing request for path: $path" + + (if (encodedQueryParams.isNotEmpty()) " with query params $encodedQueryParams" else "") + } + when { !proxy.isRunning -> { logger.error { "Proxy stopped" } @@ -108,7 +114,7 @@ class ProxyHttpService(private val proxy: Proxy, val httpPort: Int) : GenericIdl path == "favicon.ico" -> { //logger.info { "Invalid path request /${path}" } responseResults.apply { - updateMsg = "invalid_request" + updateMsg = "invalid_path" statusCode = HttpStatusCode.NotFound } } @@ -137,7 +143,7 @@ class ProxyHttpService(private val proxy: Proxy, val httpPort: Int) : GenericIdl } else -> { - submitScrapeRequest(path, agentContext, call.request, call.response) + submitScrapeRequest(path, encodedQueryParams, agentContext, call.request, call.response) .also { response -> var status = "/${path} - ${response.updateMsg} - ${response.statusCode}" @@ -204,12 +210,14 @@ class ProxyHttpService(private val proxy: Proxy, val httpPort: Int) : GenericIdl val fetchDuration: Duration) private suspend fun submitScrapeRequest(path: String, + encodedQueryParams: String, agentContext: AgentContext, request: ApplicationRequest, response: ApplicationResponse): ScrapeRequestResponse { val scrapeRequest = ScrapeRequestWrapper(proxy, path, + encodedQueryParams, agentContext, request.header(ACCEPT), proxy.options.debugEnabled) diff --git a/src/main/kotlin/io/prometheus/proxy/ScrapeRequestWrapper.kt b/src/main/kotlin/io/prometheus/proxy/ScrapeRequestWrapper.kt index ecc90868..feaeccad 100644 --- a/src/main/kotlin/io/prometheus/proxy/ScrapeRequestWrapper.kt +++ b/src/main/kotlin/io/prometheus/proxy/ScrapeRequestWrapper.kt @@ -32,6 +32,7 @@ import kotlin.time.TimeSource.Monotonic class ScrapeRequestWrapper(proxy: Proxy, path: String, + encodedQueryParams: String, val agentContext: AgentContext, accept: String?, debugEnabled: Boolean) { @@ -43,6 +44,7 @@ class ScrapeRequestWrapper(proxy: Proxy, val scrapeRequest = newScrapeRequest(agentContext.agentId, SCRAPE_ID_GENERATOR.getAndIncrement(), path, + encodedQueryParams, accept, debugEnabled) diff --git a/src/main/proto/proxy_service.proto b/src/main/proto/proxy_service.proto index 45579704..7b3740b3 100644 --- a/src/main/proto/proxy_service.proto +++ b/src/main/proto/proxy_service.proto @@ -58,6 +58,7 @@ message ScrapeRequest { string path = 3; string accept = 4; bool debug_enabled = 5; + string encodedQueryParams = 6; } message ScrapeResponse {