Tracking Deployments With New Relic

Gizem Cifgüvercin
Jun 24 · 4 min read

While working with microservice architecture and manage distributed systems that includes many of bounded contexts, you need to monitor your services one by one and be sure about the systems are up all time.

In the life cycle of software development(SDLC) we have 6 steps to be done.

Such as planning, analysis, design, implementation, testing, deployment

After every feature development we run our tests in QA environment and check quality & functionality & code coverage

We should track our system’s behaviour before deployment and after deployment for knowing deployment effects to avg response time, throughput, cpu, memory, error rate and database.

If any anomaly occurs in the production environment due to deployment these metrics will totally helpful to find the root cause of the problem.

Record deployments

New Relic allows you to track deployments so you can correlate deploy to your app’s performance. Tracking deployments creates deployment markers that appear in APM charts.

Tracking Deployments Options

You can use the New Relic REST API v2 to record deployments

1. Record a deployment with POST

2. Record a deployment with PowerShell

If you are using CI/CD to deliver apps by automation, I suggest you to add deployment marker via curl request in deployment stage. Let’s see how we can mark our deployments in CI/CD pipeline

# A curl request example given in New Relic Deployment Docs

In this curl request above, we see a few properties for identify our deployment. Let’s talk about how we can set up these parametrically;

I will show the example steps on Gitlab CI/CD

Gitlab Environment Variables To Identify Deployment

You can select for your deployment info from a lot of CI variables at https://docs.gitlab.com/ee/ci/variables/#list-all-environment-variables

You can also use GitLab user info of account to identify deployer

How To Use Gitlab Environment Variables

Now we will look at .gitlab-ci.yml closely

In gitlab yml file, we have some stages to automate deployment such as docker-build, unit test, deploy-qa, integration test, deploy-prod that can be change due to your deployment strategies

Let’s talk about deploying your new features into the qa environment. In this scenario think like you are using kubectl to push your new docker image into your k8s cluster

For using curl request in this phase, you need to install curl via this command before you send the request so you should set this command in before_script step as below;

before_script: 
- apk add --update curl && rm -rf /var/cache/apk/*

After installing curl, you will be ready to send Curl request to mark your deployment

After you do success deployment, you set your curl command in after_script step as below;

We used GitLab ci variables that were given to us but we can also create our own environment variables at GitLab under the Settings/CI CD/Variables section.

So you can set NEW_RELIC_DEPLOYMENT_KEY_QA variable here and use from everywhere (deployment, ingress, service yaml, ci yml etc) in your project. I prefer to use this key from the environment variable in GitLab ci yml so I added the key into NEW_RELIC_DEPLOYMENT_KEY_QA and wrote as ${NEW_RELIC_DEPLOYMENT_KEY_QA} in ci yml

And after this configuration, we will be able to see effects in New Relic Deployment Metrics UI

New Relic Deployment UI Dashboards

  1. Deployments Table

2. Overview of response time, throughput, cpu, memory

3. Change Log Details

4. Detailed Change Report Which Including Endpoint And Its A lot Of Metrics

References

https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/record-monitor-deployments/

hepsiburadatech

hepsiburada technology