Skip to content

Commit 961e764

Browse files
committed
Move sending root event to own script
1 parent fa0b68a commit 961e764

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ commands:
208208
- v{{ .Environment.CACHE_VERSION }}-{{ arch }}-system-tests-projects-node-modules-cache-state-{{ checksum "system_tests_cache_key" }}
209209
- run:
210210
name: Send root honeycomb event for this CI build
211-
command: cd system-tests/lib && node ./performance-reporter.js
211+
command: cd system-tests/scripts && node ./send-root-honecomb-event.js
212212
- run:
213213
name: Bail if specific cache exists
214214
command: |

system-tests/lib/performance-reporter.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,32 @@ const honey = new Libhoney({
1212
writeKey: process.env.HONEYCOMB_API_KEY,
1313
})
1414

15+
// This event is created here independently every time the reporter
16+
// is imported (in each parallel instance of the system-tests
17+
// in circleci) so that we can use it as the parent,
18+
// but ../scripts/send-root-honeycomb-event.js
19+
// is only invoked once at the start of the build,
20+
// and is responsible for sending it to honeycomb.
1521
const spanId = process.env.CIRCLE_WORKFLOW_ID || uuidv4()
1622
const circleCiRootEvent = honey.newEvent()
1723

24+
circleCiRootEvent.timestamp = Date.now()
25+
circleCiRootEvent.add({
26+
buildUrl: process.env.CIRCLE_BUILD_URL,
27+
platform: process.platform,
28+
arch: process.arch,
29+
30+
spanId,
31+
traceId: spanId,
32+
})
33+
1834
// Mocha events ('test', 'test end', etc) have no way to wait
1935
// for async callbacks, so we can't guarantee we have this
2036
// data ready by the time any of the reporter's events are emitted.
2137

2238
// Therefore, we have each honeycomb event await this promise
2339
// before sending itself.
24-
let asyncInfo = Promise.all([getNextVersionForPath('../../packages'), commitInfo()])
40+
let asyncInfo = Promise.all([getNextVersionForPath(path.resolve(__dirname, '../../packages')), commitInfo()])
2541
.then(([nextVersion, commitInformation]) => {
2642
const ciInformation = ciProvider.commitParams() || {}
2743

@@ -39,26 +55,6 @@ function addAsyncInfoAndSend (honeycombEvent) {
3955
})
4056
}
4157

42-
circleCiRootEvent.timestamp = Date.now()
43-
circleCiRootEvent.add({
44-
buildUrl: process.env.CIRCLE_BUILD_URL,
45-
platform: process.platform,
46-
arch: process.arch,
47-
48-
spanId,
49-
traceId: spanId,
50-
})
51-
52-
// This file is executed once as a script at the beginning of the circleci build,
53-
// so that we can send the root event exactly once and associate all the various
54-
// system test tasks and build steps into a single span.
55-
if (require.main === module) {
56-
addAsyncInfoAndSend(circleCiRootEvent).then(() => {
57-
console.log(circleCiRootEvent.data)
58-
honey.flush()
59-
})
60-
}
61-
6258
class HoneycombReporter {
6359
constructor (runner) {
6460
if (!process.env.HONEYCOMB_API_KEY) {
@@ -148,3 +144,7 @@ class HoneycombReporter {
148144
}
149145

150146
module.exports = HoneycombReporter
147+
148+
HoneycombReporter.honey = honey
149+
HoneycombReporter.circleCiRootEvent = circleCiRootEvent
150+
HoneycombReporter.addAsyncInfoAndSend = addAsyncInfoAndSend
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { addAsyncInfoAndSend, circleCiRootEvent, honey } = require('../lib/performance-reporter')
2+
3+
// This file is executed once during the circleci build,
4+
// so that we can send the root event honeycomb event for this
5+
// run of the system tests exactly once.
6+
// All the system test build hosts reference this root event,
7+
// joining them into a single trace.
8+
if (require.main === module) {
9+
addAsyncInfoAndSend(circleCiRootEvent).then(() => {
10+
console.log(circleCiRootEvent.data)
11+
honey.flush()
12+
})
13+
}

0 commit comments

Comments
 (0)