-
Notifications
You must be signed in to change notification settings - Fork 149
feat(#64) added multiple aggregate levels #66
feat(#64) added multiple aggregate levels #66
Conversation
lib/dashboard.js
Outdated
@@ -94,8 +100,8 @@ var VIEW_MAP = { | |||
eventLoop: EventLoopView | |||
}; | |||
|
|||
Dashboard.prototype._showLayout = function (id) { | |||
if (this.currentLayout === id) { | |||
Dashboard.prototype._showLayout = function (id, forced) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there another way to update the aggregate view without having to force a layout refresh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there is. I will work on it!
.vscode/launch.json
Outdated
@@ -0,0 +1,37 @@ | |||
{ | |||
// Use IntelliSense to learn about possible Node.js debug attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove these comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is a visual studio file - should add file/dir to .gitignore
lib/providers/metrics-provider.js
Outdated
|
||
screen.on("zoomAggregate", function zoomAggregate(zoom) { | ||
// apply zoom delta and check for boundaries | ||
this.currentAggregateZoom += zoom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just use something like lodash.clamp (https://lodash.com/docs/4.17.4#clamp) to enforce bounds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/providers/metrics-provider.js
Outdated
var MetricsProvider = function MetricsProvider(screen) { | ||
EventEmitter.call(this); | ||
// time scaling factors | ||
var timeScales = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be in constants.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
.vscode/launch.json
Outdated
@@ -0,0 +1,37 @@ | |||
{ | |||
// Use IntelliSense to learn about possible Node.js debug attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is a visual studio file - should add file/dir to .gitignore
Also, corrected the use of sinon-chai and fixed a cross-platform issue with mock-require. Included gulp and gulpfile for unit test debugging. New constants.js file for configuration. Lots of performance improvements and code cleanup in MetricsProvider aggregation logic. Lots of documentation for MetricsProvider.
gulpfile.js
Outdated
@@ -0,0 +1,9 @@ | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit here -- at least as a broad Formidable convention (and same for most of our clients), npm scripts have "won".
Gulp, while a great tool, has persistent problems of plugins being behind the "real" upstream projects and adding complexity / abstraction where it's not needed. Here, we just want to execute mocha. I vote we stick with mocha + package.json:scripts
until we hit a use case we truly can't support.
Side note -- if we need concurrent execution of things, we've got great tools for that that work with package.json:scripts
.
@jasonwilson -- Thoughts on ^^^ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can npm run scripts allow you to debug your spec files? If so, that is great. Otherwise, the only purpose for the gulp is for debugging unit tests and I can keep it out of the main repo.
Although, excluding it would make portability an issue across dev machines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, you can always use mocha
directly. Second npm scripts allow extra commands to punch to the command via --
. So, for example,
$ npm run test-only -- --grep=foo --ANY_OTHER_MOCHA_CLI_FLAG
works just fine.
Also, we write our npm package scripts to be the portable subset of shell commands that is universally (mac, win, linux) compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By dev machine, I really meant for those folks that might use VS code as their debugger, these tagalong files are helpful to include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with VS code's debugging, but I'd be surprised if generic gulp was supported and raw mocha wasn't. In any case, let's keep the main repo gulp-free to save on dependencies we don't strictly need 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Also sounds like I might have another interested party in learning debugging and using VS code?
I think you'll find it to be a really amazing editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is an Electron app, it is built on Node too, so this editor is perfectly adapted to Node development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, since you're not using VS code, what editor are you using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I have the solution I was looking for to remove the gulp and still get the debug ability.
https://gist.github.com/paambaati/54d33e409b4f7cf059cc
Up to date even!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use many, currently vs code. What I meant is that I don't use the integrated debugger -- typically when I need a debugger I just do the normal node flags and open up chrome.
Nice to see you found what you need and your preferred debugging solution is still available to you!
expect(metrics.mem.heapTotal).to.be.above(0); | ||
expect(metrics.mem.heapUsed).to.be.above(0); | ||
expect(metrics.cpu.utilization).to.be.above(0); | ||
expect(metrics.eventLoop.delay).to.be.a("number"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL SUGGESTION: I know this is a refactor, but for things like:
expect(metrics.eventLoop.delay).to.be.a("number");
if for example, metrics.eventLoop
is undefined
, you're going to get a not-so-useful assertion failure. A better way to do this is to assert on the property and let chai tell you "that deep property doesn't exist". Aka
expect(metrics).to.have.deep.property("eventLoop.delay").that.is.a("number");
(Side note -- unique to .property
assertions, the context changes from there on to the property asserted against (e.g. metrics.eventLoop.delay
) and not the original target object (e.g. metrics
))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, I like it.
test/lib/dashboard-agent.spec.js
Outdated
}; | ||
|
||
var stubProcess = sinon.stub(process, "memoryUsage", function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL: Never use sinon.stub|spy
on anything that requires a .restore()
. Instead, use a sandbox
which we declare at top scope for this test suite.
Here you've got a problem that if anything fails / errors in this test, you won't reach the .restore()
s on L99-L100. That means you have real methods potentially left unrestored that could cause unrelated tests to fail. Thus, you must always try/catch synchronous stubs to restore or do it in a beforeEach|afterEach
pair.
Since we already do this with a sandbox
, you can just use that to sandbox.stub
and never worry about the restore, since a global restore is done in the top-level afterEach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the sandbox but when the sandbox.restore() ran, the stub was still there. On other words, the sandbox did not work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can work together on Monday. A sandbox restores anything created with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, @jasonwilson and @aisapatino can help with this as they've both got a ton of experience with mocha + sandboxes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I know what I did wrong, instead of sandbox.stub() I used sinon.stub() and that would explain why it didn't go in the sandbox.
I'll correct this one, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I did notice was the sandbox create was in a before()
(pre-existing code). This may be problematic, and as a general rule for unit tests, beforeEach()
is almost always better than a before()
. before()
is typically reserved for super-expensive time-wise things, and I don't see that here. (Same for after()
)
test/lib/generate-layouts.spec.js
Outdated
@@ -149,6 +154,8 @@ describe("generate-layouts", function () { | |||
] | |||
} | |||
]]); | |||
|
|||
done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unnecessary.
}); | ||
} | ||
|
||
done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL: done()
should only be used for async callbacks. Everywhere that it's been added seems synchronous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I've always done the done() as a consistency thing, but easily removed!
}); | ||
|
||
beforeEach(function () { | ||
after(function (done) { | ||
done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
var sinon = require("sinon"); | ||
var sinonChai = require("sinon-chai"); | ||
var expect = chai.expect; | ||
chai.use(sinonChai); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL: This shouldn't be necessary -- this boilerplate is already taken care of in setup.js
https://github.com/FormidableLabs/nodejs-dashboard/blob/master/test/setup.js
I think maybe the gulp switch isn't using setup? At any rate go with how we already ran mocha from package.json scripts and should work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried npm run scripts in addition to gulp and the problem was still there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can work through it on Monday. If we've got you Slack access, just hit me or @jasonwilson up and we'll work it out.
And generally, speaking, anytime you're doing a repeated, fundamental change to a bunch of files, feel free to bounce that off of us early so we can possibly help debug things up front and save you some time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I wonder, and this could be a red herring, but is it possibly related to the order of the parameters on the npm script? I see a difference between the coverage script and test-only script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that, I see the commands aren't the same.
@ryan-roemer @jasonwilson @aisapatino I believe this is at last ready for final review :) |
@mscottx88 -- Great! I'll review for formalities / test stuff and @jasonwilson @aisapatino can do the substantive stuff in addition to that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there!
CHANGELOG.md
Outdated
@@ -1,5 +1,8 @@ | |||
# Change log | |||
|
|||
## [v0.5.1] - 2017-07-24 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Typically we do Unreleased
until we release. Here, it would seem our options should be MINOR (v0.4.2
) or MAJOR (v0.5.0
) in that v0.x.x
semver parlance or whatever 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i meant 5.0.0... sorry about that. Should I put Unreleased for now or leave CHANGLOG unchanged as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put Unreleased here. Leave package.json:version
unchanged from current master
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I will correct this one!
lib/constants.js
Outdated
|
||
// these define the time levels that data will be aggregated into | ||
// each number is in milliseconds | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Do the empty newline //
too, so that it reads as a contiguous "comment"
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "nodejs-dashboard", | |||
"version": "0.4.1", | |||
"version": "0.5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, typically we don't bump versions in PRs. Also, this differs from changelog entry.
package.json
Outdated
@@ -16,7 +16,7 @@ | |||
"test": "npm run lint && npm run test-only", | |||
"test-only": "mocha -c --require test/setup.js --recursive ./test", | |||
"test-app": "./bin/nodejs-dashboard.js node test/app/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR, but can you remove the prefix ./
in this command? ./
is unnecessary on mac/linux and breaks windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is weird. As is, with the ./
, I get the following error:
./bin/nodejs-dashboard.js node test/app/index.js
'.' is not recognized as an internal or external command,
operable program or batch file.
When I change it to not have the ./
I get this error instead:
[email protected] test-app C:\Users\formidable\Documents\nodejs-dashboard
bin/nodejs-dashboard.js node test/app/index.js
'bin' is not recognized as an internal or external command,
operable program or batch file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe my npm settings are incorrect. When I put node
in front, it works:
$ npm run test-app
[email protected] test-app C:\Users\formidable\Documents\nodejs-dashboard
node bin/nodejs-dashboard.js node test/app/index.js
Waiting for client connection on 9838...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryan-roemer Should/Could it be done as:
"test-app": "node bin/nodejs-dashboard.js -- node test/app/index.js",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonwilson -- Can you comment here? The problem is that bin/nodejs-dashboard.js
isn't a recognizable Windows cmd script.
I'm guessing we want:
node bin/nodejs-dashboard.js node test/app/index.js
but not totally sure...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that's what I ended up with too!
test/lib/generate-layouts.spec.js
Outdated
var mock = function (path, obj) { | ||
return mockRequire(process.cwd() + "/" + path, obj); | ||
return mockRequire(normalize(process.cwd() + "/" + path), obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing string concat with "/"
feels wrong.
Wouldn't
return mockRequire(path.resolve(path), obj);
solve all the problems we have here?
@ryan-roemer I reverted the version bump and changed from |
Woohoo! I figured out how to get the screen to update without the |
Do you mean, keep them as seconds until everything is evenly divisible by minutes, and so on? |
It turns out that 7.3m = 438s, both of which take up the same space on the screen 🤣 |
I mean so the units are fixed, whole number increments. For example: 1m 5m 10m 15m 20m 25m |
Time labels now appear like digital clocks.
I've got the new #67 ready to go, in a separate branch, but it relies on this one. |
The memory guage view was not getting its "metrics" events and appears frozen. Since it is not a historical graph, the "metrics" event needed to be emitted every time.
@jasonwilson @aisapatino Hi there, I was just following up on this PR. I have a few more branches/features I'd like to merge after this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple small changes then we're good to go!
@@ -1,5 +1,8 @@ | |||
# Change log | |||
|
|||
## [Unreleased] - 2017-07-24 | |||
- **Added:** Longer history for graphs [\#64] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to include the PR reference at the bottom of the file.
lib/providers/metrics-provider.js
Outdated
@@ -1,25 +1,500 @@ | |||
"use strict"; | |||
|
|||
/** | |||
* This module provides metric data for various data points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets put this writeup in a separate markdown file and abbreviate the explanation here.
@@ -71,6 +77,38 @@ BaseLineGraph.prototype.update = function (values) { | |||
this.node.setData(_.values(this.series)); | |||
}; | |||
|
|||
BaseLineGraph.prototype.changeMetricData = function (mapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway to have blessed fix the increments?
}; | ||
|
||
sandbox.stub(process, "memoryUsage", function () { | ||
return { | ||
systemTotal: 20, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@jasonwilson Corrected those, thanks for the recommendation on the separate MD. I was able to include some visuals which I really wanted to do anyway 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
🚀 |
@jasonwilson Here is the first go at this code. I need to add unit tests for the new work. If you get a moment, check it out and see what you think!