Allow instrumentation to be turned on using .ember-cli#7491
Allow instrumentation to be turned on using .ember-cli#7491hjdivad merged 2 commits intoember-cli:masterfrom
Conversation
| let instrumentationEnabled = utilsInstrumentation.instrumentationEnabled; | ||
|
|
||
| function _enableFSMonitorIfInstrumentationEnabled() { | ||
| function _enableFSMonitorIfInstrumentationEnabled(config) { |
There was a problem hiding this comment.
Need to be able to pass the config in here so we can "mock" it in tests? Is this a smell or okay to do?
| return cli.instrumentation; | ||
| } | ||
|
|
||
| let Instrumentation = require('./instrumentation'); |
There was a problem hiding this comment.
I needed to move the Instrumentation require inline otherwise it blew up on init due to circular dependencies between Instrumentation => getConfig => Project => Instrumentation and things not being fully set up.
There was a problem hiding this comment.
Can we add a comment that describes this?
Also note the only reason we need the project in get-config is to get the project root, so it's more immediately clear to a future traveler what they would need to tackle if they wanted to change things.
lib/utilities/get-config.js
Outdated
| primary: Project.getProjectRoot(), | ||
| }); | ||
|
|
||
| module.exports = function getConfig(mockedConfig) { |
There was a problem hiding this comment.
allow passing in a mocked config to support current mocking behavior in some tests
There was a problem hiding this comment.
Super minor, but within here can we call it configOverride instead of mockedConfig?
| beforeEach(function() { | ||
| expect(!!process.env.BROCCOLI_VIZ).to.eql(false); | ||
| expect(!!process.env.EMBER_CLI_INSTRUMENTATION).to.eql(false); | ||
| expect(fs.statSync).to.equal(originalStatSync); |
There was a problem hiding this comment.
Assert that we always start with clean slate on fs.statSync
| }); | ||
|
|
||
| afterEach(function() { | ||
| fs.statSync = originalStatSync; |
There was a problem hiding this comment.
Reset fs.statSync to its original state
There was a problem hiding this comment.
Let's not do this; we should instead fix heimdall-fs-monitor
| process.env.EMBER_CLI_INSTRUMENTATION = '1'; | ||
| let monitor = Instrumentation._enableFSMonitorIfInstrumentationEnabled(); | ||
| try { | ||
| expect(fs.statSync).to.not.equal(originalStatSync); |
There was a problem hiding this comment.
This test fails due to heimdall-fs-monitor not fully cleaning up after itself. Some module level variables are set in a previous test which cause it be isEnabled already. This means when calling FSMonitor() a second time, it doesn't re-"attach" the monitor functions around the fs functions.
There was a problem hiding this comment.
okay it looks like this problem in heimdall-fs-monitor was actually fixed a while ago. I've released 0.2.0 to deal with stop not cleaning up properly.
hjdivad
left a comment
There was a problem hiding this comment.
Couple of very minor suggestions but otherwise LGTM (sans greening up tests of course)
| let instrumentationEnabled = utilsInstrumentation.instrumentationEnabled; | ||
|
|
||
| function _enableFSMonitorIfInstrumentationEnabled() { | ||
| function _enableFSMonitorIfInstrumentationEnabled(config) { |
| return cli.instrumentation; | ||
| } | ||
|
|
||
| let Instrumentation = require('./instrumentation'); |
There was a problem hiding this comment.
Can we add a comment that describes this?
Also note the only reason we need the project in get-config is to get the project root, so it's more immediately clear to a future traveler what they would need to tackle if they wanted to change things.
lib/utilities/get-config.js
Outdated
| primary: Project.getProjectRoot(), | ||
| }); | ||
|
|
||
| module.exports = function getConfig(mockedConfig) { |
There was a problem hiding this comment.
Super minor, but within here can we call it configOverride instead of mockedConfig?
| }); | ||
|
|
||
| afterEach(function() { | ||
| fs.statSync = originalStatSync; |
There was a problem hiding this comment.
Let's not do this; we should instead fix heimdall-fs-monitor
| process.env.EMBER_CLI_INSTRUMENTATION = '1'; | ||
| let monitor = Instrumentation._enableFSMonitorIfInstrumentationEnabled(); | ||
| try { | ||
| expect(fs.statSync).to.not.equal(originalStatSync); |
There was a problem hiding this comment.
okay it looks like this problem in heimdall-fs-monitor was actually fixed a while ago. I've released 0.2.0 to deal with stop not cleaning up properly.
|
@patocallaghan updated heimdall-fs-monitor on your branch; |
|
Appreciate the feedback @hjdivad. Will fix up per your comments. |
33141d2 to
f88c4a2
Compare
|
|
||
| before(function() { | ||
| settings = new Yam('ember-cli', { | ||
| let mockedYam = new Yam('ember-cli', { |
There was a problem hiding this comment.
Needed to slightly refactor this test to get it to pass.
lib/utilities/get-config.js
Outdated
| if (configOverride) { | ||
| return configOverride; | ||
| } | ||
| return new Yam('ember-cli', { |
There was a problem hiding this comment.
I needed to bring the new Yam() into the getConfig function because it was failing the tests/acceptance/pods-destroy-test.js tests otherwise. Preferably the new Yam would happen at the module scope but in the pod-destroy tests the config wasn't being re-calculated after modifying the .ember-cli file.
|
@hjdivad made some changes per your feedback. Also tests should be 🍏 now. |
f88c4a2 to
0e8853e
Compare
|
@hjdivad I just did rebase against current master and the branch is still 🍏 |
lib/models/project.js
Outdated
| return cli.instrumentation; | ||
| } | ||
|
|
||
| // Instrumentation `require` needs to occur inline due to circular dependencies between Instrumentation => getConfig => Project => Instrumentation. getConfig is used in Project to get the project root. |
There was a problem hiding this comment.
sorry for nitpicking but could you wrap break this comment into separate lines, around 80 characters long?
lib/utilities/instrumentation.js
Outdated
|
|
||
| function instrumentationEnabled() { | ||
| return vizEnabled() || process.env.EMBER_CLI_INSTRUMENTATION === '1'; | ||
| function isConfigEnabled(configOverride) { |
There was a problem hiding this comment.
maybe better to name it isInstrumetationConfigEnabled?
0e8853e to
4f76e86
Compare
lib/utilities/get-config.js
Outdated
| if (configOverride) { | ||
| return configOverride; | ||
| } | ||
| return new Yam('ember-cli', { |
There was a problem hiding this comment.
should we load a new Yam on each invocation of getConfig, or memoize?
There was a problem hiding this comment.
@stefanpenner I'd initially tried have the new Yam line at the module level but had to refactor because tests which relied on mocking the config failed (pod tests I believe). I can't remember the specific reasoning but I'll have another go and see.
hjdivad
left a comment
There was a problem hiding this comment.
LGTM although it'd be good to look into @stefanpenner's comment re Yam instances
|
thanks @patocallaghan! |
|
@stefanpenner @hjdivad I've just pushed a little spike of memoizing the ember-cli/tests/acceptance/pods-destroy-test.js Lines 133 to 142 in 6fe4412 When the test is initially run the But as we've memoized the config on module load we don't have a Yam with I've added some sort of solution but to be honest it feels really wrong. When in test mode it generates a new Yam but when not it uses the memoized one. There's a precedent for this elsewhere in the tests but it still doesn't make it right 😄 If anyone has any suggestions for a better approach I'm all ears :) |
ab1d50c to
fa901c2
Compare
|
@stefanpenner @hjdivad @twokul any thoughts re my last comment here? Happy to rethink the testing if it's not acceptable. FYI I rebased against master and now the branch is failing. It appears master is also failing with the same error. |
lib/utilities/get-config.js
Outdated
|
|
||
| let config = generateConfig(); | ||
|
|
||
| module.exports = function getConfig(configOverride, shouldRegenerateConfig) { |
There was a problem hiding this comment.
instead of adding another parameter for this, what do you think about exporting a separate reset function for tests?
in es6 this would be a non default export, but in this case it should be fine to hang it off the default export. eg
let config;
module.exports = function getConfig(configOverride) {
if (configOverride) {
return configOverride;
}
if (config === undefined) {
config = generateConfig();
}
return config;
}
// private; used in testing
module.exports._reset = function() {
config = undefined;
}There was a problem hiding this comment.
I'll give that a shot. Thanks 👍
There was a problem hiding this comment.
@hjdivad it turns out the problematic tests were actually removed in a recent commit 😄 So there's no longer a need to jump through hoops to get the suite to pass. Tests are 🍏 locally and the config memoization works.
There was a problem hiding this comment.
oh nice; so if you rebase and push we should expect the PR to be green then
There was a problem hiding this comment.
it looks like master is still 🔴
There was a problem hiding this comment.
I think these tests we just moved into ember-source so that is why we're seeing the failures over there now when upgrading ember-cli.
@patocallaghan if it suits, let's have a chat about this tomorrow
fa901c2 to
5bed858
Compare
|
is there a downside to not memoizing? |
5bed858 to
d284dc8
Compare
|
@stefanpenner I guess the downside would be that we're creating new |
d284dc8 to
ca48df5
Compare
|
@hjdivad and @stefanpenner I've rebased again and the PR is now 🍏 |
|
thanks @patocallaghan! |
|
This appears to break some generators which use |
Addresses #7429
This is a WIP so hoping to get some feedback. I'm open to changing the namings + approach if required. What I initially thought to be straightforward has turned into somewhat of a rabbit-hole 😄
Yamconfig for the project out toutilities/get-config.utiltities/instrumentationmeant needing to move some things around as there are circular dependencies between Instrumentation => Project => Instrumentation. Otherwise it would blow up on init.yamwhereby a falsey value returnsundefined. I have a fix here [FIX] Fix issue where falsey property is returned as undefined twokul/yam#16_enableFSMonitorIfInstrumentationEnabledtests inmodels/instrumentation-test.jsare not atomic. Usingheimdall-fs-monitorto wrap aroundfs.statSyncdoesn't clean up after itself so affects later tests.ember-cli/tests/unit/models/instrumentation-test.js
Lines 36 to 83 in d9c0159
fs.statSyncback to it's initial state after each test and 2) callingFSMonitor()sets some module-level vars inheimdall-fs-monitor(isFirstInstance,isMonitorRegistrant) which means trying to set upFSMonitor()in a following test doesn't fully work. It doesn't re-"attach" the monitor functions.Any feedback on the approach in general is appreciated. Also any ideas how to workaround around the
heimdall-fs-monitortesting issue. I could submit a PR to fix that repo too if useful?