Skip to content

Commit

Permalink
Support configuring sampling url (open-telemetry#384)
Browse files Browse the repository at this point in the history
* Support configuring sampling endpoint

- Allow users to specify a non standard endpoint to retrieve sampling
priorities from

Signed-off-by: Prithvi Raj <p.r@uber.com>

* Add test

Signed-off-by: Prithvi Raj <p.r@uber.com>

* Fix logic

Signed-off-by: Prithvi Raj <p.r@uber.com>
  • Loading branch information
vprithvi authored and yurishkuro committed Sep 5, 2019
1 parent ca64265 commit 7923eb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/samplers/remote_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -40,6 +41,7 @@ export default class RemoteControlledSampler implements Sampler {
_refreshInterval: number;
_host: string;
_port: number;
_samplingPath: string;
_maxOperations: number;

_onSamplerUpdate: ?Function;
Expand All @@ -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]
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/samplers/remote_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 7923eb2

Please sign in to comment.