Skip to content

Commit e22f369

Browse files
authored
feat(fargate): use adot image for otel (#2481)
1 parent 018c917 commit e22f369

File tree

17 files changed

+1006
-137
lines changed

17 files changed

+1006
-137
lines changed

package-lock.json

+5-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/artillery-plugin-publish-metrics/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const NS = 'plugin:publish-metrics';
66
const debug = require('debug')(NS);
77
const A = require('async');
88

9+
const {
10+
getADOTRelevantReporterConfigs,
11+
resolveADOTConfigSettings
12+
} = require('./lib/open-telemetry/translators/vendor-adot');
13+
914
// List of reporters that use OpenTelemetry
1015
const REPORTERS_USING_OTEL = [
1116
'open-telemetry',
@@ -16,7 +21,9 @@ const REPORTERS_USING_OTEL = [
1621
];
1722
module.exports = {
1823
Plugin,
19-
LEGACY_METRICS_FORMAT: false
24+
LEGACY_METRICS_FORMAT: false,
25+
getADOTRelevantReporterConfigs,
26+
resolveADOTConfigSettings
2027
};
2128

2229
function Plugin(script, events) {

packages/artillery-plugin-publish-metrics/lib/open-telemetry/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const vendorTranslators = require('./vendor-translators');
3+
const { vendorTranslators } = require('./translators/vendor-otel');
44
const {
55
diag,
66
DiagConsoleLogger,
@@ -71,6 +71,7 @@ class OTelReporter {
7171
if (this.tracesConfig) {
7272
global.artillery.OTEL_TRACING_ENABLED = true;
7373
}
74+
7475
// Warn if traces are configured in multiple reporters
7576
this.warnIfDuplicateTracesConfigured(this.translatedConfigsList);
7677

@@ -156,6 +157,11 @@ class OTelReporter {
156157
if (!this.metricsConfig && !this.tracesConfig) {
157158
return done();
158159
}
160+
161+
// Waiting for flush period to complete here rather than in trace/metric reporters
162+
this.debug('Waiting for flush period to end');
163+
await new Promise((resolve) => setTimeout(resolve, 10000));
164+
159165
if (this.metricReporter) {
160166
await this.metricReporter.cleanup();
161167
}

packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/base.js

-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ class OTelTraceBase {
178178
}
179179

180180
this.debug('Pending traces done');
181-
this.debug('Waiting for flush period to complete');
182-
await sleep(5000);
183181
}
184182
}
185183

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
'use strict';
2+
3+
const ADOTSupportedTraceReporters = ['datadog'];
4+
const ADOTSupportedMetricReporters = [];
5+
6+
// Getting the relevant reporter configurations from full publish-metrics configuration
7+
8+
function getADOTRelevantReporterConfigs(publishMetricsConfig) {
9+
const configs = publishMetricsConfig.filter(
10+
(reporterConfig) =>
11+
(ADOTSupportedTraceReporters.includes(reporterConfig.type) &&
12+
reporterConfig.traces) ||
13+
(ADOTSupportedMetricReporters.includes(reporterConfig.type) &&
14+
reporterConfig.metrics)
15+
);
16+
17+
return configs;
18+
}
19+
20+
// Resolve the configuration settings for ADOT
21+
22+
function resolveADOTConfigSettings(options) {
23+
try {
24+
const adotConfig = getADOTConfig(options.configList); // options.configList ( array of those reporter configurations from publish-metrics config that require ADOT )
25+
const adotEnvVars = getADOTEnvVars(options.configList, options.dotenv); // options.dotenv (object with environment variables from user provided dotenv file)
26+
return { adotConfig, adotEnvVars };
27+
} catch (err) {
28+
throw new Error(err);
29+
}
30+
}
31+
32+
// Assembling the configuration for ADOT (in OTel Collector format)
33+
34+
function getADOTConfig(adotRelevantConfigs) {
35+
const translatedVendorConfigs = adotRelevantConfigs.map((config) =>
36+
vendorToCollectorConfigTranslators[config.type](config)
37+
);
38+
39+
// Different vendors can be used for metrics and tracing so we need to merge configs from each vendor into one collector config
40+
const finalADOTConfig = JSON.parse(JSON.stringify(collectorConfigTemplate));
41+
42+
translatedVendorConfigs.forEach((config) => {
43+
finalADOTConfig.processors = Object.assign(
44+
finalADOTConfig.processors,
45+
config.processors
46+
);
47+
finalADOTConfig.exporters = Object.assign(
48+
finalADOTConfig.exporters,
49+
config.exporters
50+
);
51+
finalADOTConfig.service.pipelines = Object.assign(
52+
finalADOTConfig.service.pipelines,
53+
config.service.pipelines
54+
);
55+
});
56+
return finalADOTConfig;
57+
}
58+
59+
const collectorConfigTemplate = {
60+
receivers: {
61+
otlp: {
62+
protocols: {
63+
http: {
64+
endpoint: '0.0.0.0:4318'
65+
},
66+
grpc: {
67+
endpoint: '0.0.0.0:4317'
68+
}
69+
}
70+
}
71+
},
72+
processors: {},
73+
exporters: {},
74+
service: {
75+
pipelines: {}
76+
}
77+
};
78+
79+
// Map of functions that translate vendor-specific configuration to OpenTelemetry Collector configuration to be used by ADOT
80+
const vendorToCollectorConfigTranslators = {
81+
datadog: (config) => {
82+
const collectorConfig = JSON.parse(JSON.stringify(collectorConfigTemplate));
83+
if (config.traces) {
84+
collectorConfig.processors['batch/trace'] = {
85+
timeout: '10s',
86+
send_batch_max_size: 1024,
87+
send_batch_size: 200
88+
};
89+
collectorConfig.exporters['datadog/api'] = {
90+
traces: {
91+
trace_buffer: 100
92+
},
93+
api: {
94+
key: '${env:DD_API_KEY}'
95+
}
96+
};
97+
collectorConfig.service.pipelines.traces = {
98+
receivers: ['otlp'],
99+
processors: ['batch/trace'],
100+
exporters: ['datadog/api']
101+
};
102+
}
103+
return collectorConfig;
104+
}
105+
};
106+
107+
// Handling vendor specific environment variables needed for ADOT configuration (e.g. Authentication keys/tokens that can be provided in the script )
108+
109+
function getADOTEnvVars(adotRelevantconfigs, dotenv) {
110+
const envVars = {};
111+
try {
112+
adotRelevantconfigs.forEach((config) => {
113+
const vendorVars = vendorSpecificEnvVarsForCollector[config.type](
114+
config,
115+
dotenv
116+
);
117+
Object.assign(envVars, vendorVars);
118+
});
119+
} catch (err) {
120+
// We warn here instead of throwing because in the future we will support providing these variables through secrets
121+
console.warn(err.message);
122+
}
123+
return envVars;
124+
}
125+
126+
const vendorSpecificEnvVarsForCollector = {
127+
datadog: (config, dotenv) => {
128+
const apiKey = config.apiKey || dotenv?.DD_API_KEY;
129+
// We validate API key here for Datadog (for now) because it is only required if Datadog tracing is set with test running on Fargate. (for local runs user configures their own agent, and for metrics if apiKey is not provided the reporter defaults to sending data to agent)
130+
if (!apiKey) {
131+
throw new Error(
132+
"Datadog reporter Error: Missing Datadog API key. Provide it under 'apiKey' setting in your script or under 'DD_API_KEY' environment variable set in your dotenv file."
133+
);
134+
}
135+
return { DD_API_KEY: apiKey };
136+
}
137+
};
138+
139+
module.exports = {
140+
getADOTRelevantReporterConfigs,
141+
resolveADOTConfigSettings,
142+
// All func and vars below exported for testing purposes
143+
getADOTEnvVars,
144+
vendorSpecificEnvVarsForCollector,
145+
getADOTConfig,
146+
vendorToCollectorConfigTranslators,
147+
ADOTSupportedTraceReporters,
148+
ADOTSupportedMetricReporters,
149+
collectorConfigTemplate
150+
};

packages/artillery-plugin-publish-metrics/lib/open-telemetry/vendor-translators.js packages/artillery-plugin-publish-metrics/lib/open-telemetry/translators/vendor-otel.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
// Map of functions that translate vendor-specific configuration to OpenTelemetry configuration
3+
// Map of functions that translate vendor-specific reporter configuration to OpenTelemetry reporter configuration
44
const vendorTranslators = {
55
honeycomb: (config) => {
66
if (config.enabled === false) {
@@ -115,4 +115,6 @@ function attributeListToObject(attributeList, reporterType) {
115115
return attributes;
116116
}
117117

118-
module.exports = vendorTranslators;
118+
module.exports = {
119+
vendorTranslators
120+
};

0 commit comments

Comments
 (0)