-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement baseline cloudwatch metrics #154
Conversation
Since I don't work with js much I imagine there will be a lot of feedback for non-idiomatic code in here, if it's easier I'm willing to pair fixing this up with somebody! |
send: () => void, | ||
}; | ||
|
||
process.env.AWS_PROFILE = 'frontend'; |
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 used for? Note that environment variables set on process.env
are not available outside of the Node runtime
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 makes the node aws client library use the appropriate local aws credentials if they're available, so that it works locally on your machine if you're testing the production server.
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.
Okay. Do we always want to set this, or just when we're running the app locally?
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.
It should be ok to always set this, as aws credentials work essentially as a series of fallbacks - it should try your local aws profile first, then look for credentials in other standard places. That's how it works in scala too (if it doesn't work in production it should be a quick tweak to force it to look explicitly).
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, thanks for explaining, sounds good 👍
|
||
// handles sending matrics to AWS | ||
|
||
const Collector = function collectAndSendAWSMetrics(...metrics: Metric) { |
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.
For functions that are not constructor functions:
prefer using arrow functions(EDIT: only when defined inline as callbacks)- prefer (lower) camel case names
- for commands, prefer verb phrases
const collectAndSendAWSMetrics = (...metrics: Metric) => {
// ...
};
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.
Gotcha. I was following https://github.com/airbnb/javascript#functions but I might have missed something elsewhere.
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.
Interesting! Okay, let's stick with AirBnB's recos, ignore the arrow function point 😄
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 this better?
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.
Wasn't sure whether I should do:
const collectAndSendAWSMetrics = function collectAndSendAWSMetrics(...)
vs
const collectAndSendAWSMetrics = function(...)
The other functions use the former but it's a bit of duplication
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.
As per AirBnB, the function name ought to be descriptive and unique, whereas the const
name should be short. For example:
const sendMetrics = function collectAndSendAWSMetrics(...) { }
I'm not 100% sure I like it. It's hard enough to think of one function name let alone two! They have their reasons. I think we can do something a little more palatable. For now, let's leave it as is and take the discussion outside this PR.
})), | ||
); | ||
|
||
values.length = 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.
I did not know you could truncate an array like this! JS is full of surprises.
Forgot to mention but I also added a 'make logs' command that shows the pm2 logs which was super useful for testing. |
|
||
// to record memory or file sizes | ||
|
||
const BytesMetric = function BytesMetric( |
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 since this and TimingMetric
are not constructor functions, these should be lower camelcase also.
That said, they are serving as factory functions. Maybe we need a convention around these? What's better:
createBytesMetric()
bytesMetric()
?
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.
Happy for naming convention discussion to be taken offline, don't let me stop you merging this 👍
I'm going to rebase this branch and then merge it, and take the convention issues offline. |
What does this change?
Adds a node based implementation of our standard base cloudwatch metrics to the production server (we don't collect these in CODE)
These incliude:
Why?
All frontend services should log out these core health metrics so that we can use them to diagnose production issues.