Skip to content

Commit

Permalink
Merge 1.3.8
Browse files Browse the repository at this point in the history
* Kotlin updates per code analysis
* Upgrade gRPC, kotlin, guava, brave, okhttp, and zipkin jars
  • Loading branch information
pambrose authored Dec 9, 2018
1 parent 247405c commit 6ae5f91
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.3.7
VERSION=1.3.8

default: build

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ scrape_configs:
The docker images are available via:
```bash
$ docker pull pambrose/prometheus-proxy:1.3.7
$ docker pull pambrose/prometheus-agent:1.3.7
$ docker pull pambrose/prometheus-proxy:1.3.8
$ docker pull pambrose/prometheus-agent:1.3.8
```

Start the proxy and an agent in separate shells on your local machine:
Expand All @@ -96,14 +96,14 @@ Start the proxy and an agent in separate shells on your local machine:
$ docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \
-e HOSTNAME=${HOSTNAME} \
-e METRICS_ENABLED=true \
pambrose/prometheus-proxy:1.3.7
pambrose/prometheus-proxy:1.3.8
```

```bash
$ docker run --rm -p 8083:8083 -p 8093:8093 \
-e HOSTNAME=${HOSTNAME} \
-e AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-agent:1.3.7
pambrose/prometheus-agent:1.3.8
```

Using the config file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf),
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
docker run --rm -p 8083:8083 -p 8093:8093 \
-e HOSTNAME=${HOSTNAME} \
-e AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-agent:1.3.7
pambrose/prometheus-agent:1.3.8
2 changes: 1 addition & 1 deletion bin/docker-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \
-e HOSTNAME=${HOSTNAME} \
-e PROXY_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-proxy:1.3.7
pambrose/prometheus-proxy:1.3.8
2 changes: 1 addition & 1 deletion docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ upload the *target/distro/prometheus-proxy.jar* and *target/distro/prometheus-a
11) Build and push docker images with: `make docker-build docker-push`

12) Update the *prometheus-proxy* and *prometheus-agent* repository descriptions
on [Docker hub](https://hub.docker.com) with the latest version of *README.md*.
on [Docker hub](https://hub.docker.com) with the latest `~~~~**_****_**~~~~`version of *README.md*.
2 changes: 1 addition & 1 deletion etc/compose/proxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
prometheus-proxy:
autoredeploy: true
image: 'pambrose/prometheus-proxy:1.3.7'
image: 'pambrose/prometheus-proxy:1.3.8'
ports:
- '8080:8080'
- '8082:8082'
Expand Down
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@

<groupId>io.prometheus</groupId>
<artifactId>prometheus-proxy</artifactId>
<version>1.3.7-SNAPSHOT</version>
<version>1.3.8-SNAPSHOT</version>

<properties>
<kotlin.version>1.2.70</kotlin.version>
<kotlin.version>1.3.11</kotlin.version>

<prometheus.version>0.5.0</prometheus.version>
<prometheus.version>0.6.0</prometheus.version>
<jcommander.version>1.72</jcommander.version>
<config.version>1.3.3</config.version>
<guava.version>20.0</guava.version>
<guava.version>26.0-android</guava.version>
<metrics.version>4.1.0-rc2</metrics.version>

<grpc.version>1.15.0</grpc.version>
<grpc.version>1.17.1</grpc.version>
<grpc.plugin.version>1.11.0</grpc.plugin.version>
<grpc.contrib.version>0.8.0</grpc.contrib.version>
<okhttp.version>3.11.0</okhttp.version>
<grpc.contrib.version>0.8.1</grpc.contrib.version>
<okhttp.version>3.12.0</okhttp.version>
<protobuf.version>3.5.1</protobuf.version>
<protobuf.plugin.version>0.5.1</protobuf.plugin.version>

<spark.version>2.8.0</spark.version>
<jetty.version>9.4.12.v20180830</jetty.version>

<brave.version>5.3.3</brave.version>
<zipkin-sender.version>2.7.8</zipkin-sender.version>
<brave.version>5.5.2</brave.version>
<zipkin-sender.version>2.7.13</zipkin-sender.version>

<logback.version>1.2.3</logback.version>
<slf4j.version>1.7.25</slf4j.version>
<kotlin.logging.version>1.6.10</kotlin.logging.version>
<kotlin.logging.version>1.6.22</kotlin.logging.version>

<junit.version>4.12</junit.version>
<assertj.version>3.11.1</assertj.version>
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/io/prometheus/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,41 @@ import io.grpc.ClientInterceptors.intercept
import io.grpc.ManagedChannel
import io.grpc.Status
import io.grpc.StatusRuntimeException
import io.prometheus.agent.*
import io.prometheus.common.*
import io.prometheus.agent.AgentClientInterceptor
import io.prometheus.agent.AgentMetrics
import io.prometheus.agent.AgentOptions
import io.prometheus.agent.PathContext
import io.prometheus.agent.RequestFailureException
import io.prometheus.common.AdminConfig.Companion.newAdminConfig
import io.prometheus.common.ConfigVals
import io.prometheus.common.GenericService
import io.prometheus.common.InstrumentedThreadFactory
import io.prometheus.common.MetricsConfig.Companion.newMetricsConfig
import io.prometheus.common.ZipkinConfig.Companion.newZipkinConfig
import io.prometheus.common.getBanner
import io.prometheus.common.getVersionDesc
import io.prometheus.common.localHostName
import io.prometheus.common.newQueueHealthCheck
import io.prometheus.common.sleepForMillis
import io.prometheus.common.toMillis
import io.prometheus.delegate.AtomicDelegates.atomicLong
import io.prometheus.delegate.AtomicDelegates.nonNullableReference
import io.prometheus.dsl.GrpcDsl.channel
import io.prometheus.dsl.GrpcDsl.streamObserver
import io.prometheus.dsl.GuavaDsl.toStringElements
import io.prometheus.dsl.ThreadDsl.threadFactory
import io.prometheus.grpc.*
import io.prometheus.grpc.ProxyServiceGrpc.*
import io.prometheus.grpc.AgentInfo
import io.prometheus.grpc.HeartBeatRequest
import io.prometheus.grpc.PathMapSizeRequest
import io.prometheus.grpc.ProxyServiceGrpc.ProxyServiceBlockingStub
import io.prometheus.grpc.ProxyServiceGrpc.ProxyServiceStub
import io.prometheus.grpc.ProxyServiceGrpc.newBlockingStub
import io.prometheus.grpc.ProxyServiceGrpc.newStub
import io.prometheus.grpc.RegisterAgentRequest
import io.prometheus.grpc.RegisterPathRequest
import io.prometheus.grpc.ScrapeRequest
import io.prometheus.grpc.ScrapeResponse
import io.prometheus.grpc.UnregisterPathRequest
import mu.KLogging
import okhttp3.OkHttpClient
import java.io.IOException
Expand Down Expand Up @@ -98,6 +120,7 @@ class Agent(options: AgentOptions,

private val pathConfigs =
configVals.pathConfigs
.asSequence()
.map { mapOf("name" to it.name, "path" to it.path, "url" to it.url) }
.onEach { logger.info { "Proxy path /${it["path"]} will be assigned to ${it["url"]}" } }
.toList()
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/io/prometheus/Proxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@ package io.prometheus
import com.codahale.metrics.health.HealthCheck
import com.google.common.base.Joiner
import io.grpc.Attributes
import io.prometheus.common.*
import io.prometheus.common.AdminConfig.Companion.newAdminConfig
import io.prometheus.common.ConfigVals
import io.prometheus.common.GenericService
import io.prometheus.common.MetricsConfig.Companion.newMetricsConfig
import io.prometheus.common.ZipkinConfig.Companion.newZipkinConfig
import io.prometheus.common.getBanner
import io.prometheus.common.getVersionDesc
import io.prometheus.common.newMapHealthCheck
import io.prometheus.common.sleepForMillis
import io.prometheus.dsl.GuavaDsl.toStringElements
import io.prometheus.dsl.MetricsDsl.healthCheck
import io.prometheus.proxy.*
import io.prometheus.proxy.AgentContextCleanupService
import io.prometheus.proxy.AgentContextManager
import io.prometheus.proxy.PathManager
import io.prometheus.proxy.ProxyGrpcService.Companion.newProxyGrpcService
import io.prometheus.proxy.ProxyHttpService
import io.prometheus.proxy.ProxyMetrics
import io.prometheus.proxy.ProxyOptions
import io.prometheus.proxy.ScrapeRequestManager
import mu.KLogging
import kotlin.properties.Delegates

Expand Down Expand Up @@ -110,6 +121,7 @@ class Proxy(options: ProxyOptions,
agentContextManager
.agentContextMap
.entries
.asSequence()
.filter { it.value.scrapeRequestQueueSize >= unhealthySize }
.map { "${it.value} ${it.value.scrapeRequestQueueSize}" }
.toList()
Expand Down Expand Up @@ -147,7 +159,7 @@ class Proxy(options: ProxyOptions,

companion object : KLogging() {
const val AGENT_ID = "agent-id"
val ATTRIB_AGENT_ID: Attributes.Key<String> = Attributes.Key.of(AGENT_ID)
val ATTRIB_AGENT_ID: Attributes.Key<String> = Attributes.Key.create(AGENT_ID)

@JvmStatic
fun main(argv: Array<String>) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/prometheus/common/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ fun getBanner(filename: String, logger: Logger) =
var first = -1
var last = -1
var lineNum = 0
lines.forEach {
if (it.trim { it <= ' ' }.isNotEmpty()) {
lines.forEach { arg1 ->
if (arg1.trim { arg2 -> arg2 <= ' ' }.isNotEmpty()) {
if (first == -1)
first = lineNum
last = lineNum
Expand All @@ -62,11 +62,12 @@ fun getBanner(filename: String, logger: Logger) =
lineNum = 0

val vals = lines
.asSequence()
.filter {
val currLine = lineNum++
currLine in first..last
}
.map { " $it" }
.map { arg -> " $arg" }
.toList()

val noNulls = Joiner.on("\n").skipNulls().join(vals)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/prometheus/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

@VersionAnnotation(version = "1.3.7", date = "9/18/18")
@VersionAnnotation(version = "1.3.8", date = "12/08/18")
package io.prometheus;

import io.prometheus.common.VersionAnnotation;
21 changes: 17 additions & 4 deletions src/main/java/io/prometheus/proxy/ProxyServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ import io.grpc.StatusRuntimeException
import io.grpc.stub.StreamObserver
import io.prometheus.Proxy
import io.prometheus.dsl.GrpcDsl.streamObserver
import io.prometheus.grpc.*
import io.prometheus.grpc.AgentInfo
import io.prometheus.grpc.HeartBeatRequest
import io.prometheus.grpc.HeartBeatResponse
import io.prometheus.grpc.PathMapSizeRequest
import io.prometheus.grpc.PathMapSizeResponse
import io.prometheus.grpc.ProxyServiceGrpc
import io.prometheus.grpc.RegisterAgentRequest
import io.prometheus.grpc.RegisterAgentResponse
import io.prometheus.grpc.RegisterPathRequest
import io.prometheus.grpc.RegisterPathResponse
import io.prometheus.grpc.ScrapeRequest
import io.prometheus.grpc.ScrapeResponse
import io.prometheus.grpc.UnregisterPathRequest
import io.prometheus.grpc.UnregisterPathResponse
import mu.KLogging
import java.util.concurrent.atomic.AtomicLong

Expand Down Expand Up @@ -179,9 +192,9 @@ internal class ProxyServiceImpl(private val proxy: Proxy) : ProxyServiceGrpc.Pro

onError {
Status.fromThrowable(it)
.let {
if (it !== Status.CANCELLED)
logger.info { "Error in writeResponsesToProxy(): $it" }
.let { arg ->
if (arg !== Status.CANCELLED)
logger.info { "Error in writeResponsesToProxy(): $arg" }
}

try {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/io/prometheus/proxy/ProxyTransportFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import mu.KLogging
class ProxyTransportFilter(private val proxy: Proxy) : ServerTransportFilter() {

private fun getRemoteAddr(attributes: Attributes) =
attributes.keys()
.first { "remote-addr" == it.toString() }
?.let {
attributes.get(it)?.toString() ?: "Unknown"
} ?: "Unknown"
attributes.get(REMOTE_ADDR_KEY)?.toString() ?: "Unknown"

override fun transportReady(attributes: Attributes): Attributes {
val agentContext = AgentContext(proxy, getRemoteAddr(attributes))
Expand All @@ -55,5 +51,7 @@ class ProxyTransportFilter(private val proxy: Proxy) : ServerTransportFilter() {
super.transportTerminated(attributes)
}

companion object : KLogging()
companion object : KLogging() {
val REMOTE_ADDR_KEY: Attributes.Key<String> = Attributes.Key.create("remote-addr")
}
}
49 changes: 24 additions & 25 deletions src/test/java/io/prometheus/CommonTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,21 @@ object CommonTests : KLogging() {
.forEach {
TestConstants
.EXECUTOR_SERVICE
.submit(
{
val path = "test-${cnt.getAndIncrement()}"

synchronized(paths) {
paths += path
}

try {
val url = "http://localhost:$PROXY_PORT/$path"
agent.registerPath(path, url)
latch1.countDown()
} catch (e: RequestFailureException) {
e.printStackTrace()
}
})
.submit {
val path = "test-${cnt.getAndIncrement()}"

synchronized(paths) {
paths += path
}

try {
val url = "http://localhost:$PROXY_PORT/$path"
agent.registerPath(path, url)
latch1.countDown()
} catch (e: RequestFailureException) {
e.printStackTrace()
}
}
}

assertThat(latch1.await(1, MINUTES)).isTrue()
Expand All @@ -103,14 +102,14 @@ object CommonTests : KLogging() {
paths.forEach {
TestConstants
.EXECUTOR_SERVICE
.submit({
try {
agent.unregisterPath(it)
latch2.countDown()
} catch (e: RequestFailureException) {
e.printStackTrace()
}
})
.submit {
try {
agent.unregisterPath(it)
latch2.countDown()
} catch (e: RequestFailureException) {
e.printStackTrace()
}
}
}

// Wait for all unregistrations to complete
Expand Down Expand Up @@ -176,7 +175,7 @@ object CommonTests : KLogging() {
val port = startingPort + it
httpServers +=
httpServer {
initExceptionHandler { sparkExceptionHandler(it, port) }
initExceptionHandler { arg -> sparkExceptionHandler(arg, port) }
port(port)
threadPool(30, 10, 1000)
get("/agent-$it") { _, res ->
Expand Down

0 comments on commit 6ae5f91

Please sign in to comment.