Skip to content

Commit

Permalink
1.2.1 Merge (#4)
Browse files Browse the repository at this point in the history
* Fix typo in properties
* Add version servlet
* Add unhealthy queue and map size properties for healthchecks
  • Loading branch information
pambrose authored Apr 30, 2017
1 parent 63f0cb8 commit 3798632
Show file tree
Hide file tree
Showing 25 changed files with 381 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.2.0
VERSION=1.2.1

default: build

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

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

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.2.0
pambrose/prometheus-agent:1.2.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.2.0
pambrose/prometheus-proxy:1.2.1
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.2.0'
image: 'pambrose/prometheus-proxy:1.2.1'
ports:
- '8080:8080'
- '8082:8082'
Expand Down
12 changes: 9 additions & 3 deletions etc/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
proxy {

http {
port = 8080 // Listen port for proxied scrapes
port = 8080 // Listen port for proxied scrapes
maxThreads = -1
minThreads = -1
idleTimeoutMillis = -1
Expand All @@ -14,8 +14,9 @@ proxy {
enabled = false // Enable Admin servlets
port = 8092 // Admin servlets port
pingPath = "ping" // Ping servlet path
versionPath = "version" // Version servlet path
healthCheckPath = "healthcheck" // HealthCheck servlet path
theadtDumpPath = "threaddump" // ThreadDump servlet path
threadDumpPath = "threaddump" // ThreadDump servlet path
}

metrics {
Expand Down Expand Up @@ -45,6 +46,9 @@ proxy {
scrapeRequestTimeoutSecs = 5
scrapeRequestCheckMillis = 500
scrapeRequestQueueCheckMillis = 500
scrapeRequestQueueUnhealthySize = 25

scrapeRequestMapUnhealthySize = 25

zipkin {
enabled = false
Expand Down Expand Up @@ -74,8 +78,9 @@ agent {
enabled = false // Enable Admin servlets
port = 8093 // Admin servlets port
pingPath = "ping" // Ping servlet path
versionPath = "version" // Version servlet path
healthCheckPath = "healthcheck" // HealthCheck servlet path
theadtDumpPath = "threaddump" // ThreadDump servlet path
threadDumpPath = "threaddump" // ThreadDump servlet path
}

metrics {
Expand Down Expand Up @@ -113,6 +118,7 @@ agent {

scrapeResponseQueueSize = 128
scrapeResponseQueueCheckMillis = 500
scrapeResponseQueueUnhealthySize = 25

zipkin {
enabled = false
Expand Down
25 changes: 1 addition & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.prometheus</groupId>
<artifactId>prometheus-proxy</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.1-SNAPSHOT</version>

<properties>
<config.version>1.3.1</config.version>
Expand Down Expand Up @@ -354,29 +354,6 @@
</executions>
</plugin>

<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-maven-3</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${maven.version}</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly.version}</version>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/prometheus/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static io.grpc.ClientInterceptors.intercept;
import static io.prometheus.common.InstrumentedThreadFactory.newInstrumentedThreadFactory;
import static io.prometheus.common.Utils.queueHealthCheck;
import static io.prometheus.common.Utils.sleepForMillis;
import static io.prometheus.common.Utils.toMillis;
import static io.prometheus.grpc.ProxyServiceGrpc.newBlockingStub;
Expand Down Expand Up @@ -201,8 +202,10 @@ protected void run() {
@Override
protected void registerHealtChecks() {
super.registerHealtChecks();
this.getHealthCheckRegistry().register("scrape_response_queue_check",
Utils.queueHealthCheck(scrapeResponseQueue, 25));
this.getHealthCheckRegistry()
.register("scrape_response_queue_check",
queueHealthCheck(scrapeResponseQueue,
this.getConfigVals().internal.scrapeResponseQueueUnhealthySize));
}

@Override
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/io/prometheus/Proxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.prometheus;

import com.codahale.metrics.health.HealthCheck;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import io.grpc.Attributes;
Expand All @@ -21,9 +23,12 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.google.common.base.Strings.isNullOrEmpty;
import static io.prometheus.common.Utils.mapHealthCheck;
import static java.lang.String.format;

public class Proxy
Expand Down Expand Up @@ -114,9 +119,30 @@ protected void run() {
@Override
protected void registerHealtChecks() {
super.registerHealtChecks();
this.getHealthCheckRegistry().register("scrape_response_map_check",
Utils.mapHealthCheck(scrapeRequestMap, 25));
this.getHealthCheckRegistry().register("grpc_service", this.grpcService.getHealthCheck());
this.getHealthCheckRegistry()
.register("scrape_response_map_check",
mapHealthCheck(scrapeRequestMap, this.getConfigVals().internal.scrapeRequestMapUnhealthySize));
this.getHealthCheckRegistry()
.register("agent_scrape_request_queue",
new HealthCheck() {
@Override
protected Result check()
throws Exception {
final int unhealthySize = getConfigVals().internal.scrapeRequestQueueUnhealthySize;
final List<String> vals = getAgentContextMap().entrySet()
.stream()
.filter(kv -> kv.getValue().scrapeRequestQueueSize() >= unhealthySize)
.map(kv -> format("%s %d",
kv.getValue(),
kv.getValue().scrapeRequestQueueSize()))
.collect(Collectors.toList());
return vals.isEmpty() ? Result.healthy()
: Result.unhealthy(format("Large scrapeRequestQueues: %s",
Joiner.on(", ").join(vals)));
}
});

}

public void addAgentContext(final AgentContext agentContext) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/io/prometheus/common/AdminConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public static AdminConfig create(final boolean enabled,
return new AutoValue_AdminConfig(enabled,
port,
admin.pingPath,
admin.versionPath,
admin.healthCheckPath,
admin.theadtDumpPath);
admin.threadDumpPath);
}

public static AdminConfig create(final boolean enabled,
Expand All @@ -22,8 +23,9 @@ public static AdminConfig create(final boolean enabled,
return new AutoValue_AdminConfig(enabled,
port,
admin.pingPath,
admin.versionPath,
admin.healthCheckPath,
admin.theadtDumpPath);
admin.threadDumpPath);
}

public abstract boolean enabled();
Expand All @@ -32,9 +34,11 @@ public static AdminConfig create(final boolean enabled,

public abstract String pingPath();

public abstract String versionPath();

public abstract String healthCheckPath();

public abstract String theadtDumpPath();
public abstract String threadDumpPath();
}


5 changes: 5 additions & 0 deletions src/main/java/io/prometheus/common/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ public class AdminService

private final int port;
private final String pingPath;
private final String versionPath;
private final String healthCheckPath;
private final String threadDumpPath;
private final Server server;

public AdminService(final GenericService service,
final int port,
final String pingPath,
final String versionPath,
final String healthCheckPath,
final String threadDumpPath) {
this.port = port;
this.pingPath = pingPath;
this.versionPath = versionPath;
this.healthCheckPath = healthCheckPath;
this.threadDumpPath = threadDumpPath;
this.server = new Server(this.port);
Expand All @@ -39,6 +42,8 @@ public AdminService(final GenericService service,

if (!isNullOrEmpty(this.pingPath))
context.addServlet(new ServletHolder(new PingServlet()), "/" + this.pingPath);
if (!isNullOrEmpty(this.versionPath))
context.addServlet(new ServletHolder(new VersionServlet()), "/" + this.versionPath);
if (!isNullOrEmpty(this.healthCheckPath))
context.addServlet(new ServletHolder(new HealthCheckServlet(service.getHealthCheckRegistry())),
"/" + this.healthCheckPath);
Expand Down
20 changes: 15 additions & 5 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.8.0 on Sat Apr 29 11:36:36 PDT 2017
// generated by tscfg 0.8.0 on Sat Apr 29 23:58:20 PDT 2017
// source: etc/config/config.conf

package io.prometheus.common;
Expand Down Expand Up @@ -40,14 +40,16 @@ public static class Admin {
public final java.lang.String healthCheckPath;
public final java.lang.String pingPath;
public final int port;
public final java.lang.String theadtDumpPath;
public final java.lang.String threadDumpPath;
public final java.lang.String versionPath;

public Admin(com.typesafe.config.Config c) {
this.enabled = c.hasPathOrNull("enabled") && c.getBoolean("enabled");
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") : 8093;
this.theadtDumpPath = c.hasPathOrNull("theadtDumpPath") ? c.getString("theadtDumpPath") : "threaddump";
this.threadDumpPath = c.hasPathOrNull("threadDumpPath") ? c.getString("threadDumpPath") : "threaddump";
this.versionPath = c.hasPathOrNull("versionPath") ? c.getString("versionPath") : "version";
}
}

Expand All @@ -58,6 +60,7 @@ public static class Internal {
public final int reconectPauseSecs;
public final int scrapeResponseQueueCheckMillis;
public final int scrapeResponseQueueSize;
public final int scrapeResponseQueueUnhealthySize;
public final Internal.Zipkin zipkin;
public Internal(com.typesafe.config.Config c) {
this.heartbeatCheckPauseMillis = c.hasPathOrNull("heartbeatCheckPauseMillis") ? c.getInt("heartbeatCheckPauseMillis") : 500;
Expand All @@ -66,6 +69,7 @@ public Internal(com.typesafe.config.Config c) {
this.reconectPauseSecs = c.hasPathOrNull("reconectPauseSecs") ? c.getInt("reconectPauseSecs") : 3;
this.scrapeResponseQueueCheckMillis = c.hasPathOrNull("scrapeResponseQueueCheckMillis") ? c.getInt("scrapeResponseQueueCheckMillis") : 500;
this.scrapeResponseQueueSize = c.hasPathOrNull("scrapeResponseQueueSize") ? c.getInt("scrapeResponseQueueSize") : 128;
this.scrapeResponseQueueUnhealthySize = c.hasPathOrNull("scrapeResponseQueueUnhealthySize") ? c.getInt("scrapeResponseQueueUnhealthySize") : 25;
this.zipkin = new Internal.Zipkin(c.getConfig("zipkin"));
}

Expand Down Expand Up @@ -165,14 +169,16 @@ public static class Admin2 {
public final java.lang.String healthCheckPath;
public final java.lang.String pingPath;
public final int port;
public final java.lang.String theadtDumpPath;
public final java.lang.String threadDumpPath;
public final java.lang.String versionPath;

public Admin2(com.typesafe.config.Config c) {
this.enabled = c.hasPathOrNull("enabled") && c.getBoolean("enabled");
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.theadtDumpPath = c.hasPathOrNull("theadtDumpPath") ? c.getString("theadtDumpPath") : "threaddump";
this.threadDumpPath = c.hasPathOrNull("threadDumpPath") ? c.getString("threadDumpPath") : "threaddump";
this.versionPath = c.hasPathOrNull("versionPath") ? c.getString("versionPath") : "version";
}
}

Expand Down Expand Up @@ -202,8 +208,10 @@ public static class Internal2 {
public final Internal2.Blitz blitz;
public final int maxAgentInactivitySecs;
public final int scrapeRequestCheckMillis;
public final int scrapeRequestMapUnhealthySize;
public final int scrapeRequestQueueCheckMillis;
public final int scrapeRequestQueueSize;
public final int scrapeRequestQueueUnhealthySize;
public final int scrapeRequestTimeoutSecs;
public final boolean staleAgentCheckEnabled;
public final int staleAgentCheckPauseSecs;
Expand All @@ -212,8 +220,10 @@ public Internal2(com.typesafe.config.Config c) {
this.blitz = new Internal2.Blitz(c.getConfig("blitz"));
this.maxAgentInactivitySecs = c.hasPathOrNull("maxAgentInactivitySecs") ? c.getInt("maxAgentInactivitySecs") : 15;
this.scrapeRequestCheckMillis = c.hasPathOrNull("scrapeRequestCheckMillis") ? c.getInt("scrapeRequestCheckMillis") : 500;
this.scrapeRequestMapUnhealthySize = c.hasPathOrNull("scrapeRequestMapUnhealthySize") ? c.getInt("scrapeRequestMapUnhealthySize") : 25;
this.scrapeRequestQueueCheckMillis = c.hasPathOrNull("scrapeRequestQueueCheckMillis") ? c.getInt("scrapeRequestQueueCheckMillis") : 500;
this.scrapeRequestQueueSize = c.hasPathOrNull("scrapeRequestQueueSize") ? c.getInt("scrapeRequestQueueSize") : 128;
this.scrapeRequestQueueUnhealthySize = c.hasPathOrNull("scrapeRequestQueueUnhealthySize") ? c.getInt("scrapeRequestQueueUnhealthySize") : 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;
Expand Down
Loading

0 comments on commit 3798632

Please sign in to comment.