This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
69 lines (63 loc) · 2.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const NS = 'plugin:publish-metrics';
const debug = require('debug')(NS);
const A = require('async');
const { createDatadogReporter } = require('./lib/datadog');
const { createHoneycombReporter } = require('./lib/honeycomb');
const { createLightstepReporter } = require('./lib/lightstep');
const { createMixPanelReporter } = require('./lib/mixpanel');
const { createPrometheusReporter } = require('./lib/prometheus');
const { createCloudWatchReporter } = require('./lib/cloudwatch');
module.exports = {
Plugin,
LEGACY_METRICS_FORMAT: false,
};
function Plugin(script, events) {
this.script = script;
this.events = events;
this.reporters = [];
(script.config.plugins['publish-metrics'] || []).forEach((config) => {
if (
config.type === 'datadog' ||
config.type === 'statsd' ||
config.type === 'influxdb-statsd'
) {
this.reporters.push(createDatadogReporter(config, events, script));
} else if (config.type === 'honeycomb') {
this.reporters.push(createHoneycombReporter(config, events, script));
} else if (config.type === 'lightstep') {
this.reporters.push(createLightstepReporter(config, events, script));
} else if (config.type === 'mixpanel') {
this.reporters.push(createMixPanelReporter(config, events, script));
} else if (config.type === 'prometheus') {
this.reporters.push(createPrometheusReporter(config, events, script));
} else if (config.type === 'cloudwatch') {
this.reporters.push(createCloudWatchReporter(config, events, script));
} else {
events.emit(
'userWarning',
`Reporting type "${config.type}" is not recognized.`,
{
type: 'plugin',
id: NS,
}
);
}
});
return this;
}
Plugin.prototype.cleanup = function (done) {
A.eachSeries(
this.reporters,
(reporter, next) => {
reporter.cleanup(() => {
next();
});
},
() => {
return done();
}
);
};