The purpose of this lab is to expose students to the base concepts surrounding monitoring and code inspection using the New Relic nodejs agent to profile a GraphQL interface in the Apollo GraphQL Server.
- This lab requires that a student be able to signup for a basic New Relic account and configure a newrelic.js configuration file in the base directory of the project. (See the instructions below)
- As of the publication of this lab, the New Relic nodejs agent has suboptimal support for GraphQL libraries. Thus the additional code referencing the custom instrumentation capabilities in the New Relic nodejs agent that you'll find in the project code.
- All the data provided in
testdata.js
is completely fictious, generated by random data generation tools. If you find a real person or email address in this list, let me know and I'll publish an update. It's not in anyone's interest to expose PII (real or randomly generated).
Update/simplify the code in this lab once the New Relic nodejs agent has more complete support for the Apollo Server.
Lab reports will be submitted by generating a markdown file in the labreports directory under the naming convention: LAB_[GITHUB HANDLE].md, and submitting a Pull Request to this repository that include your lab report as well as any accompanying images/files (there are diagrams required in the lab content).
- Throughout these instructions, you'll find that items marked in bold text reference content you are to submit in your lab report.
- For the purposes of clear communication, you may base your lab report off of the template found in LAB.md, but you're also free, welcome, and encouraged to get more creative.
- If you are unfamiliar with markdown, I recommend checking 1000 places on the Interwebs that will help you close that gap.
- If you don't have a GitHub account already, create one. If you do, record the name of your handle in your lab report.
- If you don't already have git installed on your development machine, do so.
- Install a text editor or some sort of application for local development. Lately, I'm partial to Visual Studio Code and my instructions assume it's use, but you're welcome to diviate. Each one should choose their own sword, etc. etc.
- To run the project in Step 2, you'll need to have node.js and npm installed.
- After logging in, navigate to the root of this repository.
- Fork this repository to your personal GitHub account (hint: read the page).
- Navigate to your forked repository in your GitHub account and copy the reference to your repository in from the Clone or Download button.
- Open the terminal or command line interface on your development machine, navigate to your chosen working directory, and execute the following command:
git clone [YOUR COPIED GITHUB CLONE REFERENCE]
. - Navigate to that directory
cd cis411_lab3
. - Run
npm install
and watch the magic happen. - Run
npm start
and navigate to http://localhost:4000/graphql. - Run the following GraphQL mutation in GraphiQL and record the response.
mutation {
mutateAccount(input: {
email: "YOUR EMAIL"
name: "YOUR FULL NAME"
mutation: "add"
}) {
id
name
email
}
}
- Stop your service with a
Ctrl+C
, as we need to setup New Relic for telemetry acquisition.
In its downloaded state, the project will run successfully but fail to record any performance data to New Relic because you must follow the installation instructions for the New Relic nodejs agent. There's a great 4-minute video on the nodejs installation process here, under the heading, View installation video.
To accomplish the necessary configuration, perform the following.
- [Signup for a New Relic account] (https://newrelic.com/signup)
- Once you've registered for an account, login to New Relic.
- Navigate to your account settings at
https://rpm.newrelic.com/accounts/
- Find and copy the License key in the lower right side of the page. (You'll need it in a future step.)
- Copy the newrelic.js file from your local development environment's npm_modules directory into the root on your project.
# Command assumes you're in cis411_lab3 directory and have run 'npm install' already
> cp node_modules/newrelic/newrelic.js .
- Open the newrelic.js file in the root of your project.
# Command assumes the use of VS Code
> code newrelic.js
- In the newrelic.js file in the root of your project, find the
app_name
parameter and set it to cislab (or whatever name you prefer).
app_name: ['cislab'],
-
In the newrelic.js file in the root of your project, find the
license_key
parameter and set it to the value of yourlicense key
. -
Save the newrelic.js file with those changes.
-
Run
npm start
and navigate to http://localhost:4000/graphql and run a few GraphQL queries. -
After a minute (to allow the collector to begin sending performance data), login to New Relic and verify that you can see performance data.
-
Go back to the
Overview
page and click on an entry under theTransactions
list calledpost /
. -
Find the linked titled
Track as key transaction
and click it.
Open a web browser to http://localhost:4000/graphql
and run the following series of GraphQL requests:
{
#all orders containing the word PA
orders(query: "PA") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#all orders in Pennsylvania
orders(location: "PA") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#all orders with an item that contains an onion bagel
orders(bagel: "onion") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#all orders in Texas
orders(location: "TX") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#all orders with an item that contains a raisin bagel
orders(bagel: "raisin") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#retrieve all orders container the word everything
orders(query: "everything") {
id
customer {
id
email
}
items {
label
quantity
}
}
}
{
#all accounts that contain gmail.com
accounts(query: "gmail.com") {
id
items {
label
quantity
}
}
}
Explore a few more mutations and queries in GraphQL to create a good base of requests for the nodejs client to profile. Did you notice if any of those requests seemed particularly slow? Which ones? How much? Why? (Note: these are rhetorical questions meant to underscore the point of the next step.)
- Open (or log back into) New Relic and select your
cislab
(or whatever you chose to set the app_name configuration in your newrelic.js) application in the application list. - Observe and record what the Overview page for your application has to tell you about the performance of your GraphQL service.
- At the bottom of the
Overview
page, click on yourHost
, and record what it's telling you about the health/performance of your compute device. - Go back to the
Overview
page and click on an entry under theTransactions
list calledpost /
. - Scroll down to the section marked
Transaction traces
and click on a long-running transaction. What segment of the transaction took the most time? - Repeat step 5 for 3 other transactions.
- What are your observations regarding the performance of this application? Is performance even or uneven? Between queries and mutations, what requests are less performant? Among the less performant requests, which ones are the most problematic?
Amongst the requests in this GraphQL server, there is one specific permiatation of a request that is the most problematic (hint: I put it there on purpose).
- Using New Relic, identify and record the least performant request(s).
- Using the Transaction Trace capability in New Relic, identify which segment(s) in that request permiatation is/are the most problematic and record your findings.
- Recommend a solution for improving the performance of those most problematic request(s) / permiatation(s).
Once you've completed your report markdown, have ensured that your forked repository is successfully running in CircleCI, and have committed all your changes to your (primary) master branch, initiate a Pull Request in GitHub to submit your Lab Report.
- Navigate to the root of your forked repository (ex. https://github.com/YOURHANDLE/cis411_lab3).
- Click the New pull request button.
- Choose the base fork tangollama/cis411_lab3 is the target and that your fully updated master branch is the source.
- Enter a title and description for the Pull Request (PR).
For the purposes of gaining 25% or even more extra credit on the assignment, perform the following:
- Adjust the diagnosed slow call(s) to improve performance.
- Verify the improved performance in New Relic, including data and/or screenshots in your lab report.
- Check in those changes and note your solution(s) in your lab report.
Note this work in your lab report by submitting it in your PR and linking to either the PR or the specific commit as recorded in GitHub in your lab report.