From 961e764037606d6b80e4872ca35eaacfd12eb9ae Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Thu, 10 Feb 2022 14:21:44 -0800 Subject: [PATCH] Move sending root event to own script --- circle.yml | 2 +- system-tests/lib/performance-reporter.js | 42 +++++++++---------- .../scripts/send-root-honecomb-event.js | 13 ++++++ 3 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 system-tests/scripts/send-root-honecomb-event.js diff --git a/circle.yml b/circle.yml index c6593af628a1..90f381d5ad91 100644 --- a/circle.yml +++ b/circle.yml @@ -208,7 +208,7 @@ commands: - v{{ .Environment.CACHE_VERSION }}-{{ arch }}-system-tests-projects-node-modules-cache-state-{{ checksum "system_tests_cache_key" }} - run: name: Send root honeycomb event for this CI build - command: cd system-tests/lib && node ./performance-reporter.js + command: cd system-tests/scripts && node ./send-root-honecomb-event.js - run: name: Bail if specific cache exists command: | diff --git a/system-tests/lib/performance-reporter.js b/system-tests/lib/performance-reporter.js index 2a453e4b8099..22339fdd1cbb 100644 --- a/system-tests/lib/performance-reporter.js +++ b/system-tests/lib/performance-reporter.js @@ -12,16 +12,32 @@ const honey = new Libhoney({ writeKey: process.env.HONEYCOMB_API_KEY, }) +// This event is created here independently every time the reporter +// is imported (in each parallel instance of the system-tests +// in circleci) so that we can use it as the parent, +// but ../scripts/send-root-honeycomb-event.js +// is only invoked once at the start of the build, +// and is responsible for sending it to honeycomb. const spanId = process.env.CIRCLE_WORKFLOW_ID || uuidv4() const circleCiRootEvent = honey.newEvent() +circleCiRootEvent.timestamp = Date.now() +circleCiRootEvent.add({ + buildUrl: process.env.CIRCLE_BUILD_URL, + platform: process.platform, + arch: process.arch, + + spanId, + traceId: spanId, +}) + // Mocha events ('test', 'test end', etc) have no way to wait // for async callbacks, so we can't guarantee we have this // data ready by the time any of the reporter's events are emitted. // Therefore, we have each honeycomb event await this promise // before sending itself. -let asyncInfo = Promise.all([getNextVersionForPath('../../packages'), commitInfo()]) +let asyncInfo = Promise.all([getNextVersionForPath(path.resolve(__dirname, '../../packages')), commitInfo()]) .then(([nextVersion, commitInformation]) => { const ciInformation = ciProvider.commitParams() || {} @@ -39,26 +55,6 @@ function addAsyncInfoAndSend (honeycombEvent) { }) } -circleCiRootEvent.timestamp = Date.now() -circleCiRootEvent.add({ - buildUrl: process.env.CIRCLE_BUILD_URL, - platform: process.platform, - arch: process.arch, - - spanId, - traceId: spanId, -}) - -// This file is executed once as a script at the beginning of the circleci build, -// so that we can send the root event exactly once and associate all the various -// system test tasks and build steps into a single span. -if (require.main === module) { - addAsyncInfoAndSend(circleCiRootEvent).then(() => { - console.log(circleCiRootEvent.data) - honey.flush() - }) -} - class HoneycombReporter { constructor (runner) { if (!process.env.HONEYCOMB_API_KEY) { @@ -148,3 +144,7 @@ class HoneycombReporter { } module.exports = HoneycombReporter + +HoneycombReporter.honey = honey +HoneycombReporter.circleCiRootEvent = circleCiRootEvent +HoneycombReporter.addAsyncInfoAndSend = addAsyncInfoAndSend diff --git a/system-tests/scripts/send-root-honecomb-event.js b/system-tests/scripts/send-root-honecomb-event.js new file mode 100644 index 000000000000..e3dc7bcdc67f --- /dev/null +++ b/system-tests/scripts/send-root-honecomb-event.js @@ -0,0 +1,13 @@ +const { addAsyncInfoAndSend, circleCiRootEvent, honey } = require('../lib/performance-reporter') + +// This file is executed once during the circleci build, +// so that we can send the root event honeycomb event for this +// run of the system tests exactly once. +// All the system test build hosts reference this root event, +// joining them into a single trace. +if (require.main === module) { + addAsyncInfoAndSend(circleCiRootEvent).then(() => { + console.log(circleCiRootEvent.data) + honey.flush() + }) +}