Skip to content

Commit

Permalink
1.6.2 (#34)
Browse files Browse the repository at this point in the history
* Create 1.6.2 release

* Rename NonChunkedScrapeResponse to ScrapeResponse

* Rename NonChunkedScrapeResponse to ScrapeResponse

* Add support for min gzip size

* Add support for min gzip size

* Add support for min gzip size

* Add support for min gzip size

* Add support for min gzip size

* Add support for min gzip size
  • Loading branch information
pambrose authored Dec 19, 2019
1 parent c3af2f5 commit 6f72a28
Show file tree
Hide file tree
Showing 40 changed files with 523 additions and 398 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.6.1
VERSION=1.6.2

default: compile

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ scrape_configs:
The docker images are available via:
```bash
docker pull pambrose/prometheus-proxy:1.6.1
docker pull pambrose/prometheus-agent:1.6.1
docker pull pambrose/prometheus-proxy:1.6.2
docker pull pambrose/prometheus-agent:1.6.2
```

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

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.6.1
pambrose/prometheus-agent:1.6.2
```

Using the config file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf),
Expand All @@ -130,7 +130,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.6.1
pambrose/prometheus-agent:1.6.2
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure
Expand Down Expand Up @@ -180,7 +180,8 @@ The only required argument is an agent config value, which should have an `agent
| --metrics, -e | METRICS_ENABLED <br> agent.metrics.enabled | false | Enable agent metrics |
| --metrics_port, -m | METRICS_PORT <br> agent.metrics.port | 8083 | Agent metrics listen port |
| --debug, -b | DEBUG_ENABLED <br> agent.metrics.debugEnabled | false | Enable agent debug servlet<br>on admin port|
| --max | MAX_CONTENT_SIZE_KBS <br> agent.maxContentSizeKbs | 32 | Threshold for chunking data to Proxy and buffer size |
| --chunk | CHUNK_CONTENT_SIZE_KBS <br> agent.chunkContentSizeKbs | 32 | Threshold for chunking data to Proxy and buffer size (KBs) |
| --gzip | MIN_GZIP_SIZE_BYTES <br> agent.minGzipSizeBytes | 1024 | Minimum size for content to be gzipped (Bytes) |
| --cert, -t | CERT_CHAIN_FILE_PATH <br> agent.tls.certChainFilePath | | Certificate chain file path |
| --key, -k | PRIVATE_KEY_FILE_PATH <br> agent.tls.privateKeyFilePath | | Private key file path |
| --trust, -s | TRUST_CERT_COLLECTION_FILE_PATH <br> agent.tls.trustCertCollectionFilePath | | Trust certificate collection file path |
Expand Down Expand Up @@ -248,15 +249,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.6.1
pambrose/prometheus-proxy:1.6.2

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.6.1
pambrose/prometheus-agent:1.6.2
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure
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.6.1
pambrose/prometheus-agent:1.6.2
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.6.1
pambrose/prometheus-proxy:1.6.2
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'io.prometheus'
version = '1.6.1'
version = '1.6.2'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -29,7 +29,7 @@ def loggingVersion = '1.7.8'
def protocVersion = '3.10.0'
def serializationVersion = '0.13.0'
def slf4jVersion = '1.7.28'
def tscfgVersion = '1.3.4'
def typesafeVersion = '1.3.4'
def utilsVersion = '1.1.13'
def zipkinVersion = '5.9.1'

Expand Down Expand Up @@ -66,7 +66,7 @@ dependencies {

implementation "javax.annotation:javax.annotation-api:${annotationVersion}"
implementation "com.beust:jcommander:${jcommanderVersion}"
implementation "com.typesafe:config:${tscfgVersion}"
implementation "com.typesafe:config:${typesafeVersion}"

implementation "io.prometheus:simpleclient:${prometheusVersion}"

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.6.1'
image: 'pambrose/prometheus-proxy:1.6.2'
ports:
- '8080:8080'
- '8082:8082'
Expand Down
5 changes: 4 additions & 1 deletion etc/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ proxy {
scrapeRequestBacklogUnhealthySize = 25 // Threshold for returning an unhealthy healthcheck
scrapeRequestMapUnhealthySize = 25 // Threshold for returning an unhealthy healthcheck

chunkContextMapUnhealthySize = 25 // Threshold for returning an unhealthy healthcheck

zipkin {
enabled = false
hostname = "localhost"
Expand All @@ -74,8 +76,9 @@ proxy {
agent {
name = "" // Agent name used in metrics reporting

maxContentSizeKbs = 32 // Threshold for chunking data to Proxy and buffer size
// See: https://github.com/grpc/grpc.github.io/issues/371
chunkContentSizeKbs = 32 // Threshold for chunking data to Proxy and buffer size
minGzipSizeBytes = 512 // Minimum size for content to be gzipped

proxy {
hostname = "localhost" // Proxy hostname
Expand Down
35 changes: 20 additions & 15 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.95 on Sat Dec 14 20:41:31 PST 2019
// generated by tscfg 0.9.95 on Wed Dec 18 21:18:09 PST 2019
// source: etc/config/config.conf

package io.prometheus.common;
Expand All @@ -16,18 +16,20 @@ public ConfigVals(com.typesafe.config.Config c) {

public static class Agent {
public final Agent.Admin admin;
public final int chunkContentSizeKbs;
public final Agent.Internal internal;
public final int maxContentSizeKbs;
public final Agent.Metrics metrics;
public final int minGzipSizeBytes;
public final java.lang.String name;
public final java.util.List<Agent.PathConfigs$Elm> pathConfigs;
public final Agent.Proxy proxy;
public final Agent.Tls tls;
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.chunkContentSizeKbs = c.hasPathOrNull("chunkContentSizeKbs") ? c.getInt("chunkContentSizeKbs") : 32;
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);
this.maxContentSizeKbs = c.hasPathOrNull("maxContentSizeKbs") ? c.getInt("maxContentSizeKbs") : 32;
this.metrics = c.hasPathOrNull("metrics") ? new Agent.Metrics(c.getConfig("metrics"), parentPath + "metrics.", $tsCfgValidator) : new Agent.Metrics(com.typesafe.config.ConfigFactory.parseString("metrics{}"), parentPath + "metrics.", $tsCfgValidator);
this.minGzipSizeBytes = c.hasPathOrNull("minGzipSizeBytes") ? c.getInt("minGzipSizeBytes") : 512;
this.name = c.hasPathOrNull("name") ? c.getString("name") : "";
this.pathConfigs = $_LAgent_PathConfigs$Elm(c.getList("pathConfigs"), parentPath, $tsCfgValidator);
this.proxy = c.hasPathOrNull("proxy") ? new Agent.Proxy(c.getConfig("proxy"), parentPath + "proxy.", $tsCfgValidator) : new Agent.Proxy(com.typesafe.config.ConfigFactory.parseString("proxy{}"), parentPath + "proxy.", $tsCfgValidator);
Expand Down Expand Up @@ -242,6 +244,7 @@ public Http(com.typesafe.config.Config c, java.lang.String parentPath, $TsCfgVal

public static class Internal2 {
public final Internal2.Blitz blitz;
public final int chunkContextMapUnhealthySize;
public final int maxAgentInactivitySecs;
public final int scrapeRequestBacklogUnhealthySize;
public final int scrapeRequestCheckMillis;
Expand All @@ -250,6 +253,20 @@ 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.chunkContextMapUnhealthySize = c.hasPathOrNull("chunkContextMapUnhealthySize") ? c.getInt("chunkContextMapUnhealthySize") : 25;
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 @@ -277,18 +294,6 @@ 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.6.1", date = "12/15/19")
@VersionAnnotation(version = "1.6.2", date = "12/18/19")
package io.prometheus;

import io.prometheus.common.VersionAnnotation;
13 changes: 9 additions & 4 deletions src/main/kotlin/io/prometheus/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Agent(val options: AgentOptions,
logger.info { "Disconnected from proxy at $proxyHost" }
} catch (e: Throwable) {
// Catch anything else to avoid exiting retry loop
logger.warn(e) { "Throwable caught" }
} finally {
logger.info { "Waited ${reconnectLimiter.acquire().roundToInt().seconds} to reconnect" }
}
Expand All @@ -140,6 +141,7 @@ class Agent(val options: AgentOptions,
// Reset gRPC stubs if previous iteration had a successful connection, i.e., the agentId != ""
if (agentId.isNotEmpty()) {
grpcService.resetGrpcStubs()
logger.info { "Resetting agentId" }
agentId = ""
}

Expand Down Expand Up @@ -190,8 +192,8 @@ class Agent(val options: AgentOptions,
}

fun updateScrapeCounter(type: String) {
if (isMetricsEnabled && type.isNotEmpty())
metrics.scrapeRequests.labels(type).inc()
if (type.isNotEmpty())
metrics { scrapeRequestCount.labels(type).inc() }
}

fun markMsgSent() {
Expand All @@ -201,6 +203,11 @@ class Agent(val options: AgentOptions,
fun awaitInitialConnection(timeout: Duration) =
initialConnectionLatch.await(timeout.toLongMilliseconds(), MILLISECONDS)

fun metrics(args: AgentMetrics.() -> Unit) {
if (isMetricsEnabled)
args.invoke(metrics)
}

override fun shutDown() {
grpcService.shutDown()
super.shutDown()
Expand Down Expand Up @@ -235,12 +242,10 @@ class Agent(val options: AgentOptions,
companion object : KLogging() {
@JvmStatic
fun main(argv: Array<String>) {

logger.apply {
info { getBanner("banners/agent.txt", this) }
info { getVersionDesc(false) }
}

Agent(options = AgentOptions(argv, true)) { startSync() }
}
}
Expand Down
36 changes: 20 additions & 16 deletions src/main/kotlin/io/prometheus/Proxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import io.prometheus.common.ConfigVals
import io.prometheus.common.ConfigWrappers.newAdminConfig
import io.prometheus.common.ConfigWrappers.newMetricsConfig
import io.prometheus.common.ConfigWrappers.newZipkinConfig
import io.prometheus.common.GrpcObjects.EMPTY_AGENTID
import io.prometheus.common.getVersionDesc
import io.prometheus.proxy.AgentContext
import io.prometheus.proxy.AgentContextCleanupService
import io.prometheus.proxy.AgentContextManager
import io.prometheus.proxy.ProxyGrpcService
Expand Down Expand Up @@ -141,6 +143,9 @@ class Proxy(val options: ProxyOptions,
healthCheckRegistry
.apply {
register("grpc_service", grpcService.healthCheck)
register("chunking_map_check",
newMapHealthCheck(agentContextManager.chunkedContextMap,
proxyConfigVals.chunkContextMapUnhealthySize))
register("scrape_response_map_check",
newMapHealthCheck(scrapeRequestManager.scrapeRequestMap,
proxyConfigVals.scrapeRequestMapUnhealthySize))
Expand All @@ -162,22 +167,23 @@ class Proxy(val options: ProxyOptions,
}
}

fun removeAgentContext(agentId: String?) =
if (agentId == null || agentId.isEmpty()) {
logger.error { "Missing agentId" }
null
}
fun removeAgentContext(agentId: String): AgentContext? {
require(agentId.isNotEmpty()) { EMPTY_AGENTID }
return agentContextManager.removeAgentContext(agentId).let { agentContext ->
if (agentContext == null)
logger.error { "Missing AgentContext for agentId: $agentId" }
else {
val agentContext = agentContextManager.removeAgentContext(agentId)
if (agentContext == null) {
logger.error { "Missing AgentContext for agentId: $agentId" }
}
else {
logger.debug { "Removed $agentContext" }
agentContext.invalidate()
}
agentContext
logger.debug { "Removed $agentContext" }
agentContext.invalidate()
}
agentContext
}
}

fun metrics(args: ProxyMetrics.() -> Unit) {
if (isMetricsEnabled)
args.invoke(metrics)
}

//val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
private val formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
Expand Down Expand Up @@ -216,12 +222,10 @@ class Proxy(val options: ProxyOptions,

@JvmStatic
fun main(argv: Array<String>) {

logger.apply {
info { getBanner("banners/proxy.txt", logger) }
info { getVersionDesc(false) }
}

Proxy(options = ProxyOptions(argv)) { startSync() }
}
}
Expand Down
Loading

0 comments on commit 6f72a28

Please sign in to comment.