From 90346b65d7508cb5253c5cd32e8813e5dfa04aaa Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Fri, 7 Jul 2023 16:20:36 +0200 Subject: [PATCH] Use browsertime runTime for Graphite/Influx and Grafana annotations and data. (#3900) * Use browsertime runTime for Graphite/Influx and Grafana anootations and data. The old implementation always used the start time for all metrics sent except browsertime.run metrics (data for each run). This fix instead makes sure that if metrics (and annotations) uses the browsertime.pageSummary runTime (when the actual first iteration happen). This makes more sense if you test multiple pages within the same test. --- lib/plugins/grafana/index.js | 10 +++++++++- lib/plugins/graphite/index.js | 19 +++++++++++++++---- lib/plugins/influxdb/index.js | 6 +++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/plugins/grafana/index.js b/lib/plugins/grafana/index.js index 30648f973..1748abcba 100644 --- a/lib/plugins/grafana/index.js +++ b/lib/plugins/grafana/index.js @@ -1,3 +1,5 @@ +import dayjs from 'dayjs'; + import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { send } from './send-annotation.js'; @@ -90,13 +92,19 @@ export default class GrafanaPlugin extends SitespeedioPlugin { this.alias[message.url] ); this.receivedTypesThatFireAnnotations[message.url] = 0; + + const timestamp = + message.type === 'browsertime.pageSummary' + ? dayjs(message.runTime) + : this.timestamp; + return send( message.url, message.group, absolutePagePath, this.useScreenshots, this.screenshotType, - this.timestamp, + timestamp, this.tsdbType, this.alias, this.wptExtras[message.url], diff --git a/lib/plugins/graphite/index.js b/lib/plugins/graphite/index.js index 49403fc44..e82cc9b50 100644 --- a/lib/plugins/graphite/index.js +++ b/lib/plugins/graphite/index.js @@ -149,11 +149,16 @@ export default class GraphitePlugin extends SitespeedioPlugin { // TODO Here we could add logic to either create a new timestamp or // use the one that we have for that run. Now just use the one for the // run + let timestamp = this.timestamp; + if ( + message.type === 'browsertime.run' || + message.type === 'browsertime.pageSummary' + ) { + timestamp = dayjs(message.runTime); + } const dataPoints = this.dataGenerator.dataFromMessage( message, - message.type === 'browsertime.run' - ? dayjs(message.runTime) - : this.timestamp, + timestamp, this.alias ); @@ -176,13 +181,19 @@ export default class GraphitePlugin extends SitespeedioPlugin { message.url, this.alias[message.url] ); + + const timestamp = + message.type === 'browsertime.pageSummary' + ? dayjs(message.runTime) + : this.timestamp; + return send( message.url, message.group, absolutePagePath, this.useScreenshots, this.screenshotType, - this.timestamp, + timestamp, this.alias, this.wptExtras[message.url], this.usingBrowsertime, diff --git a/lib/plugins/influxdb/index.js b/lib/plugins/influxdb/index.js index 47fb8171f..a80ee8b64 100644 --- a/lib/plugins/influxdb/index.js +++ b/lib/plugins/influxdb/index.js @@ -1,5 +1,7 @@ import isEmpty from 'lodash.isempty'; import intel from 'intel'; +import dayjs from 'dayjs'; + import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { InfluxDBSender as Sender } from './sender.js'; import { InfluxDB2Sender as SenderV2 } from './senderV2.js'; @@ -125,7 +127,9 @@ export default class InfluxDBPlugin extends SitespeedioPlugin { let data = this.dataGenerator.dataFromMessage( message, - this.timestamp, + message.type === 'browsertime.pageSummary' + ? dayjs(message.runTime) + : this.timestamp, this.alias );