Skip to content

Commit

Permalink
adding config parameter for no-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalBooking committed Mar 19, 2024
1 parent f70fa46 commit 204ba2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 15 additions & 0 deletions agent/src/main/java/io/pyroscope/javaagent/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class Config {
private static final String PYROSCOPE_FORMAT_CONFIG = "PYROSCOPE_FORMAT";
private static final String PYROSCOPE_PUSH_QUEUE_CAPACITY_CONFIG = "PYROSCOPE_PUSH_QUEUE_CAPACITY";
private static final String PYROSCOPE_LABELS = "PYROSCOPE_LABELS";
private static final String PYROSCOPE_NO_PROXY_CONFIG = "PYROSCOPE_NO_PROXY";

private static final String PYROSCOPE_INGEST_MAX_TRIES = "PYROSCOPE_INGEST_MAX_TRIES";
private static final String PYROSCOPE_EXPORT_COMPRESSION_LEVEL_JFR = "PYROSCOPE_EXPORT_COMPRESSION_LEVEL_JFR";
Expand Down Expand Up @@ -77,6 +78,7 @@ public final class Config {
private static final int DEFAULT_JAVA_STACK_DEPTH_MAX = 2048;
private static final String DEFAULT_SERVER_ADDRESS = "http://localhost:4040";
private static final Format DEFAULT_FORMAT = Format.JFR;
private static final boolean DEFAULT_NO_PROXY = false;
// The number of snapshots simultaneously stored in memory is limited by this.
// The number is fairly arbitrary. If an average snapshot is 5KB, it's about 160 KB.
private static final int DEFAULT_PUSH_QUEUE_CAPACITY = 8;
Expand Down Expand Up @@ -109,6 +111,7 @@ public final class Config {
public final int ingestMaxTries;
public final int compressionLevelJFR;
public final int compressionLevelLabels;
public final boolean noProxy;

public final boolean allocLive;
public final boolean gcBeforeDump;
Expand Down Expand Up @@ -136,6 +139,7 @@ public final class Config {
final Format format,
final int pushQueueCapacity,
final Map<String, String> labels,
final boolean noProxy,
int ingestMaxRetries,
int compressionLevelJFR,
int compressionLevelLabels,
Expand Down Expand Up @@ -176,6 +180,7 @@ public final class Config {
this.format = format;
this.pushQueueCapacity = pushQueueCapacity;
this.labels = Collections.unmodifiableMap(labels);
this.noProxy = noProxy;
HttpUrl serverAddressUrl = HttpUrl.parse(serverAddress);
if (serverAddressUrl == null) {
throw new IllegalArgumentException("invalid url " + serverAddress);
Expand Down Expand Up @@ -219,6 +224,7 @@ public String toString() {
", format=" + format +
", pushQueueCapacity=" + pushQueueCapacity +
", labels=" + labels +
", noProxy=" + noProxy +
", ingestMaxTries=" + ingestMaxTries +
", compressionLevelJFR=" + compressionLevelJFR +
", compressionLevelLabels=" + compressionLevelLabels +
Expand Down Expand Up @@ -246,6 +252,7 @@ public static Config build(ConfigurationProvider cp) {
String alloc = profilingAlloc(cp);
boolean agentEnabled = bool(cp, PYROSCOPE_AGENT_ENABLED_CONFIG, DEFAULT_AGENT_ENABLED);
boolean allocLive = bool(cp, PYROSCOPE_ALLOC_LIVE, DEFAULT_ALLOC_LIVE);
boolean noProxyEnabled = bool(cp, PYROSCOPE_NO_PROXY_CONFIG, DEFAULT_NO_PROXY);
if (DEFAULT_PROFILER_ALLOC.equals(alloc) && allocLive) {
DefaultLogger.PRECONFIG_LOGGER.log(Logger.Level.WARN, "%s is ignored because %s is not configured",
PYROSCOPE_ALLOC_LIVE, PYROSCOPE_PROFILER_ALLOC_CONFIG);
Expand All @@ -267,6 +274,7 @@ public static Config build(ConfigurationProvider cp) {
format(cp),
pushQueueCapacity(cp),
labels(cp),
noProxyEnabled,
ingestMaxRetries(cp),
compressionLevel(cp, PYROSCOPE_EXPORT_COMPRESSION_LEVEL_JFR),
compressionLevel(cp, PYROSCOPE_EXPORT_COMPRESSION_LEVEL_LABELS),
Expand Down Expand Up @@ -648,6 +656,7 @@ public static class Builder {
public Format format = DEFAULT_FORMAT;
public int pushQueueCapacity = DEFAULT_PUSH_QUEUE_CAPACITY;
public Map<String, String> labels = Collections.emptyMap();
public boolean noProxy = DEFAULT_NO_PROXY;
public int ingestMaxRetries = DEFAULT_INGEST_MAX_RETRIES;
public int compressionLevelJFR = DEFAULT_COMPRESSION_LEVEL;
public int compressionLevelLabels = DEFAULT_COMPRESSION_LEVEL;
Expand Down Expand Up @@ -768,6 +777,11 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

public Builder setNoProxy(boolean noProxy) {
this.noProxy = noProxy;
return this;
}

public Builder setIngestMaxRetries(int ingestMaxRetries) {
this.ingestMaxRetries = ingestMaxRetries;
return this;
Expand Down Expand Up @@ -852,6 +866,7 @@ public Config build() {
format,
pushQueueCapacity,
labels,
noProxy,
ingestMaxRetries,
compressionLevelJFR,
compressionLevelLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.pyroscope.javaagent.util.zip.GzipSink;
import io.pyroscope.labels.Pyroscope;
import okhttp3.*;
import java.net.Proxy;

import java.io.IOException;
import java.time.Duration;
Expand All @@ -27,12 +28,16 @@ public class PyroscopeExporter implements Exporter {
public PyroscopeExporter(Config config, Logger logger) {
this.config = config;
this.logger = logger;
this.client = new OkHttpClient.Builder()
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(TIMEOUT)
.readTimeout(TIMEOUT)
.callTimeout(TIMEOUT)
.build();
.callTimeout(TIMEOUT);

if (config.noProxy) {
builder.proxy(Proxy.NO_PROXY);
}

this.client = builder.build();
}

@Override
Expand Down

0 comments on commit 204ba2e

Please sign in to comment.