Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(otlp-exporter-base): fix handling of destroyed requests #4929

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,14 @@ describe('export - real http request destroyed before response received', () =>

setTimeout(() => {
collectorExporter.export(spans, result => {
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
const error = result.error as OTLPExporterError;
assert.ok(error !== undefined);
assert.strictEqual(error.message, 'Request Timeout');
try {
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
const error = result.error as OTLPExporterError;
assert.ok(error !== undefined);
assert.strictEqual(error.message, 'Request Timeout');
} catch (e) {
done(e);
}
Comment on lines +579 to +586
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewer note: i changed this test as to ensure it does not show up as timed out when assertions fail.

done();
});
}, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ import {
} from '../../is-export-retryable';
import { OTLPExporterError } from '../../types';

export const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
export const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
export const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;

Comment on lines -28 to -31
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewer note: this is unrelated. They're not used anymore, so I decided to remove them.

/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export function sendWithHttp(
params: HttpRequestParameters,
Expand Down Expand Up @@ -64,9 +61,6 @@ export function sendWithHttp(
res.on('data', chunk => responseData.push(chunk));

res.on('end', () => {
if (req.destroyed) {
return;
}
if (res.statusCode && res.statusCode < 299) {
onDone({
status: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as url from 'url';
import * as http from 'http';
import * as https from 'https';
import { OTLPExporterNodeConfigBase } from '.';
import { diag } from '@opentelemetry/api';

import { CompressionAlgorithm } from './types';
import { getEnv } from '@opentelemetry/core';

export function createHttpAgent(
config: OTLPExporterNodeConfigBase
): http.Agent | https.Agent | undefined {
if (config.httpAgentOptions && config.keepAlive === false) {
diag.warn('httpAgentOptions is used only when keepAlive is true');
return undefined;
}

if (config.keepAlive === false || !config.url) return undefined;

try {
const parsedUrl = new url.URL(config.url as string);
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
return new Agent({ keepAlive: true, ...config.httpAgentOptions });
} catch (err) {
diag.error(
`collector exporter failed to create http agent. err: ${err.message}`
);
return undefined;
}
}

export function configureCompression(
compression: CompressionAlgorithm | undefined
): CompressionAlgorithm {
Expand Down
Loading