-
Notifications
You must be signed in to change notification settings - Fork 231
Introduce JAEGER_CONFIG_MANAGER_ENDPOINT property #554
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,11 @@ public class Configuration { | |
*/ | ||
public static final String JAEGER_SAMPLER_MANAGER_HOST_PORT = JAEGER_PREFIX + "SAMPLER_MANAGER_HOST_PORT"; | ||
|
||
/** | ||
* The config manager endpoint URL. | ||
*/ | ||
public static final String JAEGER_CONFIG_MANAGER_ENDPOINT = JAEGER_PREFIX + "CONFIG_MANAGER_ENDPOINT"; | ||
|
||
/** | ||
* The service name. | ||
*/ | ||
|
@@ -332,26 +337,36 @@ public static class SamplerConfiguration { | |
private Number param; | ||
|
||
/** | ||
* HTTP host:port of the sampling manager that can provide sampling strategy to this service. | ||
* HTTP URL of the sampling manager that can provide sampling strategy to this service. | ||
* Optional. | ||
*/ | ||
private String managerHostPort; | ||
private String serverUrl; | ||
|
||
public SamplerConfiguration() { | ||
} | ||
|
||
public static SamplerConfiguration fromEnv() { | ||
String configManagerEndpoint = getProperty(JAEGER_CONFIG_MANAGER_ENDPOINT); | ||
if (configManagerEndpoint == null) { | ||
if (getProperty(JAEGER_SAMPLER_MANAGER_HOST_PORT) != null) { | ||
configManagerEndpoint = "http://" + getProperty(JAEGER_SAMPLER_MANAGER_HOST_PORT) + "/sampling"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go with HOST_PORT, shouldn't need to use any sort of string manipulation; pending confirmation that we're happy to diverge from the Go lib. |
||
} else if (getProperty(JAEGER_AGENT_HOST) != null) { | ||
configManagerEndpoint = "http://" + getProperty(JAEGER_AGENT_HOST) + ":" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
+ HttpSamplingManager.DEFAULT_SERVER_PORT + "/sampling"; | ||
} | ||
} | ||
|
||
return new SamplerConfiguration() | ||
.withType(getProperty(JAEGER_SAMPLER_TYPE)) | ||
.withParam(getPropertyAsNum(JAEGER_SAMPLER_PARAM)) | ||
.withManagerHostPort(getProperty(JAEGER_SAMPLER_MANAGER_HOST_PORT)); | ||
.withServerUrl(configManagerEndpoint); | ||
} | ||
|
||
// for tests | ||
Sampler createSampler(String serviceName, Metrics metrics) { | ||
String samplerType = stringOrDefault(this.getType(), RemoteControlledSampler.TYPE); | ||
Number samplerParam = numberOrDefault(this.getParam(), ProbabilisticSampler.DEFAULT_SAMPLING_PROBABILITY); | ||
String hostPort = stringOrDefault(this.getManagerHostPort(), HttpSamplingManager.DEFAULT_HOST_PORT); | ||
String serverUrl = stringOrDefault(this.getServerUrl(), HttpSamplingManager.DEFAULT_SERVER_URL); | ||
|
||
if (samplerType.equals(ConstSampler.TYPE)) { | ||
return new ConstSampler(samplerParam.intValue() != 0); | ||
|
@@ -367,7 +382,7 @@ Sampler createSampler(String serviceName, Metrics metrics) { | |
|
||
if (samplerType.equals(RemoteControlledSampler.TYPE)) { | ||
return new RemoteControlledSampler.Builder(serviceName) | ||
.withSamplingManager(new HttpSamplingManager(hostPort)) | ||
.withSamplingManager(new HttpSamplingManager(serverUrl)) | ||
.withInitialSampler(new ProbabilisticSampler(samplerParam.doubleValue())) | ||
.withMetrics(metrics) | ||
.build(); | ||
|
@@ -384,8 +399,8 @@ public Number getParam() { | |
return param; | ||
} | ||
|
||
public String getManagerHostPort() { | ||
return managerHostPort; | ||
public String getServerUrl() { | ||
return serverUrl; | ||
} | ||
|
||
public SamplerConfiguration withType(String type) { | ||
|
@@ -398,8 +413,17 @@ public SamplerConfiguration withParam(Number param) { | |
return this; | ||
} | ||
|
||
/** | ||
* @deprecated Use {@link #withServerUrl(String)} instead | ||
*/ | ||
@Deprecated | ||
public SamplerConfiguration withManagerHostPort(String managerHostPort) { | ||
this.managerHostPort = managerHostPort; | ||
this.serverUrl = "http://" + managerHostPort + "/sampling"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
return this; | ||
} | ||
|
||
public SamplerConfiguration withServerUrl(String serverUrl) { | ||
this.serverUrl = serverUrl; | ||
return this; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,23 @@ | |
|
||
@ToString | ||
public class HttpSamplingManager implements SamplingManager { | ||
public static final String DEFAULT_HOST_PORT = "localhost:5778"; | ||
private final String hostPort; | ||
public static final String DEFAULT_SERVER_HOST = "localhost"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not seem to be used. Only port is used in configuration |
||
public static final int DEFAULT_SERVER_PORT = 5778; | ||
public static final String DEFAULT_SERVER_URL = | ||
"http://" + DEFAULT_SERVER_HOST + ":" + DEFAULT_SERVER_PORT + "/sampling"; | ||
private final String serverUrl; | ||
|
||
@ToString.Exclude private final Gson gson = new Gson(); | ||
|
||
/** | ||
* This constructor expects running sampling manager on {@link #DEFAULT_HOST_PORT}. | ||
* This constructor expects running sampling manager on {@link #DEFAULT_SERVER_URL}. | ||
*/ | ||
public HttpSamplingManager() { | ||
this(DEFAULT_HOST_PORT); | ||
this(DEFAULT_SERVER_URL); | ||
} | ||
|
||
public HttpSamplingManager(String hostPort) { | ||
this.hostPort = hostPort != null ? hostPort : DEFAULT_HOST_PORT; | ||
public HttpSamplingManager(String serverUrl) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like a breaking change. We can keep Host port is easier to configure. Not sure if there are any advantages of using full URL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - the primary driver of using ENDPOINT was to keep this in-line with the Go library. If that's not a concern, then this is something I can change. |
||
this.serverUrl = serverUrl != null ? serverUrl : DEFAULT_SERVER_URL; | ||
} | ||
|
||
SamplingStrategyResponse parseJson(String json) { | ||
|
@@ -59,7 +62,7 @@ public SamplingStrategyResponse getSamplingStrategy(String serviceName) | |
try { | ||
jsonString = | ||
makeGetRequest( | ||
"http://" + hostPort + "/?service=" + URLEncoder.encode(serviceName, "UTF-8")); | ||
serverUrl + "?service=" + URLEncoder.encode(serviceName, "UTF-8")); | ||
} catch (IOException e) { | ||
throw new SamplingStrategyErrorException( | ||
"http call to get sampling strategy from local agent failed.", e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use
CONFIG_MANAGER_HOST_PORT
as it is also used by baggage restriction. host port is also easier to configure.