Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Allow configuring http client timeout #465

Merged
merged 3 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ None of the env vars are required and all of them can be overridden via properti
| JAEGER_PASSWORD | Password to send as part of "Basic" authentication to the collector endpoint |
| JAEGER_REPORTER_LOG_SPANS | Whether the reporter should also log the spans |
| JAEGER_REPORTER_FLUSH_INTERVAL | The reporter's flush interval (ms) |
| JAEGER_REPORTER_TIMEOUT | The reporter's http timeout (ms) |
| JAEGER_SAMPLER_TYPE | The sampler type |
| JAEGER_SAMPLER_PARAM | The sampler parameter (number) |
| JAEGER_SAMPLER_MANAGER_HOST_PORT | The HTTP endpoint when using the remote sampler, i.e. http://jaeger-agent:5778/sampling |
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ let jaegerSchema = {
username: { type: 'string' },
password: { type: 'string' },
flushIntervalMs: { type: 'number' },
timeoutMs: { type: 'number' },
},
additionalProperties: false,
},
Expand Down Expand Up @@ -136,6 +137,9 @@ export default class Configuration {
if (config.reporter.password) {
senderConfig['password'] = config.reporter.password;
}
if (config.reporter.timeoutMs) {
senderConfig[ 'timeoutMs' ] = config.reporter.timeoutMs;
}
}
if (config.reporter.agentHost) {
senderConfig['host'] = config.reporter.agentHost;
Expand Down
9 changes: 9 additions & 0 deletions src/configuration_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ export default class ConfigurationEnv {
reporterConfig.agentHost = value;
}

value = ConfigurationEnv._getConfigValue(
config.reporter,
'timeoutMs',
process.env.JAEGER_REPORTER_TIMEOUT
);
if (value) {
reporterConfig.timeoutMs = parseInt(value);
}

value = ConfigurationEnv._getConfigValue(
config.reporter,
'agentPort',
Expand Down
6 changes: 3 additions & 3 deletions src/reporters/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class HTTPSender {
_username: string;
_password: string;
_emitSpanBatchOverhead: number;
_timeoutMS: number;
_timeoutMs: number;
_httpAgent: http$Agent;
_logger: Logger;
_jaegerThrift: Thrift;
Expand All @@ -46,7 +46,7 @@ export default class HTTPSender {
this._url = URL.parse(options.endpoint);
this._username = options.username;
this._password = options.password;
this._timeoutMS = options.timeoutMS || DEFAULT_TIMEOUT_MS;
this._timeoutMs = options.timeoutMs || options.timeoutMS || DEFAULT_TIMEOUT_MS;
this._httpAgent =
this._url.protocol === 'https:'
? new https.Agent({ keepAlive: true })
Expand All @@ -72,7 +72,7 @@ export default class HTTPSender {
Connection: 'keep-alive',
},
agent: this._httpAgent,
timeout: this._timeoutMS,
timeout: this._timeoutMs,
};
}

Expand Down
11 changes: 11 additions & 0 deletions test/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ describe('http sender', () => {
});
});

it('should use timeout provided', done => {
sender = new HTTPSender({
endpoint: serverEndpoint,
timeoutMs: 20,
});
sender.setProcess(reporter._process);

assert.equal(sender._timeoutMs, 20);
done();
});

it('should returns error from flush() on failed buffer conversion', done => {
let span = tracer.startSpan('leela');
span.finish(); // finish to set span duration
Expand Down
4 changes: 4 additions & 0 deletions test/init_tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ describe('initTracer', () => {
username: protocol === 'https' ? 'test' : undefined,
password: protocol === 'https' ? 'mypass' : undefined,
flushIntervalMs: 2000,
timeoutMs: 225,
},
};
let tracer = initTracer(config);
Expand All @@ -198,6 +199,7 @@ describe('initTracer', () => {
}

assert.equal(url.format(remoteReporter._sender._url), `${protocol}://127.0.0.1:4939/my/path`);
assert.equal(remoteReporter._sender._timeoutMs, 225);
assert.instanceOf(remoteReporter._sender, HTTPSender);
tracer.close(done);
});
Expand Down Expand Up @@ -502,6 +504,7 @@ describe('initTracerFromENV', () => {
process.env.JAEGER_SERVICE_NAME = 'test-service';
process.env.JAEGER_REPORTER_FLUSH_INTERVAL = 3000;
process.env.JAEGER_REPORTER_ENDPOINT = 'http://127.0.0.1:8080';
process.env.JAEGER_REPORTER_TIMEOUT = 225;
process.env.JAEGER_REPORTER_USER = 'test';
process.env.JAEGER_REPORTER_PASSWORD = 'xxxx';

Expand All @@ -512,6 +515,7 @@ describe('initTracerFromENV', () => {
assert.equal(tracer._reporter._sender._url.href, 'http://127.0.0.1:8080/');
assert.equal(tracer._reporter._sender._username, 'test');
assert.equal(tracer._reporter._sender._password, 'xxxx');
assert.equal(tracer._reporter._sender._timeoutMs, 225);

tracer.close(done);
});
Expand Down