Skip to content

Commit

Permalink
1.18.0 (#95)
Browse files Browse the repository at this point in the history
* Convert try/catch stmts to runCatching.

* Suppress warnings on functions intended for embedded client usage.

* Update jars:
    Kotlin 1.9.0
    ktor 2.3.1
    gRPC 1.56.1
    Dropwizard 4.2.19

 Update gradle to 8.2.1
  • Loading branch information
pambrose authored Jul 19, 2023
1 parent a162c6f commit 020e566
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 168 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.17.0
VERSION=1.18.0

default: versioncheck

Expand Down Expand Up @@ -68,4 +68,4 @@ refresh:
./gradlew --refresh-dependencies

upgrade-wrapper:
./gradlew wrapper --gradle-version=8.1.1 --distribution-type=bin
./gradlew wrapper --gradle-version=8.2.1 --distribution-type=bin
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ scrape_configs:
The docker images are available via:
```bash
docker pull pambrose/prometheus-proxy:1.17.0
docker pull pambrose/prometheus-agent:1.17.0
docker pull pambrose/prometheus-proxy:1.18.0
docker pull pambrose/prometheus-agent:1.18.0
```

Start a proxy container with:
Expand All @@ -122,15 +122,15 @@ 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.17.0
pambrose/prometheus-proxy:1.18.0
```

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.17.0
pambrose/prometheus-agent:1.18.0
```

Using the config
Expand All @@ -148,7 +148,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.17.0
pambrose/prometheus-agent:1.18.0
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure to use `/app` as the base directory in the
Expand Down Expand Up @@ -264,16 +264,16 @@ Agents connect to a proxy using [gRPC](https://grpc.io). gRPC supports TLS with
necessary certificate and key file paths can be specified via CLI args, environment variables and configuration file
settings.

The gRPC docs describe [how to setup TLS](https://github.com/grpc/grpc-java/tree/master/examples/example-tls).
The gRPC docs describe [how to set up TLS](https://github.com/grpc/grpc-java/tree/master/examples/example-tls).
The [repo](https://github.com/pambrose/prometheus-proxy/tree/master/testing/certs) includes the certificates and keys
necessary to test TLS support.

Running TLS without mutual authentication requires these settingss:
Running TLS without mutual authentication requires these settings:

* `certChainFilePath` and `privateKeyFilePath` on the proxy
* `trustCertCollectionFilePath` on the agent

Running TLS with mutual authentication requires these settingss:
Running TLS with mutual authentication requires these settings:

* `certChainFilePath`, `privateKeyFilePath` and `trustCertCollectionFilePath` on the proxy
* `certChainFilePath`, `privateKeyFilePath` and `trustCertCollectionFilePath` on the agent
Expand All @@ -296,15 +296,15 @@ 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.17.0
pambrose/prometheus-proxy:1.18.0

docker run --rm -p 8083:8083 -p 8093:8093 \
--mount type=bind,source="$(pwd)"/testing/certs,target=/app/testing/certs \
--mount type=bind,source="$(pwd)"/examples/tls-no-mutual-auth.conf,target=/app/tls-no-mutual-auth.conf \
--env AGENT_CONFIG=tls-no-mutual-auth.conf \
--env PROXY_HOSTNAME=mymachine.lan:50440 \
--name docker-agent \
pambrose/prometheus-agent:1.17.0
pambrose/prometheus-agent:1.18.0
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure to use `/app` as the base directory in the
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 \
--env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
--env PROXY_HOSTNAME=mymachine.lan \
pambrose/prometheus-agent:1.17.0
pambrose/prometheus-agent:1.18.0
2 changes: 1 addition & 1 deletion bin/docker-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.17.0
pambrose/prometheus-proxy:1.18.0
57 changes: 29 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ plugins {
id 'idea'
id 'java'
id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version '1.8.21'
id 'org.jetbrains.kotlin.jvm' version '1.9.0'
id 'com.google.protobuf' version '0.9.1' // Keep in sync with grpc
id 'org.jmailen.kotlinter' version "3.13.0"
id "com.github.ben-manes.versions" version '0.46.0'
id "com.github.ben-manes.versions" version '0.47.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.github.gmazzo.buildconfig' version '4.0.4'
id 'org.jetbrains.kotlinx.kover' version '0.6.1'
id 'com.github.gmazzo.buildconfig' version '4.1.2'
id 'org.jetbrains.kotlinx.kover' version '0.7.2'
// Turn these off until jacoco fixes their kotlin 1.5.0 SMAP issue
// id 'jacoco'
// id 'com.github.kt3k.coveralls' version '2.12.0'
}

group = 'io.prometheus'
version = '1.17.0'
version = '1.18.0'

sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

buildConfig {
packageName("io.prometheus")

buildConfigField('String', 'APP_NAME', "\"${project.name}\"")
buildConfigField('String', 'APP_VERSION', "\"${project.version}\"")
buildConfigField('String', 'APP_RELEASE_DATE', "\"05/16/2023\"")
buildConfigField('String', 'APP_RELEASE_DATE', "\"07/19/2023\"")
}

repositories {
Expand Down Expand Up @@ -150,15 +150,17 @@ configurations.all {

//startScripts.enabled = false

task sourcesJar(type: Jar, dependsOn: classes) {
// This is to fix a bizarre gradle error related to duplicate Agent.toString() methods
project.getTasks().getByName("jar").setProperty("duplicatesStrategy", DuplicatesStrategy.INCLUDE);

tasks.register('sourcesJar', Jar) {
dependsOn classes
from sourceSets.main.allSource
archiveClassifier = 'sources'
}

// This is to fix a bizarre gradle error related to duplicate Agent.toString() methods
project.getTasks().getByName("jar").setProperty("duplicatesStrategy", DuplicatesStrategy.INCLUDE);

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
Expand Down Expand Up @@ -219,25 +221,24 @@ task proxyJar(type: Jar, dependsOn: shadowJar) {

compileKotlin.dependsOn ':generateProto'

kotlin {
jvmToolchain(17)
}

compileKotlin {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += ['-Xbackend-threads=8',
"-opt-in=kotlin.time.ExperimentalTime",
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi"]
}
kotlinOptions.freeCompilerArgs += ['-Xbackend-threads=8',
"-opt-in=kotlin.time.ExperimentalTime",
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.coroutines.DelicateCoroutinesApi"]
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += ['-Xbackend-threads=8',
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.coroutines.DelicateCoroutinesApi"]
}
kotlinOptions.freeCompilerArgs += ['-Xbackend-threads=8',
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.coroutines.DelicateCoroutinesApi"]
}

test {
Expand Down
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.17.0'
image: 'pambrose/prometheus-proxy:1.18.0'
ports:
- '8080:8080'
- '8082:8082'
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ org.gradle.parallel=true
org.gradle.caching=true
org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
annotation_version=1.3.2
dropwizard_version=4.2.18
dropwizard_version=4.2.19
gengrpc_version=1.3.0
grpc_version=1.55.1
grpc_version=1.56.1
jcommander_version=1.82
jetty_version=10.0.15
junit_version=5.9.3
kluent_version=1.73
kotlin_version=1.8.21
krotodc_version=1.0.1
ktor_version=2.3.0
logback_version=1.4.7
kotlin_version=1.9.0
krotodc_version=1.0.3
ktor_version=2.3.2
logback_version=1.4.8
logging_version=4.0.0-beta-2
# Keep in sync with grpc
tcnative_version=2.0.59.Final
Expand All @@ -26,5 +26,5 @@ protoc_version=3.22.3
serialization_version=1.5.1
slf4j_version=2.0.7
typesafe_version=1.4.2
utils_version=1.38.0
utils_version=1.39.9
zipkin_version=5.16.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk11
- openjdk17
#before_install:
# - ./custom_setup.sh
#install:
Expand Down
24 changes: 13 additions & 11 deletions src/main/kotlin/io/prometheus/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ class Agent(

while (isRunning) {
try {
runBlocking {
connectToProxy()
runCatching {
runBlocking {
connectToProxy()
}
}.onFailure { e ->
when (e) {
is RequestFailureException -> logger.info { "Disconnected from proxy at $proxyHost after invalid response ${e.message}" }
is StatusRuntimeException -> logger.info { "Disconnected from proxy at $proxyHost" }
is StatusException -> logger.warn { "Cannot connect to proxy at $proxyHost ${e.simpleClassName} ${e.message}" }
// Catch anything else to avoid exiting retry loop
else -> logger.warn { "Throwable caught ${e.simpleClassName} ${e.message}" }
}
}
} catch (e: RequestFailureException) {
logger.info { "Disconnected from proxy at $proxyHost after invalid response ${e.message}" }
} catch (e: StatusRuntimeException) {
logger.info { "Disconnected from proxy at $proxyHost" }
} catch (e: StatusException) {
logger.warn { "Cannot connect to proxy at $proxyHost ${e.simpleClassName} ${e.message}" }
} catch (e: Throwable) {
// Catch anything else to avoid exiting retry loop
logger.warn { "Throwable caught ${e.simpleClassName} ${e.message}" }
} finally {
logger.info { "Waited ${reconnectLimiter.acquire().roundToInt().seconds} to reconnect" }
}
Expand Down Expand Up @@ -288,6 +289,7 @@ class Agent(
Agent(options = AgentOptions(argv, exitOnMissingConfig)) { startSync() }
}

@Suppress("unused")
@JvmStatic
fun startAsyncAgent(
configFilename: String,
Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal class AgentGrpcService(

// If successful, this will create an agentContext on the Proxy and an interceptor will add an agent_id to the headers`
suspend fun connectAgent(transportFilterDisabled: Boolean) =
try {
runCatching {
logger.info { "Connecting to proxy at ${agent.proxyHost} using ${tlsContext.desc()}..." }
if (transportFilterDisabled)
stub.connectAgentWithTransportFilterDisabled(EMPTY_INSTANCE).also { agent.agentId = it.agentId }
Expand All @@ -181,7 +181,7 @@ internal class AgentGrpcService(
logger.info { "Connected to proxy at ${agent.proxyHost} using ${tlsContext.desc()}" }
agent.metrics { connectCount.labels(agent.launchId, "success").inc() }
true
} catch (e: StatusRuntimeException) {
}.getOrElse { e ->
agent.metrics { connectCount.labels(agent.launchId, "failure").inc() }
logger.info { "Cannot connect to proxy at ${agent.proxyHost} using ${tlsContext.desc()} - ${e.simpleClassName}: ${e.message}" }
false
Expand Down Expand Up @@ -253,7 +253,7 @@ internal class AgentGrpcService(
agent.agentId
.also { agentId ->
if (agentId.isNotEmpty())
try {
runCatching {
val request = HeartBeatRequest(agentId).toProto()
stub.sendHeartBeat(request).toDataClass()
.apply {
Expand All @@ -263,8 +263,11 @@ internal class AgentGrpcService(
throw StatusRuntimeException(Status.NOT_FOUND)
}
}
} catch (e: StatusRuntimeException) {
logger.error { "sendHeartBeat() failed ${e.status}" }
}.onFailure { e ->
if (e is StatusRuntimeException)
logger.error { "sendHeartBeat() failed ${e.status}" }
else
logger.error { "sendHeartBeat() failed ${e.message}" }
}
}
}
Expand Down
Loading

0 comments on commit 020e566

Please sign in to comment.