Skip to content
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

Merged
merged 4 commits into from
Aug 31, 2018
Merged

Conversation

MatthewJWalls
Copy link
Contributor

@MatthewJWalls MatthewJWalls commented Aug 24, 2018

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:

  • maxHeapMemory
  • freeDiskSpace
  • usedHeapMemory
  • freePhysicalMemory
  • totalPhysicalMemory

Why?

All frontend services should log out these core health metrics so that we can use them to diagnose production issues.

@MatthewJWalls
Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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) {
Copy link
Contributor

@SiAdcock SiAdcock Aug 28, 2018

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) => {
 // ... 
};

Copy link
Contributor Author

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.

Copy link
Contributor

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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this better?

Copy link
Contributor Author

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

Copy link
Contributor

@SiAdcock SiAdcock Aug 28, 2018

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;
Copy link
Contributor

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.

@MatthewJWalls
Copy link
Contributor Author

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(
Copy link
Contributor

@SiAdcock SiAdcock Aug 28, 2018

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()

?

Copy link
Contributor

@SiAdcock SiAdcock left a 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 👍

@MatthewJWalls
Copy link
Contributor Author

I'm going to rebase this branch and then merge it, and take the convention issues offline.

@MatthewJWalls MatthewJWalls merged commit 2d7497a into master Aug 31, 2018
@MatthewJWalls MatthewJWalls deleted the cloudwatch-metrics branch August 31, 2018 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants