Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
* Migrate to new common-utils
  • Loading branch information
pambrose authored Nov 15, 2019
1 parent 6c25766 commit 6991e19
Show file tree
Hide file tree
Showing 42 changed files with 147 additions and 619 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: java

jdk:
# - oraclejdk11
#- oraclejdk11
- openjdk11

after_success:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
VERSION=1.4.0
VERSION=1.4.1

default: compile

clean:
./gradlew clean

compile:
./gradlew build -x test
./gradlew build -xtest

jars:
./gradlew agentJar proxyJar
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://travis-ci.org/pambrose/prometheus-proxy.svg?branch=master)](https://travis-ci.org/pambrose/prometheus-proxy)
[![Coverage Status](https://coveralls.io/repos/github/pambrose/prometheus-proxy/badge.svg?branch=master)](https://coveralls.io/github/pambrose/prometheus-proxy?branch=master)
[![codebeat badge](https://codebeat.co/badges/8dbe1dc6-628e-44a4-99f9-d468831ff0cc)](https://codebeat.co/projects/github-com-pambrose-prometheus-proxy-master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/58aaa4a43d2a482c8f460d852302f997)](https://www.codacy.com/app/pambrose/prometheus-proxy?utm_source=github.com&utm_medium=referral&utm_content=pambrose/prometheus-proxy&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/422df508473443df9fbd8ea00fdee973)](https://www.codacy.com/app/pambrose/prometheus-proxy?utm_source=github.com&utm_medium=referral&utm_content=pambrose/prometheus-proxy&utm_campaign=Badge_Grade)
[![Code Climate](https://codeclimate.com/github/pambrose/prometheus-proxy/badges/gpa.svg)](https://codeclimate.com/github/pambrose/prometheus-proxy)
[![Kotlin](https://img.shields.io/badge/%20language-Kotlin-red.svg)](https://kotlinlang.org/)

Expand Down Expand Up @@ -97,8 +97,8 @@ scrape_configs:
The docker images are available via:
```bash
docker pull pambrose/prometheus-proxy:1.4.0
docker pull pambrose/prometheus-agent:1.4.0
docker pull pambrose/prometheus-proxy:1.4.1
docker pull pambrose/prometheus-agent:1.4.1
```

Start the proxy and an agent in separate shells on your local machine:
Expand All @@ -107,14 +107,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.4.0
pambrose/prometheus-proxy:1.4.1
```

```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.4.0
pambrose/prometheus-agent:1.4.1
```

If you want to be able to externalize your `agent` config file on your local machine (or VM) file system (instead of the above HTTP served config file), you'll need to add the Docker `volume` definition to the command:
Expand All @@ -124,7 +124,7 @@ docker run --rm -p 8083:8083 -p 8093:8093 \
-v ${PWD}/prom-agent.conf:/prom-agent.conf \
-e HOSTNAME=${HOSTNAME} \
-e AGENT_CONFIG=/prom-agent.conf \
pambrose/prometheus-agent:1.4.0
pambrose/prometheus-agent:1.4.1
```

The above assumes that you have the file `prom-agent.conf` in the current directory from which you're running the `docker` command.
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.4.0
pambrose/prometheus-agent:1.4.1
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.4.0
pambrose/prometheus-proxy:1.4.1
30 changes: 21 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ plugins {
}

group = 'io.prometheus'
version = '1.4.0-SNAPSHOT'
sourceCompatibility = '1.8'
version = '1.4.1-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

def kotlinVersion = '1.3.50'
def serializationVersion = '0.13.0'
def coroutinesVersion = '1.3.2'
def utilsVersion = '1.0.5'
def utilsVersion = '1.1.2'

def grpcVersion = '1.25.0'
def protocVersion = '3.10.0'

def ktorVersion = '1.2.4'
def jettyVersion = '9.4.22.v20191022'
def annotationVersion = '1.3.2'
def prometheusVersion = '0.8.0'
def loggingVersion = '1.7.6'
def sparkVersion = '2.9.1'
def dropwizardVersion = '4.1.1'
def zipkinVersion = '5.9.0'
def zipkenSenderVersion = '2.11.0'
Expand All @@ -37,7 +39,7 @@ def slf4jVersion = '1.7.28'
def junitVersion = '5.5.2'

repositories {
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url = "https://kotlin.bintray.com/kotlinx" }
maven { url = 'https://dl.bintray.com/kotlin/kotlin-dev/' }
maven { url = 'https://maven-central.storage-download.googleapis.com/repos/central/data/' }
mavenCentral()
Expand All @@ -55,24 +57,31 @@ dependencies {

implementation "io.grpc:grpc-all:${grpcVersion}"

implementation "com.github.pambrose:common-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:core-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:dropwizard-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:guava-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:grpc-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:ktor-client-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:jetty-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:prometheus-utils:${utilsVersion}"
implementation "com.github.pambrose.common-utils:zipkin-utils:${utilsVersion}"

implementation "javax.annotation:javax.annotation-api:${annotationVersion}"
implementation "com.beust:jcommander:${jcommanderVersion}"
implementation "com.typesafe:config:${tscfgVersion}"
implementation "com.sparkjava:spark-core:${sparkVersion}"
implementation "com.salesforce.servicelibs:grpc-contrib:${contribVersion}"

implementation "io.prometheus:simpleclient:${prometheusVersion}"
implementation "io.prometheus:simpleclient_hotspot:${prometheusVersion}"
implementation "io.prometheus:simpleclient_servlet:${prometheusVersion}"
implementation "io.prometheus:simpleclient_jetty:${prometheusVersion}"

implementation "io.ktor:ktor-server-core:${ktorVersion}"
implementation "io.ktor:ktor-server-cio:${ktorVersion}"
implementation "io.ktor:ktor-client-core:${ktorVersion}"
implementation "io.ktor:ktor-client-cio:${ktorVersion}"

implementation "org.eclipse.jetty:jetty-server:${jettyVersion}"
implementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}"

implementation "io.dropwizard.metrics:metrics-core:${dropwizardVersion}"
implementation "io.dropwizard.metrics:metrics-healthchecks:${dropwizardVersion}"
Expand All @@ -87,7 +96,6 @@ dependencies {
implementation "org.slf4j:jul-to-slf4j:${slf4jVersion}"
implementation "io.github.microutils:kotlin-logging:${loggingVersion}"

//testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}"
testImplementation "org.amshove.kluent:kluent:${kluentVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
Expand All @@ -107,6 +115,10 @@ protobuf {
}
}

configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

sourceSets {
main {
java {
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.4.0'
image: 'pambrose/prometheus-proxy:1.4.1'
ports:
- '8080:8080'
- '8082:8082'
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.4.0", date = "11/12/19")
@VersionAnnotation(version = "1.4.1", date = "11/14/19")
package io.prometheus;

import io.prometheus.common.VersionAnnotation;
21 changes: 11 additions & 10 deletions src/main/kotlin/io/prometheus/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

package io.prometheus

import com.github.pambrose.common.delegate.AtomicDelegates.nonNullableReference
import com.github.pambrose.common.dsl.GrpcDsl.streamObserver
import com.github.pambrose.common.dsl.GuavaDsl.toStringElements
import com.github.pambrose.common.dsl.KtorDsl.get
import com.github.pambrose.common.dsl.KtorDsl.http
import com.github.pambrose.common.util.getBanner
import com.google.common.net.HttpHeaders
import com.google.common.net.HttpHeaders.CONTENT_TYPE
import com.google.common.util.concurrent.RateLimiter
import com.google.protobuf.Empty
import com.sudothought.common.delegate.AtomicDelegates.nonNullableReference
import com.sudothought.common.dsl.GuavaDsl.toStringElements
import com.sudothought.common.util.getBanner
import io.grpc.Status
import io.grpc.StatusRuntimeException
import io.ktor.client.request.HttpRequestBuilder
Expand Down Expand Up @@ -53,9 +56,6 @@ import io.prometheus.common.localHostName
import io.prometheus.common.newBacklogHealthCheck
import io.prometheus.common.simpleClassName
import io.prometheus.common.thenElse
import io.prometheus.dsl.GrpcDsl.streamObserver
import io.prometheus.dsl.KtorDsl.get
import io.prometheus.dsl.KtorDsl.http
import io.prometheus.grpc.ScrapeRequest
import io.prometheus.grpc.ScrapeResponse
import kotlinx.coroutines.Dispatchers
Expand All @@ -69,6 +69,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import kotlin.properties.Delegates.notNull
import kotlin.time.ClockMark
import kotlin.time.Duration
import kotlin.time.MonoClock
import kotlin.time.milliseconds
Expand All @@ -94,10 +95,10 @@ class Agent(options: AgentOptions,
RateLimiter.create(1.0 / configVals.reconectPauseSecs).apply { acquire() } // Prime the limiter

private val clock = MonoClock
private var lastMsgSentMark by nonNullableReference(clock.markNow())
private var metrics by notNull<AgentMetrics>()
private var lastMsgSentMark: ClockMark by nonNullableReference(clock.markNow())
private var metrics: AgentMetrics by notNull()

var agentId by nonNullableReference("")
var agentId: String by nonNullableReference("")

val scrapeRequestBacklogSize = AtomicInteger(0)
val pathManager = AgentPathManager(this)
Expand Down Expand Up @@ -329,7 +330,7 @@ class Agent(options: AgentOptions,
})

for (scrapeRequestAction in scrapeRequestChannel) {
val scrapeResponse = scrapeRequestAction.invoke()
val scrapeResponse = scrapeRequestAction()
observer.onNext(scrapeResponse)
markMsgSent()
scrapeRequestBacklogSize.decrementAndGet()
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/io/prometheus/Proxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
package io.prometheus

import com.codahale.metrics.health.HealthCheck
import com.github.pambrose.common.dsl.GuavaDsl.toStringElements
import com.github.pambrose.common.dsl.MetricsDsl.healthCheck
import com.github.pambrose.common.util.getBanner
import com.google.common.base.Joiner
import com.sudothought.common.dsl.GuavaDsl.toStringElements
import com.sudothought.common.util.getBanner
import io.grpc.Attributes
import io.prometheus.common.AdminConfig.Companion.newAdminConfig
import io.prometheus.common.ConfigVals
Expand All @@ -31,7 +32,6 @@ import io.prometheus.common.ZipkinConfig.Companion.newZipkinConfig
import io.prometheus.common.delay
import io.prometheus.common.getVersionDesc
import io.prometheus.common.newMapHealthCheck
import io.prometheus.dsl.MetricsDsl.healthCheck
import io.prometheus.proxy.AgentContextCleanupService
import io.prometheus.proxy.AgentContextManager
import io.prometheus.proxy.ProxyGrpcService
Expand Down Expand Up @@ -63,7 +63,7 @@ class Proxy(options: ProxyOptions,
val pathManager = ProxyPathManager(isTestMode)
val scrapeRequestManager = ScrapeRequestManager()
val agentContextManager = AgentContextManager()
var metrics by notNull<ProxyMetrics>()
var metrics: ProxyMetrics by notNull()

private val httpService = ProxyHttpService(this, proxyHttpPort)
private val grpcService =
Expand All @@ -72,7 +72,7 @@ class Proxy(options: ProxyOptions,
else
ProxyGrpcService(this, inProcessName = inProcessServerName)

private var agentCleanupService by notNull<AgentContextCleanupService>()
private var agentCleanupService: AgentContextCleanupService by notNull()

init {
if (isMetricsEnabled)
Expand Down
29 changes: 13 additions & 16 deletions src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ package io.prometheus.agent

import brave.Tracing
import brave.grpc.GrpcTracing
import com.sudothought.common.delegate.AtomicDelegates.nonNullableReference
import com.github.pambrose.common.delegate.AtomicDelegates.nonNullableReference
import com.github.pambrose.common.dsl.GrpcDsl.channel
import io.grpc.ClientInterceptor
import io.grpc.ClientInterceptors
import io.grpc.ManagedChannel
import io.prometheus.Agent
import io.prometheus.dsl.GrpcDsl.channel
import io.prometheus.grpc.ProxyServiceGrpc
import io.prometheus.grpc.ProxyServiceGrpc.ProxyServiceBlockingStub
import io.prometheus.grpc.ProxyServiceGrpc.ProxyServiceStub
Expand All @@ -38,11 +38,11 @@ class AgentGrpcService(private val agent: Agent,
private val inProcessServerName: String) {
private var grpcStarted = AtomicBoolean(false)

var channel by nonNullableReference<ManagedChannel>()
var grpcTracing by notNull<GrpcTracing>()
var blockingStub by nonNullableReference<ProxyServiceBlockingStub>()
var asyncStub by nonNullableReference<ProxyServiceStub>()
private var tracing by notNull<Tracing>()
private var tracing: Tracing by notNull()
var channel: ManagedChannel by nonNullableReference()
private var grpcTracing: GrpcTracing by notNull()
var blockingStub: ProxyServiceBlockingStub by nonNullableReference()
var asyncStub: ProxyServiceStub by nonNullableReference()

val hostName: String
val port: Int
Expand All @@ -65,33 +65,30 @@ class AgentGrpcService(private val agent: Agent,
resetGrpcStubs()
}

val isGrpcStarted
get() = grpcStarted.get()

fun shutDown() {
if (agent.isZipkinEnabled)
tracing.close()
if (isGrpcStarted)
if (grpcStarted.get())
channel.shutdownNow()
}

fun resetGrpcStubs() {
logger.info { "Creating gRPC stubs" }

if (isGrpcStarted)
if (grpcStarted.get())
shutDown()
else
grpcStarted.set(true)

channel =
channel(inProcessServerName = inProcessServerName, hostName = hostName, port = port) {
channel(inProcessServerName = inProcessServerName,
hostName = hostName,
port = port) {
if (agent.isZipkinEnabled)
intercept(grpcTracing.newClientInterceptor())
usePlaintext()
}

val interceptors = listOf<ClientInterceptor>(AgentClientInterceptor(agent))

val interceptors: List<ClientInterceptor> = listOf(AgentClientInterceptor(agent))
blockingStub = ProxyServiceGrpc.newBlockingStub(ClientInterceptors.intercept(channel, interceptors))
asyncStub = ProxyServiceGrpc.newStub(ClientInterceptors.intercept(channel, interceptors))
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/io/prometheus/agent/AgentMetrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package io.prometheus.agent

import com.github.pambrose.common.dsl.PrometheusDsl.counter
import com.github.pambrose.common.dsl.PrometheusDsl.gauge
import com.github.pambrose.common.dsl.PrometheusDsl.summary
import com.github.pambrose.common.metrics.SamplerGaugeCollector
import io.prometheus.Agent
import io.prometheus.client.Counter
import io.prometheus.client.Summary
import io.prometheus.common.SamplerGaugeCollector
import io.prometheus.dsl.PrometheusDsl.counter
import io.prometheus.dsl.PrometheusDsl.gauge
import io.prometheus.dsl.PrometheusDsl.summary

class AgentMetrics(agent: Agent) {

Expand Down
Loading

0 comments on commit 6991e19

Please sign in to comment.