Skip to content

Commit 0020017

Browse files
authored
Add 'metrics' flag to specify available metrics (#4)
* Add 'metrics' flag to specify available metrics * Rewrite flag and add a test * Workflows: add a flag 'influxdb.functions'
1 parent db71bd9 commit 0020017

File tree

4 files changed

+381
-12
lines changed

4 files changed

+381
-12
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
- name: Run test with Influx 1.8
4646
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --plugins.add ../../../lib/index.js
4747
- name: Run test with Influx 2.6.1
48-
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --influxdb.port 8087 --influxdb.version 2 --influxdb.organisation sitespeed --influxdb.token sitespeed --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --plugins.add ../../../lib/index.js
48+
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --influxdb.port 8087 --influxdb.version 2 --influxdb.organisation sitespeed --influxdb.token sitespeed --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --influxdb.functions='min,max' --plugins.add ../../../lib/index.js

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Store data in InfluxDB from sitespeed.io. This plugin was included in sitespeed.io before sitespeed.io 37 was released. After that version you need to install it yourself.
33

44
## Install the plugin
5-
If you use NodeJs the simplest way is to install the plugin globally: `npm install @sitespeed.io/plugin-influxdb -g`
5+
If you use Node.js the simplest way is to install the plugin globally: `npm install @sitespeed.io/plugin-influxdb -g`
66

77

88
## Run the plugin
9-
And then run sitespeed.io adding the pluging using the package name: `sitespeed.io --plugins.add @sitespeed.io/plugin-influxdb --influxdb.host YOUR_HOST https://www.sitespeed.io`
9+
And then run sitespeed.io adding the plugin using the package name: `sitespeed.io --plugins.add @sitespeed.io/plugin-influxdb --influxdb.host YOUR_HOST https://www.sitespeed.io`
1010

1111
## CLI help
1212
To see the command line options using help:

lib/data-generator.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function getAdditionalTags(key, type) {
154154
return tags;
155155
}
156156

157-
function getFieldAndSeriesName(key) {
157+
function getFieldAndSeriesName(key, options) {
158158
const functions = [
159159
'min',
160160
'p10',
@@ -168,12 +168,20 @@ function getFieldAndSeriesName(key) {
168168
'stddev',
169169
'rsd'
170170
];
171+
172+
const availableFunctions = options.influxdb.functions
173+
? options.influxdb.functions.split(',')
174+
: functions;
175+
171176
const keyArray = key.split('.');
172177
const end = keyArray.pop();
173-
if (functions.includes(end)) {
178+
if (availableFunctions.includes(end)) {
174179
return { field: end, seriesName: keyArray.pop() };
175180
}
176-
return { field: 'value', seriesName: end };
181+
if (!availableFunctions.includes(end) && !functions.includes(end)) {
182+
return { field: 'value', seriesName: end };
183+
}
184+
return {};
177185
}
178186
export class InfluxDBDataGenerator {
179187
constructor(includeQueryParameters, options) {
@@ -237,7 +245,7 @@ export class InfluxDBDataGenerator {
237245
}
238246
return Object.entries(flattenMessageData(message)).reduce(
239247
(entries, [key, value]) => {
240-
const fieldAndSeriesName = getFieldAndSeriesName(key);
248+
const fieldAndSeriesName = getFieldAndSeriesName(key, this.options);
241249
let tags = getTagsFromMessage(
242250
message,
243251
this.includeQueryParams,
@@ -249,11 +257,13 @@ export class InfluxDBDataGenerator {
249257
time: time.valueOf(),
250258
[fieldAndSeriesName.field]: value
251259
};
252-
entries.push({
253-
tags,
254-
seriesName: fieldAndSeriesName.seriesName,
255-
point
256-
});
260+
if (fieldAndSeriesName.seriesName !== undefined) {
261+
entries.push({
262+
tags,
263+
seriesName: fieldAndSeriesName.seriesName,
264+
point
265+
});
266+
}
257267
return entries;
258268
},
259269
[]

0 commit comments

Comments
 (0)