Skip to content

Commit

Permalink
Move sending root event to own script
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWinds committed Feb 10, 2022
1 parent fa0b68a commit 961e764
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
42 changes: 21 additions & 21 deletions system-tests/lib/performance-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() || {}

Expand All @@ -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) {
Expand Down Expand Up @@ -148,3 +144,7 @@ class HoneycombReporter {
}

module.exports = HoneycombReporter

HoneycombReporter.honey = honey
HoneycombReporter.circleCiRootEvent = circleCiRootEvent
HoneycombReporter.addAsyncInfoAndSend = addAsyncInfoAndSend
13 changes: 13 additions & 0 deletions system-tests/scripts/send-root-honecomb-event.js
Original file line number Diff line number Diff line change
@@ -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()
})
}

0 comments on commit 961e764

Please sign in to comment.