Skip to content

Commit

Permalink
feat(publish-metrics): fail early if required config missing (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
InesNi authored Aug 16, 2023
1 parent 338b070 commit 7871d39
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
12 changes: 6 additions & 6 deletions packages/artillery-plugin-publish-metrics/lib/dynatrace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const debug = require('debug')('plugin:publish-metrics:dynatrace');

class DynatraceReporter {
constructor(config, events, script) {
if (!config.apiToken || !config.envUrl) {
throw new Error(
'Dynatrace reporter: both apiToken and envUrl must be set. More info in the docs (https://docs.art/reference/extensions/publish-metrics#dynatrace)'
);
}

this.config = {
apiToken: config.apiToken,
envUrl: config.envUrl,
Expand All @@ -14,12 +20,6 @@ class DynatraceReporter {
dimensions: this.parseDimensions(config.dimensions)
};

if (!config.apiToken || !config.envUrl) {
throw new Error(
'Dynatrace API Access Token or Environment URL not specified. In order to send metrics to Dynatrace both `apiToken` and `envUrl` must be set'
);
}

// Configure event if set - if event key is set but its value isn't we use defaults
if (config.hasOwnProperty('event')) {
this.eventConfig = {
Expand Down
5 changes: 5 additions & 0 deletions packages/artillery-plugin-publish-metrics/lib/honeycomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const { URL } = require('url');

class HoneycombReporter {
constructor(config, events, script) {
if (!config.apiKey || !config.writeKey) {
throw new Error(
'Honeycomb reporter: apiKey or writeKey must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#honeycomb)'
);
}
this.hnyOpts = {
writeKey: config.apiKey || config.writeKey,
dataset: config.dataset,
Expand Down
6 changes: 6 additions & 0 deletions packages/artillery-plugin-publish-metrics/lib/lightstep.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const { URL } = require('url');

class LightstepReporter {
constructor(config, events, script) {
if (!config.accessToken || !config.componentName) {
throw new Error(
'Lightstep reporter: accessToken and componentName must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#lightstep)'
);
}
this.lightstepOpts = {
accessToken: config.accessToken,
componentName: config.componentName,
Expand Down Expand Up @@ -45,6 +50,7 @@ class LightstepReporter {
component_name: this.lightstepOpts.componentName,
access_token: this.lightstepOpts.accessToken
});

opentracing.initGlobalTracer(this.tracer);

attachScenarioHooks(script, [
Expand Down
9 changes: 6 additions & 3 deletions packages/artillery-plugin-publish-metrics/lib/mixpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const debug = require('debug')('plugin:publish-metrics:mixpanel');

class MixPanelReporter {
constructor(config, events, script) {
if (!config.projectToken) {
throw new Error(
'Mixpanel reporter: projectToken must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#mixpanel)'
);
}
this.mixPanelOpts = {
projectToken: config.projectToken
};
Expand All @@ -15,9 +20,7 @@ class MixPanelReporter {
})`
);
}
if (!this.mixPanelOpts.projectToken) {
console.error('mix panel project token not specified');
}

this.mixpanel = Mixpanel.init(this.mixPanelOpts.projectToken);
this.sendToMixPanel(config, events, script);
debug('init done');
Expand Down
12 changes: 6 additions & 6 deletions packages/artillery-plugin-publish-metrics/lib/newrelic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const debug = require('debug')('plugin:publish-metrics:newrelic');

class NewRelicReporter {
constructor(config, events, script) {
if (!config.licenseKey) {
throw new Error(
'New Relic reporter: licenseKey must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#newrelic)'
);
}

// Set each config value as matching user config if exists, else default values
this.config = {
region: config.region || 'us',
Expand All @@ -13,12 +19,6 @@ class NewRelicReporter {
licenseKey: config.licenseKey
};

if (!config.licenseKey) {
throw new Error(
'New Relic License Key not specified. In order to send metrics to New Relic `licenseKey` must be provided'
);
}

if (config.hasOwnProperty('event') && !config.event?.accountId) {
throw new Error(
'New Relic account ID not specified. In order to send events to New Relic `accountId` must be provided'
Expand Down
10 changes: 5 additions & 5 deletions packages/artillery-plugin-publish-metrics/lib/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const COUNTERS_STATS = 'counters', // counters stats

class PrometheusReporter {
constructor(config, events) {
if (!config.pushgateway) {
throw new Error(
'Prometheus reporter: pushgateway must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#prometheus-pushgateway)'
);
}
this.hasPendingRequest = false;
this.workerID = process.env.WORKER_ID || uuid.v4();
this.config = Object.assign(
Expand All @@ -26,11 +31,6 @@ class PrometheusReporter {
ca: config.ca
};

debug('ensuring pushgatewayUrl is configured');
if (!this.prometheusOpts.pushgatewayUrl) {
console.error(`the prometheus [pushgateway] url was not specified`);
}

debug('setting default labels');
PromClient.register.setDefaultLabels(this.tagsToLabels(this.config.tags));

Expand Down
10 changes: 8 additions & 2 deletions packages/artillery-plugin-publish-metrics/lib/splunk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const debug = require('debug')('plugin:publish-metrics:splunk');

class SplunkReporter {
constructor(config, events, script) {
if (!config.accessToken) {
throw new Error(
'Splunk reporter: accessToken must be provided. More info in the docs (https://docs.art/reference/extensions/publish-metrics#splunk)'
);
}

this.config = {
realm: config.realm || 'us0',
prefix: config.prefix || 'artillery.',
Expand All @@ -18,7 +24,7 @@ class SplunkReporter {
// Event API endpoint requires request payload to be an array of objects
this.eventOpts = [
{
eventType: config.event.eventType || `Artillery_io_Test`,
eventType: config.event.eventType || 'Artillery_io_Test',
dimensions: {
target: script.config.target,
...this.parseDimensions(config.event.dimensions)
Expand Down Expand Up @@ -217,7 +223,7 @@ class SplunkReporter {
if (this.startedEventSent) {
const timestamp = Date.now();
this.eventOpts[0].timestamp = timestamp;
this.eventOpts[0].dimensions.phase = `Test-Finished`;
this.eventOpts[0].dimensions.phase = 'Test-Finished';

this.sendRequest(this.ingestAPIEventEndpoint, this.eventOpts, 'event');
}
Expand Down

0 comments on commit 7871d39

Please sign in to comment.