From 7923eb2e3c17ff751d9cb285c89adf483030debd Mon Sep 17 00:00:00 2001 From: Prithvi Raj Date: Thu, 5 Sep 2019 15:01:41 -0400 Subject: [PATCH] Support configuring sampling url (#384) * Support configuring sampling endpoint - Allow users to specify a non standard endpoint to retrieve sampling priorities from Signed-off-by: Prithvi Raj * Add test Signed-off-by: Prithvi Raj * Fix logic Signed-off-by: Prithvi Raj --- src/samplers/remote_sampler.js | 6 +++++- test/samplers/remote_sampler.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/samplers/remote_sampler.js b/src/samplers/remote_sampler.js index c6a4bb66f74..516e61bb95b 100644 --- a/src/samplers/remote_sampler.js +++ b/src/samplers/remote_sampler.js @@ -27,6 +27,7 @@ const DEFAULT_REFRESH_INTERVAL = 60000; const DEFAULT_MAX_OPERATIONS = 2000; const DEFAULT_SAMPLING_HOST = '0.0.0.0'; const DEFAULT_SAMPLING_PORT = 5778; +const DEFAULT_SAMPLING_PATH = '/sampling'; const PROBABILISTIC_STRATEGY_TYPE = 'PROBABILISTIC'; const RATE_LIMITING_STRATEGY_TYPE = 'RATE_LIMITING'; @@ -40,6 +41,7 @@ export default class RemoteControlledSampler implements Sampler { _refreshInterval: number; _host: string; _port: number; + _samplingPath: string; _maxOperations: number; _onSamplerUpdate: ?Function; @@ -59,6 +61,7 @@ export default class RemoteControlledSampler implements Sampler { * @param {string} [options.hostPort] - host and port for jaeger-agent, defaults to 'localhost:5778' * @param {string} [options.host] - host for jaeger-agent, defaults to 'localhost' * @param {number} [options.port] - port for jaeger-agent for SamplingManager endpoint + * @param {string} [options.samplingPath] - path on jaeger-agent for SamplingManager endpoint * @param {number} [options.maxOperations] - max number of operations to track in PerOperationSampler * @param {function} [options.onSamplerUpdate] */ @@ -77,6 +80,7 @@ export default class RemoteControlledSampler implements Sampler { this._host = options.host || DEFAULT_SAMPLING_HOST; this._port = options.port || DEFAULT_SAMPLING_PORT; } + this._samplingPath = options.samplingPath || DEFAULT_SAMPLING_PATH; this._onSamplerUpdate = options.onSamplerUpdate; if (options.refreshInterval !== 0) { @@ -118,7 +122,7 @@ export default class RemoteControlledSampler implements Sampler { this._logger.error(`Error in fetching sampling strategy: ${err}.`); this._metrics.samplerQueryFailure.increment(1); }; - Utils.httpGet(this._host, this._port, `/sampling?service=${serviceName}`, success, error); + Utils.httpGet(this._host, this._port, `${this._samplingPath}?service=${serviceName}`, success, error); } _handleSamplingServerResponse(body: string) { diff --git a/test/samplers/remote_sampler.js b/test/samplers/remote_sampler.js index 70f4ae546fe..297551d28f9 100644 --- a/test/samplers/remote_sampler.js +++ b/test/samplers/remote_sampler.js @@ -255,4 +255,12 @@ describe('RemoteSampler', () => { assert.deepEqual(decision, remoteSampler.onSetTag(span, 'pi', 3.1415)); assert.deepEqual([span, 'pi', 3.1415], mockSampler._onSetTag); }); + + it('should support setting a custom path for sampling endpoint', () => { + let samplingPath = '/custom-sampling-path'; + let rs = new RemoteSampler('service1', { + samplingPath: samplingPath, + }); + assert.equal(rs._samplingPath, samplingPath); + }); });