Move graphite cli options to plugin (#2991)
* test(cli): add graphite coverage for current cli options * refactor(plugins/graphite): move CLI option definitions to plugin
This commit is contained in:
parent
7d9a647a99
commit
c750fe2b4a
|
|
@ -12,8 +12,8 @@ const findUp = require('find-up');
|
|||
const toArray = require('../support/util').toArray;
|
||||
|
||||
const grafanaPlugin = require('../plugins/grafana/index');
|
||||
const graphitePlugin = require('../plugins/graphite/index');
|
||||
|
||||
const graphiteConfig = require('../plugins/graphite/index').config;
|
||||
const influxdbConfig = require('../plugins/influxdb/index').config;
|
||||
const browsertimeConfig = require('../plugins/browsertime/index').config;
|
||||
const metricsConfig = require('../plugins/metrics/index').config;
|
||||
|
|
@ -861,95 +861,10 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
// Grafana CLI options
|
||||
cliUtil.registerPluginOptions(parsed, grafanaPlugin);
|
||||
|
||||
parsed
|
||||
/**
|
||||
Graphite cli option
|
||||
*/
|
||||
.option('graphite.host', {
|
||||
describe: 'The Graphite host used to store captured metrics.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.port', {
|
||||
default: graphiteConfig.port,
|
||||
describe: 'The Graphite port used to store captured metrics.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.auth', {
|
||||
describe:
|
||||
'The Graphite user and password used for authentication. Format: user:password',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.httpPort', {
|
||||
describe:
|
||||
'The Graphite port used to access the user interface and send annotations event',
|
||||
default: 8080,
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.webHost', {
|
||||
describe:
|
||||
'The graphite-web host. If not specified graphite.host will be used.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.namespace', {
|
||||
default: graphiteConfig.namespace,
|
||||
describe: 'The namespace key added to all captured metrics.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.includeQueryParams', {
|
||||
default: graphiteConfig.includeQueryParams,
|
||||
describe:
|
||||
'Whether to include query parameters from the URL in the Graphite keys or not',
|
||||
type: 'boolean',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.arrayTags', {
|
||||
default: true,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Send the tags as Array or a String. In Graphite 1.0 the tags is a array. Before a String',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.annotationTitle', {
|
||||
describe: 'Add a title to the annotation sent for a run.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.annotationMessage', {
|
||||
describe:
|
||||
'Add an extra message that will be attached to the annotation sent for a run. The message is attached after the default message and can contain HTML.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.annotationScreenshot', {
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Include screenshot (from Browsertime/WebPageTest) in the annotation. You need to specify a --resultBaseURL for this to work.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.statsd', {
|
||||
default: graphiteConfig.statsd,
|
||||
type: 'boolean',
|
||||
describe: 'Uses the StatsD interface',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.annotationTag', {
|
||||
describe:
|
||||
'Add a extra tag to the annotation sent for a run. Repeat the --graphite.annotationTag option for multiple tags. Make sure they do not collide with the other tags.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.bulkSize', {
|
||||
default: graphiteConfig.bulkSize,
|
||||
type: 'number',
|
||||
describe: 'Break up number of metrics to send with each request.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
.option('graphite.experimental.perIteration', {
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Experimental setup to send each iteration of metrics to Graphite. Experimental means this can change and is not released as stable. Use it with care.',
|
||||
group: 'Graphite'
|
||||
})
|
||||
// Graphite CLI options
|
||||
cliUtil.registerPluginOptions(parsed, graphitePlugin);
|
||||
|
||||
parsed
|
||||
/** Plugins */
|
||||
.option('plugins.list', {
|
||||
describe: 'List all configured plugins in the log.',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
module.exports = {
|
||||
host: {
|
||||
describe: 'The Graphite host used to store captured metrics.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
port: {
|
||||
default: 2003,
|
||||
describe: 'The Graphite port used to store captured metrics.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
auth: {
|
||||
describe:
|
||||
'The Graphite user and password used for authentication. Format: user:password',
|
||||
group: 'Graphite'
|
||||
},
|
||||
httpPort: {
|
||||
describe:
|
||||
'The Graphite port used to access the user interface and send annotations event',
|
||||
default: 8080,
|
||||
group: 'Graphite'
|
||||
},
|
||||
webHost: {
|
||||
describe:
|
||||
'The graphite-web host. If not specified graphite.host will be used.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
namespace: {
|
||||
default: 'sitespeed_io.default',
|
||||
describe: 'The namespace key added to all captured metrics.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
includeQueryParams: {
|
||||
default: false,
|
||||
describe:
|
||||
'Whether to include query parameters from the URL in the Graphite keys or not',
|
||||
type: 'boolean',
|
||||
group: 'Graphite'
|
||||
},
|
||||
arrayTags: {
|
||||
default: true,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Send the tags as Array or a String. In Graphite 1.0 the tags is a array. Before a String',
|
||||
group: 'Graphite'
|
||||
},
|
||||
annotationTitle: {
|
||||
describe: 'Add a title to the annotation sent for a run.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
annotationMessage: {
|
||||
describe:
|
||||
'Add an extra message that will be attached to the annotation sent for a run. The message is attached after the default message and can contain HTML.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
annotationScreenshot: {
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Include screenshot (from Browsertime/WebPageTest) in the annotation. You need to specify a --resultBaseURL for this to work.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
statsd: {
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
describe: 'Uses the StatsD interface',
|
||||
group: 'Graphite'
|
||||
},
|
||||
annotationTag: {
|
||||
describe:
|
||||
'Add a extra tag to the annotation sent for a run. Repeat the --graphite.annotationTag option for multiple tags. Make sure they do not collide with the other tags.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
bulkSize: {
|
||||
default: null,
|
||||
type: 'number',
|
||||
describe: 'Break up number of metrics to send with each request.',
|
||||
group: 'Graphite'
|
||||
},
|
||||
'experimental.perIteration': {
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
describe:
|
||||
'Experimental setup to send each iteration of metrics to Graphite. Experimental means this can change and is not released as stable. Use it with care.',
|
||||
group: 'Graphite'
|
||||
}
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const GraphiteSender = require('./graphite-sender');
|
||||
const StatsDSender = require('./statsd-sender');
|
||||
|
|
@ -11,20 +11,26 @@ const DataGenerator = require('./data-generator');
|
|||
const graphiteUtil = require('../../support/tsdbUtil');
|
||||
const isStatsd = require('./helpers/is-statsd');
|
||||
const throwIfMissing = require('../../support/util').throwIfMissing;
|
||||
|
||||
const defaultConfig = {
|
||||
port: 2003,
|
||||
namespace: 'sitespeed_io.default',
|
||||
includeQueryParams: false,
|
||||
statsd: false,
|
||||
bulkSize: null,
|
||||
perIteration: false
|
||||
};
|
||||
const cliUtil = require('../../cli/util');
|
||||
|
||||
module.exports = {
|
||||
name() {
|
||||
return path.basename(__dirname);
|
||||
},
|
||||
|
||||
/**
|
||||
* Define `yargs` options with their respective default values. When displayed by the CLI help message
|
||||
* all options are namespaced by its plugin name.
|
||||
*
|
||||
* @return {Object<string, require('yargs').Options} an object mapping the name of the option and its yargs configuration
|
||||
*/
|
||||
get cliOptions() {
|
||||
return require(path.resolve(__dirname, 'cli.js'));
|
||||
},
|
||||
|
||||
open(context, options) {
|
||||
throwIfMissing(options.graphite, ['host'], 'graphite');
|
||||
const opts = merge({}, defaultConfig, options.graphite);
|
||||
const opts = merge({}, this.config, options.graphite);
|
||||
this.options = options;
|
||||
this.perIteration = get(opts, 'experimental.perIteration', false);
|
||||
const SenderConstructor = isStatsd(opts) ? StatsDSender : GraphiteSender;
|
||||
|
|
@ -170,5 +176,8 @@ module.exports = {
|
|||
);
|
||||
}
|
||||
},
|
||||
config: defaultConfig
|
||||
|
||||
get config() {
|
||||
return cliUtil.pluginDefaults(this.cliOptions);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,5 +78,80 @@ describe('cli', () => {
|
|||
'Include screenshot (from Browsertime/WebPageTest) in the annotation. You need to specify a --resultBaseURL for this to work.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should contain graphite options', () => {
|
||||
expect(stdout).to.contain('--graphite.host');
|
||||
expect(stdout).to.contain(
|
||||
'The Graphite host used to store captured metrics.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.port');
|
||||
expect(stdout).to.contain(
|
||||
'The Graphite port used to store captured metrics.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.auth');
|
||||
expect(stdout).to.contain(
|
||||
'The Graphite user and password used for authentication. Format: user:password'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.httpPort');
|
||||
expect(stdout).to.contain(
|
||||
'The Graphite port used to access the user interface and send annotations event'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.webHost');
|
||||
expect(stdout).to.contain(
|
||||
'The graphite-web host. If not specified graphite.host will be used.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.namespace');
|
||||
expect(stdout).to.contain(
|
||||
'The namespace key added to all captured metrics.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.includeQueryParams');
|
||||
expect(stdout).to.contain(
|
||||
'Whether to include query parameters from the URL in the Graphite keys or not'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.arrayTags');
|
||||
expect(stdout).to.contain(
|
||||
'Send the tags as Array or a String. In Graphite 1.0 the tags is a array. Before a String'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.annotationTitle');
|
||||
expect(stdout).to.contain(
|
||||
'Add a title to the annotation sent for a run.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.annotationMessage');
|
||||
expect(stdout).to.contain(
|
||||
'Add an extra message that will be attached to the annotation sent for a run. The message is attached after the default message and can contain HTML.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.annotationScreenshot');
|
||||
expect(stdout).to.contain(
|
||||
'Include screenshot (from Browsertime/WebPageTest) in the annotation. You need to specify a --resultBaseURL for this to work.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.statsd');
|
||||
expect(stdout).to.contain('Uses the StatsD interface');
|
||||
|
||||
expect(stdout).to.contain('--graphite.annotationTag');
|
||||
expect(stdout).to.contain(
|
||||
'Add a extra tag to the annotation sent for a run. Repeat the --graphite.annotationTag option for multiple tags. Make sure they do not collide with the other tags.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.bulkSize');
|
||||
expect(stdout).to.contain(
|
||||
'Break up number of metrics to send with each request.'
|
||||
);
|
||||
|
||||
expect(stdout).to.contain('--graphite.experimental.perIteration');
|
||||
expect(stdout).to.contain(
|
||||
'Experimental setup to send each iteration of metrics to Graphite. Experimental means this can change and is not released as stable. Use it with care.'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue