Skip to content

Commit

Permalink
1.4.5
Browse files Browse the repository at this point in the history
* Add debug servlet
  • Loading branch information
pambrose authored Nov 22, 2019
1 parent 0cb7430 commit 4485c1f
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.4.4
VERSION=1.4.5

default: compile

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ scrape_configs:
The docker images are available via:
```bash
docker pull pambrose/prometheus-proxy:1.4.4
docker pull pambrose/prometheus-agent:1.4.4
docker pull pambrose/prometheus-proxy:1.4.5
docker pull pambrose/prometheus-agent:1.4.5
```

Start the proxy and an agent in separate shells on your local machine:
Expand All @@ -107,13 +107,13 @@ 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 ADMIN_ENABLED=true \
-e METRICS_ENABLED=true \
pambrose/prometheus-proxy:1.4.4
pambrose/prometheus-proxy:1.4.5
```

```bash
docker run --rm -p 8083:8083 -p 8093:8093 \
-e AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-agent:1.4.4
pambrose/prometheus-agent:1.4.5
```

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 @@ -122,7 +122,7 @@ If you want to be able to externalize your `agent` config file on your local mac
docker run --rm -p 8083:8083 -p 8093:8093 \
-v ${PWD}/prom-agent.conf:/prom-agent.conf \
-e AGENT_CONFIG=/prom-agent.conf \
pambrose/prometheus-agent:1.4.4
pambrose/prometheus-agent:1.4.5
```

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.4
pambrose/prometheus-agent:1.4.5
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.4
pambrose/prometheus-proxy:1.4.5
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ plugins {
}

group = 'io.prometheus'
version = '1.4.4'
version = '1.4.5'

sourceCompatibility = 1.8
targetCompatibility = 1.8

def kotlinVersion = '1.3.60'
def serializationVersion = '0.13.0'
def coroutinesVersion = '1.3.2'
def utilsVersion = '1.1.7'
def utilsVersion = '1.1.8'

def grpcVersion = '1.25.0'
def protocVersion = '3.10.0'
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.4'
image: 'pambrose/prometheus-proxy:1.4.5'
ports:
- '8080:8080'
- '8082:8082'
Expand Down
1 change: 1 addition & 0 deletions etc/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ proxy {
healthCheckPath = "healthcheck" // HealthCheck servlet path
threadDumpPath = "threaddump" // ThreadDump servlet path
debugEnabled = false // Enable proxy debug servlet on admin port
recentRequestsQueueSize = 50 // Size of queue for recent activities on debug servlet
}

metrics {
Expand Down
48 changes: 26 additions & 22 deletions src/main/java/io/prometheus/common/ConfigVals.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated by tscfg 0.9.94 on Tue Nov 19 19:09:31 PST 2019
// generated by tscfg 0.9.94 on Thu Nov 21 21:55:11 PST 2019
// source: etc/config/config.conf

package io.prometheus.common;
Expand All @@ -21,6 +21,7 @@ public static class Agent {
public final java.lang.String name;
public final java.util.List<Agent.PathConfigs$Elm> pathConfigs;
public final Agent.Proxy proxy;

public Agent(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgValidator $tsCfgValidator) {
this.admin = c.hasPathOrNull("admin") ? new Agent.Admin(c.getConfig("admin"), parentPath + "admin.", $tsCfgValidator) : new Agent.Admin(com.typesafe.config.ConfigFactory.parseString("admin{}"), parentPath + "admin.", $tsCfgValidator);
this.internal = c.hasPathOrNull("internal") ? new Agent.Internal(c.getConfig("internal"), parentPath + "internal.", $tsCfgValidator) : new Agent.Internal(com.typesafe.config.ConfigFactory.parseString("internal{}"), parentPath + "internal.", $tsCfgValidator);
Expand Down Expand Up @@ -65,15 +66,6 @@ public static class Internal {
public final int reconnectPauseSecs;
public final int scrapeRequestBacklogUnhealthySize;
public final Internal.Zipkin zipkin;
public Internal(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgValidator $tsCfgValidator) {
this.heartbeatCheckPauseMillis = c.hasPathOrNull("heartbeatCheckPauseMillis") ? c.getInt("heartbeatCheckPauseMillis") : 500;
this.heartbeatEnabled = !c.hasPathOrNull("heartbeatEnabled") || c.getBoolean("heartbeatEnabled");
this.heartbeatMaxInactivitySecs = c.hasPathOrNull("heartbeatMaxInactivitySecs") ? c.getInt("heartbeatMaxInactivitySecs") : 5;
this.reconnectPauseSecs = c.hasPathOrNull("reconnectPauseSecs") ? c.getInt("reconnectPauseSecs") : 3;
this.scrapeRequestBacklogUnhealthySize = c.hasPathOrNull("scrapeRequestBacklogUnhealthySize") ? c.getInt("scrapeRequestBacklogUnhealthySize") : 25;
this.zipkin = c.hasPathOrNull("zipkin") ? new Internal.Zipkin(c.getConfig("zipkin"), parentPath + "zipkin.", $tsCfgValidator) : new Internal.Zipkin(com.typesafe.config.ConfigFactory.parseString("zipkin{}"), parentPath + "zipkin.", $tsCfgValidator);
}

public static class Zipkin {
public final boolean enabled;
public final boolean grpcReportingEnabled;
Expand All @@ -91,6 +83,15 @@ public Zipkin(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgV
this.serviceName = c.hasPathOrNull("serviceName") ? c.getString("serviceName") : "prometheus-agent";
}
}

public Internal(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgValidator $tsCfgValidator) {
this.heartbeatCheckPauseMillis = c.hasPathOrNull("heartbeatCheckPauseMillis") ? c.getInt("heartbeatCheckPauseMillis") : 500;
this.heartbeatEnabled = !c.hasPathOrNull("heartbeatEnabled") || c.getBoolean("heartbeatEnabled");
this.heartbeatMaxInactivitySecs = c.hasPathOrNull("heartbeatMaxInactivitySecs") ? c.getInt("heartbeatMaxInactivitySecs") : 5;
this.reconnectPauseSecs = c.hasPathOrNull("reconnectPauseSecs") ? c.getInt("reconnectPauseSecs") : 3;
this.scrapeRequestBacklogUnhealthySize = c.hasPathOrNull("scrapeRequestBacklogUnhealthySize") ? c.getInt("scrapeRequestBacklogUnhealthySize") : 25;
this.zipkin = c.hasPathOrNull("zipkin") ? new Internal.Zipkin(c.getConfig("zipkin"), parentPath + "zipkin.", $tsCfgValidator) : new Internal.Zipkin(com.typesafe.config.ConfigFactory.parseString("zipkin{}"), parentPath + "zipkin.", $tsCfgValidator);
}
}

public static class Metrics {
Expand Down Expand Up @@ -138,6 +139,7 @@ public static class PathConfigs$Elm {
this.path = $_reqStr(parentPath, c, "path", $tsCfgValidator);
this.url = $_reqStr(parentPath, c, "url", $tsCfgValidator);
}

private static java.lang.String $_reqStr(java.lang.String parentPath, com.typesafe.config.Config c, java.lang.String path, $TsCfgValidator $tsCfgValidator) {
if (c == null) return null;
try {
Expand Down Expand Up @@ -181,6 +183,7 @@ public static class Admin2 {
public final java.lang.String healthCheckPath;
public final java.lang.String pingPath;
public final int port;
public final int recentRequestsQueueSize;
public final java.lang.String threadDumpPath;
public final java.lang.String versionPath;

Expand All @@ -190,6 +193,7 @@ public Admin2(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgV
this.healthCheckPath = c.hasPathOrNull("healthCheckPath") ? c.getString("healthCheckPath") : "healthcheck";
this.pingPath = c.hasPathOrNull("pingPath") ? c.getString("pingPath") : "ping";
this.port = c.hasPathOrNull("port") ? c.getInt("port") : 8092;
this.recentRequestsQueueSize = c.hasPathOrNull("recentRequestsQueueSize") ? c.getInt("recentRequestsQueueSize") : 50;
this.threadDumpPath = c.hasPathOrNull("threadDumpPath") ? c.getString("threadDumpPath") : "threaddump";
this.versionPath = c.hasPathOrNull("versionPath") ? c.getString("versionPath") : "version";
}
Expand Down Expand Up @@ -227,18 +231,6 @@ public static class Internal2 {
public final boolean staleAgentCheckEnabled;
public final int staleAgentCheckPauseSecs;
public final Internal2.Zipkin2 zipkin;
public Internal2(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgValidator $tsCfgValidator) {
this.blitz = c.hasPathOrNull("blitz") ? new Internal2.Blitz(c.getConfig("blitz"), parentPath + "blitz.", $tsCfgValidator) : new Internal2.Blitz(com.typesafe.config.ConfigFactory.parseString("blitz{}"), parentPath + "blitz.", $tsCfgValidator);
this.maxAgentInactivitySecs = c.hasPathOrNull("maxAgentInactivitySecs") ? c.getInt("maxAgentInactivitySecs") : 15;
this.scrapeRequestBacklogUnhealthySize = c.hasPathOrNull("scrapeRequestBacklogUnhealthySize") ? c.getInt("scrapeRequestBacklogUnhealthySize") : 25;
this.scrapeRequestCheckMillis = c.hasPathOrNull("scrapeRequestCheckMillis") ? c.getInt("scrapeRequestCheckMillis") : 500;
this.scrapeRequestMapUnhealthySize = c.hasPathOrNull("scrapeRequestMapUnhealthySize") ? c.getInt("scrapeRequestMapUnhealthySize") : 25;
this.scrapeRequestTimeoutSecs = c.hasPathOrNull("scrapeRequestTimeoutSecs") ? c.getInt("scrapeRequestTimeoutSecs") : 5;
this.staleAgentCheckEnabled = !c.hasPathOrNull("staleAgentCheckEnabled") || c.getBoolean("staleAgentCheckEnabled");
this.staleAgentCheckPauseSecs = c.hasPathOrNull("staleAgentCheckPauseSecs") ? c.getInt("staleAgentCheckPauseSecs") : 10;
this.zipkin = c.hasPathOrNull("zipkin") ? new Internal2.Zipkin2(c.getConfig("zipkin"), parentPath + "zipkin.", $tsCfgValidator) : new Internal2.Zipkin2(com.typesafe.config.ConfigFactory.parseString("zipkin{}"), parentPath + "zipkin.", $tsCfgValidator);
}

public static class Blitz {
public final boolean enabled;
public final java.lang.String path;
Expand Down Expand Up @@ -266,6 +258,18 @@ public Zipkin2(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfg
this.serviceName = c.hasPathOrNull("serviceName") ? c.getString("serviceName") : "prometheus-proxy";
}
}

public Internal2(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgValidator $tsCfgValidator) {
this.blitz = c.hasPathOrNull("blitz") ? new Internal2.Blitz(c.getConfig("blitz"), parentPath + "blitz.", $tsCfgValidator) : new Internal2.Blitz(com.typesafe.config.ConfigFactory.parseString("blitz{}"), parentPath + "blitz.", $tsCfgValidator);
this.maxAgentInactivitySecs = c.hasPathOrNull("maxAgentInactivitySecs") ? c.getInt("maxAgentInactivitySecs") : 15;
this.scrapeRequestBacklogUnhealthySize = c.hasPathOrNull("scrapeRequestBacklogUnhealthySize") ? c.getInt("scrapeRequestBacklogUnhealthySize") : 25;
this.scrapeRequestCheckMillis = c.hasPathOrNull("scrapeRequestCheckMillis") ? c.getInt("scrapeRequestCheckMillis") : 500;
this.scrapeRequestMapUnhealthySize = c.hasPathOrNull("scrapeRequestMapUnhealthySize") ? c.getInt("scrapeRequestMapUnhealthySize") : 25;
this.scrapeRequestTimeoutSecs = c.hasPathOrNull("scrapeRequestTimeoutSecs") ? c.getInt("scrapeRequestTimeoutSecs") : 5;
this.staleAgentCheckEnabled = !c.hasPathOrNull("staleAgentCheckEnabled") || c.getBoolean("staleAgentCheckEnabled");
this.staleAgentCheckPauseSecs = c.hasPathOrNull("staleAgentCheckPauseSecs") ? c.getInt("staleAgentCheckPauseSecs") : 10;
this.zipkin = c.hasPathOrNull("zipkin") ? new Internal2.Zipkin2(c.getConfig("zipkin"), parentPath + "zipkin.", $tsCfgValidator) : new Internal2.Zipkin2(com.typesafe.config.ConfigFactory.parseString("zipkin{}"), parentPath + "zipkin.", $tsCfgValidator);
}
}

public static class Metrics2 {
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.4", date = "11/20/19")
@VersionAnnotation(version = "1.4.5", date = "11/21/19")
package io.prometheus;

import io.prometheus.common.VersionAnnotation;
13 changes: 10 additions & 3 deletions src/main/kotlin/io/prometheus/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.github.pambrose.common.delegate.AtomicDelegates.nonNullableReference
import com.github.pambrose.common.dsl.GuavaDsl.toStringElements
import com.github.pambrose.common.service.GenericService
import com.github.pambrose.common.servlet.LambdaServlet
import com.github.pambrose.common.time.format
import com.github.pambrose.common.util.MetricsUtils.newBacklogHealthCheck
import com.github.pambrose.common.util.getBanner
import com.github.pambrose.common.util.hostInfo
Expand Down Expand Up @@ -96,7 +97,10 @@ class Agent(options: AgentOptions,

initService {
if (options.debugEnabled)
addServlet(DEBUG, LambdaServlet({ toPlainText() + "\n" + pathManager.toPlainText() }))
addServlet(DEBUG,
LambdaServlet {
listOf(toPlainText(), pathManager.toPlainText()).joinToString("\n")
})
}

initBlock?.invoke(this)
Expand Down Expand Up @@ -202,14 +206,17 @@ class Agent(options: AgentOptions,

fun toPlainText() =
"""
Prometheus Agent Info [${getVersionDesc(false)}]
Uptime: ${upTime.format(true)}
AgentId: $agentId
AgentName: $agentName
ProxyHost: $proxyHost
AdminService:
Admin Service:
${if (isAdminEnabled) adminService.toString() else "Disabled"}
MetricsService:
Metrics Service:
${if (isMetricsEnabled) metricsService.toString() else "Disabled"}
""".trimIndent()
Expand Down
34 changes: 29 additions & 5 deletions src/main/kotlin/io/prometheus/Proxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import com.github.pambrose.common.dsl.GuavaDsl.toStringElements
import com.github.pambrose.common.dsl.MetricsDsl.healthCheck
import com.github.pambrose.common.service.GenericService
import com.github.pambrose.common.servlet.LambdaServlet
import com.github.pambrose.common.time.format
import com.github.pambrose.common.util.MetricsUtils.newMapHealthCheck
import com.github.pambrose.common.util.getBanner
import com.google.common.base.Joiner
import com.google.common.collect.EvictingQueue
import io.grpc.Attributes
import io.prometheus.common.BaseOptions.Companion.DEBUG
import io.prometheus.common.ConfigVals
Expand All @@ -44,9 +46,11 @@ import io.prometheus.proxy.ProxyPathManager
import io.prometheus.proxy.ScrapeRequestManager
import kotlinx.coroutines.runBlocking
import mu.KLogging
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.time.milliseconds

class Proxy(options: ProxyOptions,
class Proxy(val options: ProxyOptions,
proxyHttpPort: Int = options.proxyHttpPort,
inProcessServerName: String = "",
testMode: Boolean = false,
Expand All @@ -64,6 +68,7 @@ class Proxy(options: ProxyOptions,

private val proxyConfigVals: ConfigVals.Proxy2.Internal2 = configVals.proxy.internal
private val httpService = ProxyHttpService(this, proxyHttpPort)
private val recentActions = EvictingQueue.create<String>(configVals.proxy.admin.recentRequestsQueueSize)
private val grpcService =
if (inProcessServerName.isEmpty())
ProxyGrpcService(this, port = options.proxyAgentPort)
Expand All @@ -88,8 +93,17 @@ class Proxy(options: ProxyOptions,
addServices(grpcService, httpService)

initService {
if (options.debugEnabled)
addServlet(DEBUG, LambdaServlet({ toPlainText() + "\n" + pathManager.toPlainText() }))
if (options.debugEnabled) {
val cnt = configVals.proxy.admin.recentRequestsQueueSize
addServlet(DEBUG,
LambdaServlet {
listOf(toPlainText(),
pathManager.toPlainText(),
if (recentActions.size > 0) "\n$cnt most recent Requests:" else "",
recentActions.reversed().joinToString("\n"))
.joinToString("\n")
})
}
}

initBlock?.invoke(this)
Expand Down Expand Up @@ -162,14 +176,24 @@ class Proxy(options: ProxyOptions,
agentContext
}

//val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
private val formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")

fun logActivity(desc: String) {
recentActions.add("${LocalDateTime.now().format(formatter)}: $desc")
}

fun toPlainText() =
"""
Prometheus Proxy Info [${getVersionDesc(false)}]
Uptime: ${upTime.format(true)}
Proxy port: ${httpService.httpPort}
AdminService:
Admin Service:
${if (isAdminEnabled) adminService.toString() else "Disabled"}
MetricsService:
Metrics Service:
${if (isMetricsEnabled) metricsService.toString() else "Disabled"}
""".trimIndent()
Expand Down
16 changes: 9 additions & 7 deletions src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import brave.grpc.GrpcTracing
import com.github.pambrose.common.delegate.AtomicDelegates.nonNullableReference
import com.github.pambrose.common.dsl.GrpcDsl
import com.github.pambrose.common.dsl.GrpcDsl.channel
import com.github.pambrose.common.util.simpleClassName
import com.google.protobuf.Empty
import io.grpc.ClientInterceptor
import io.grpc.ClientInterceptors
Expand Down Expand Up @@ -57,13 +58,14 @@ class AgentGrpcService(private val agent: Agent,

init {
val schemeStripped =
options.proxyHostname.run {
when {
startsWith("http://") -> removePrefix("http://")
startsWith("https://") -> removePrefix("https://")
else -> this
options.proxyHostname
.run {
when {
startsWith("http://") -> removePrefix("http://")
startsWith("https://") -> removePrefix("https://")
else -> this
}
}
}

if (schemeStripped.contains(":")) {
val vals = schemeStripped.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
Expand Down Expand Up @@ -122,7 +124,7 @@ class AgentGrpcService(private val agent: Agent,
} catch (e: StatusRuntimeException) {
if (agent.isMetricsEnabled)
agent.metrics.connects.labels("failure")?.inc()
logger.info { "Cannot connect to proxy at ${agent.proxyHost} [${e.message}]" }
logger.info { "Cannot connect to proxy at ${agent.proxyHost} - ${e.simpleClassName}: ${e.message}" }
false
}

Expand Down
Loading

0 comments on commit 4485c1f

Please sign in to comment.