Skip to content

Commit

Permalink
1.2.0 dev (#3)
Browse files Browse the repository at this point in the history
* Add admin servlets (ping, threaddump, healthcheck)
  • Loading branch information
pambrose authored Apr 30, 2017
1 parent e085c46 commit 63f0cb8
Show file tree
Hide file tree
Showing 41 changed files with 832 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ notifications:
- [email protected]

after_success:
- ./mvnw clean test jacoco:report coveralls:report
- ./mvnw jacoco:report coveralls:report
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.1.0
VERSION=1.2.0

default: build

Expand All @@ -25,6 +25,9 @@ build-coverage:
report-coverage:
./mvnw -DrepoToken=${COVERALLS_TOKEN} clean package test jacoco:report coveralls:report

sonar:
./mvnw sonar:sonar -Dsonar.host.url=http://localhost:9000

distro: build
mkdir target/distro
mv target/proxy-jar-with-dependencies.jar target/distro/prometheus-proxy.jar
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ scrape_configs:
The docker images are available via:
```bash
$ docker pull pambrose/prometheus-proxy:1.1.0
$ docker pull pambrose/prometheus-agent:1.1.0
$ docker pull pambrose/prometheus-proxy:1.2.0
$ docker pull pambrose/prometheus-agent:1.2.0
```

Start the proxy and an agent in separate shells on your local machine:

```bash
$ docker run --rm -p 8082:8082 -p 50051:50051 -p 8080:8080 \
$ 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.1.0
pambrose/prometheus-proxy:1.2.0
```

```bash
$ docker run --rm -p 8083:8083 \
$ 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.1.0
pambrose/prometheus-agent:1.2.0
```

Using the config file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf),
Expand Down Expand Up @@ -129,6 +129,8 @@ The only required argument is an Agent config value, which should have an `agent
| -c --config | PROXY_CONFIG | | | Agent config file or url |
| -p --port | PROXY_PORT | proxy.http.port | 8080 | Proxy listen port |
| -a --agent_port | AGENT_PORT | proxy.agent.port | 50051 | Grpc listen port |
| -r --admin | ADMIN_ENABLED | proxy.admin.enabled | false | Enable admin servlets |
| -i --admin_port | ADMIN_PORT | proxy.admin.port | 8092 | Admin servlets port |
| -e --metrics | METRICS_ENABLED | proxy.metrics.enabled | false | Enable proxy metrics |
| -m --metrics_port | METRICS_PORT | proxy.metrics.port | 8082 | Proxy metrics listen port |
| -v --version | | | | Print version info and exit |
Expand All @@ -143,6 +145,8 @@ The only required argument is an Agent config value, which should have an `agent
| -c --config | AGENT_CONFIG | | | Agent config file or url (required) |
| -p --proxy | PROXY_HOSTNAME | agent.proxy.hostname | | Proxy hostname (can include :port) |
| -n --name | AGENT_NAME | agent.name | | Agent name |
| -r --admin | ADMIN_ENABLED | agent.admin.enabled | false | Enable admin servlets |
| -i --admin_port | ADMIN_PORT | agent.admin.port | 8093 | Admin servlets port |
| -e --metrics | METRICS_ENABLED | agent.metrics.enabled | false | Enable agent metrics |
| -m --metrics_port | METRICS_PORT | agent.metrics.port | 8083 | Agent metrics listen port |
| -v --version | | | | Print version info and exit |
Expand All @@ -157,6 +161,16 @@ Misc notes:
* Option values are evaluated in the order: CLI, enviroment vars, and finally config file vals
* Property values can be set as a java -D arg to or as a proxy or agent jar -D arg.

### Admin Servlets

Three admin servlets are available when the `proxy.admin.enabled` or `agent.admin.enabled` properties are enabled:
* /ping
* /threaddump
* /healthcheck

Descriptions of the servlets are [here](http://metrics.dropwizard.io/3.2.2/manual/servlets.html).
The path names can be changed in the configuration file.

## Grafana

[Grafana](https://grafana.com) dashboards for the Proxy and Agent are [here](https://github.com/pambrose/prometheus-proxy/tree/master/grafana).
Expand Down
4 changes: 2 additions & 2 deletions bin/docker-agent.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

docker run --rm -p 8083:8083 \
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.1.0
pambrose/prometheus-agent:1.2.0
4 changes: 2 additions & 2 deletions bin/docker-proxy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

docker run --rm -p 8082:8082 -p 50051:50051 -p 8080:8080 \
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.1.0
pambrose/prometheus-proxy:1.2.0
3 changes: 2 additions & 1 deletion etc/compose/proxy.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
prometheus-proxy:
autoredeploy: true
image: 'pambrose/prometheus-proxy:1.1.0'
image: 'pambrose/prometheus-proxy:1.2.0'
ports:
- '8080:8080'
- '8082:8082'
- '8092:8092'
- '50051:50051'
environment:
- PROXY_CONFIG=https://dl.dropboxusercontent.com/u/481551/prometheus/cloud-proxy.conf
Expand Down
16 changes: 16 additions & 0 deletions etc/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ proxy {

agent.port = 50051 // Listen port for agent connections

admin {
enabled = false // Enable Admin servlets
port = 8092 // Admin servlets port
pingPath = "ping" // Ping servlet path
healthCheckPath = "healthcheck" // HealthCheck servlet path
theadtDumpPath = "threaddump" // ThreadDump servlet path
}

metrics {
enabled = false // Enable Proxy metrics
port = 8082 // Listen port for metrics endpoint
Expand Down Expand Up @@ -62,6 +70,14 @@ agent {
port = 50051
}

admin {
enabled = false // Enable Admin servlets
port = 8093 // Admin servlets port
pingPath = "ping" // Ping servlet path
healthCheckPath = "healthcheck" // HealthCheck servlet path
theadtDumpPath = "threaddump" // ThreadDump servlet path
}

metrics {
enabled = false // Enable Agent metrics
port = 8083 // Listen port for metrics endpoint
Expand Down
1 change: 1 addition & 0 deletions etc/docker/agent.df
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ RUN ./mvnw -DskipTests=true clean package && \
rm -rf /root/.m2 .mvn etc src target/*.jar target/protoc* target/maven* target/generated* target/archive* target/test-classes

EXPOSE 8083
expose 8093

ENTRYPOINT ["/prometheus-proxy/target/bin/agent.sh"]
1 change: 1 addition & 0 deletions etc/docker/proxy.df
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN ./mvnw -DskipTests=true clean package && \

EXPOSE 8080
EXPOSE 8082
EXPOSE 8092
EXPOSE 50051

ENTRYPOINT ["/prometheus-proxy/target/bin/proxy.sh"]
2 changes: 2 additions & 0 deletions examples/simple.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
proxy {
admin.enabled: true
metrics.enabled: true
}

agent {
proxy.hostname = ${HOSTNAME}
admin.enabled: true
metrics.enabled: true

pathConfigs: [
Expand Down
48 changes: 47 additions & 1 deletion 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.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>

<properties>
<config.version>1.3.1</config.version>
Expand All @@ -21,6 +21,7 @@
<okhttp.version>3.7.0</okhttp.version>
<auto.version>1.4.1</auto.version>
<grpc-prom.version>0.3.0</grpc-prom.version>
<metrics.version>3.2.2</metrics.version>
<brave.version>4.2.0</brave.version>
<zipkin-reporter.version>0.7.0</zipkin-reporter.version>

Expand Down Expand Up @@ -117,6 +118,30 @@
</exclusions>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>${metrics.version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-healthchecks</artifactId>
<version>${metrics.version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-servlets</artifactId>
<version>${metrics.version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jvm</artifactId>
<version>${metrics.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down Expand Up @@ -256,6 +281,27 @@
</configuration>
</plugin>

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

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
Expand Down
52 changes: 25 additions & 27 deletions src/main/java/io/prometheus/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.RateLimiter;
import com.google.common.util.concurrent.ServiceManager;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.protobuf.Empty;
import io.grpc.ClientInterceptor;
Expand All @@ -22,9 +20,9 @@
import io.prometheus.agent.PathContext;
import io.prometheus.agent.RequestFailureException;
import io.prometheus.client.Summary;
import io.prometheus.common.AdminConfig;
import io.prometheus.common.ConfigVals;
import io.prometheus.common.GenericService;
import io.prometheus.common.GenericServiceListener;
import io.prometheus.common.MetricsConfig;
import io.prometheus.common.Utils;
import io.prometheus.common.ZipkinConfig;
Expand Down Expand Up @@ -98,15 +96,18 @@ public class Agent
private final BlockingQueue<ScrapeResponse> scrapeResponseQueue;
private final RateLimiter reconnectLimiter;
private final List<Map<String, String>> pathConfigs;
private final ServiceManager serviceManager;


public Agent(final AgentOptions options,
final MetricsConfig metricsConfig,
final ZipkinConfig zipkinConfig,
final String inProcessServerName,
final boolean testMode) {
super(options.getConfigVals(), metricsConfig, zipkinConfig, testMode);
public Agent(final AgentOptions options, final String inProcessServerName, final boolean testMode) {
super(options.getConfigVals(),
AdminConfig.create(options.isAdminEnabled(),
options.getAdminPort(),
options.getConfigVals().agent.admin),
MetricsConfig.create(options.isMetricsEnabled(),
options.getMetricsPort(),
options.getConfigVals().agent.metrics),
ZipkinConfig.create(options.getConfigVals().agent.internal.zipkin),
testMode);

this.inProcessServerName = inProcessServerName;
this.agentName = isNullOrEmpty(options.getAgentName()) ? format("Unnamed-%s", Utils.getHostName())
Expand All @@ -131,9 +132,9 @@ public Agent(final AgentOptions options,
this.pathConfigs = this.getConfigVals().pathConfigs.stream()
.map(v -> ImmutableMap.of("name", v.name,
"path", v.path,
"url", v.url))
"pingUrl", v.url))
.peek(v -> logger.info("Proxy path /{} will be assigned to {}",
v.get("path"), v.get("url")))
v.get("path"), v.get("pingUrl")))
.collect(Collectors.toList());


Expand All @@ -149,25 +150,17 @@ public Agent(final AgentOptions options,

this.resetGrpcStubs();

this.serviceManager = new ServiceManager(this.newServiceList());
this.serviceManager.addListener(this.newListener());

logger.info("Created {}", this);
this.init();
}

public static void main(final String[] argv)
throws IOException, InterruptedException {
final AgentOptions options = new AgentOptions(argv, true);
final MetricsConfig metricsConfig = MetricsConfig.create(options.getMetricsEnabled(),
options.getMetricsPort(),
options.getConfigVals().agent.metrics);
final ZipkinConfig zipkinConfig = ZipkinConfig.create(options.getConfigVals().agent.internal.zipkin);

logger.info(Utils.getBanner("banners/agent.txt"));
logger.info(Utils.getVersionDesc());

final Agent agent = new Agent(options, metricsConfig, zipkinConfig, null, false);
agent.addListener(new GenericServiceListener(agent), MoreExecutors.directExecutor());
final Agent agent = new Agent(options, null, false);
agent.startAsync();
}

Expand Down Expand Up @@ -205,6 +198,13 @@ protected void run() {
}
}

@Override
protected void registerHealtChecks() {
super.registerHealtChecks();
this.getHealthCheckRegistry().register("scrape_response_queue_check",
Utils.queueHealthCheck(scrapeResponseQueue, 25));
}

@Override
protected String serviceName() { return format("%s %s", this.getClass().getSimpleName(), this.agentName); }

Expand Down Expand Up @@ -383,7 +383,7 @@ private void registerPaths()
throws RequestFailureException {
for (final Map<String, String> agentConfig : this.pathConfigs) {
final String path = agentConfig.get("path");
final String url = agentConfig.get("url");
final String url = agentConfig.get("pingUrl");
this.registerPath(path, url);
}
}
Expand Down Expand Up @@ -569,11 +569,9 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("agentId", this.getAgentId())
.add("agentName", this.agentName)
.add("metricsPort",
this.isMetricsEnabled() ? this.getMetricsService().getPort() : "Disabled")
.add("metricsPath",
this.isMetricsEnabled() ? "/" + this.getMetricsService().getPath() : "Disabled")
.add("proxyHost", this.getProxyHost())
.add("adminService", this.isAdminEnabled() ? this.getAdminService() : "Disabled")
.add("metricsService", this.isMetricsEnabled() ? this.getMetricsService() : "Disabled")
.toString();
}
}
Loading

0 comments on commit 63f0cb8

Please sign in to comment.