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

Add new relic gem #11256

Merged
merged 4 commits into from
Aug 7, 2023
Merged

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Jul 21, 2023

What? Why?

Related to #10997

It uses the following env varirable to enable new relic agent, setup the licence key and customise application name:

  • NEW_RELIC_AGENT_ENABLED
  • NEW_RELIC_LICENSE_KEY
  • NEW_RELIC_APP_NAME

The agent is disable by default so we can enable new relic for the production server that needs it.

What should we test?

  • Set up the license key and application name
  • Stage the application
  • Play around a little bit with the website
  • Check that data is being sent to New Relic

Release notes

Changelog Category: Technical changes

The title of the pull request will be included in the release notes.

@rioug rioug force-pushed the 10997-add-new-relic-gem branch 2 times, most recently from c494954 to 4867b13 Compare July 21, 2023 06:42
@rioug rioug marked this pull request as ready for review July 21, 2023 06:45
Copy link
Contributor

@jibees jibees left a comment

Choose a reason for hiding this comment

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

👌

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Great! I would put it in the global group though.

Gemfile Outdated
@@ -139,6 +139,7 @@ gem "faraday"
gem "private_address_check"

group :production, :staging do
gem 'newrelic_rpm'
Copy link
Member

Choose a reason for hiding this comment

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

Would it hurt to have it in all environments?

I find it increases the chance to catch compatibility bugs early.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It don't think it would. I fixed up the configuration so we don't run the agent by default in Dev. And I realised I forgot to actually test if the configuration was working, which I have now done.

@rioug rioug force-pushed the 10997-add-new-relic-gem branch 2 times, most recently from f016de7 to ce533ef Compare July 24, 2023 05:17
@rioug rioug requested a review from mkllnk July 24, 2023 05:20
@rioug
Copy link
Collaborator Author

rioug commented Jul 24, 2023

I don't actually know how env variable are set up on each instance, maybe someone more knowledgeable can update the testing note ?


# To disable the agent regardless of other settings, uncomment the following:

# agent_enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably want to disable the agent by default if there's no API key present (in development for example). I think this file allows interpolation with erb.

Maybe here we can do something like:

agent_enabled: <%= ENV["NEW_RELIC_LICENSE_KEY"].present? %>

Copy link
Member

Choose a reason for hiding this comment

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

Good idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the new relic config doesn't allow interpolation any more. I couldn't find a way to disable the agent if the license key is not present, but I updated the config to disable the agent in dev, test and staging.

Copy link
Member

Choose a reason for hiding this comment

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

That's a problem. Not every production instance will have a new relic key. Do we set it to false everywhere and then use environment variables to control it instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think that would be a better solution. Do we need to update any documentation around this ?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update any documentation around this ?

Yes.

  • The ofn-install repository has a template for the secrets which needs entries with comments.
  • The wiki describes optional services, how to set them up etc. It needs to be mentioned there.

@rioug rioug force-pushed the 10997-add-new-relic-gem branch 2 times, most recently from 8441421 to 2bfe217 Compare July 28, 2023 03:37
Comment on lines 63 to 66
staging:
<<: *default_settings
app_name: 'Open Food Network (Staging)'
agent_enabled: false
Copy link
Member

Choose a reason for hiding this comment

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

How are we going to test changes before they go to production? It would be great to have this on staging as well. And testing locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you can override the configuration by setting the env variable NEW_RELIC_AGENT_ENABLED to true

@rioug rioug force-pushed the 10997-add-new-relic-gem branch 2 times, most recently from 5c55908 to f4b9a6f Compare July 31, 2023 01:07
@rioug rioug self-assigned this Jul 31, 2023
# Your application name. Renaming here affects where data displays in New
# Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
# Use NEW_RELIC_APP_NAME env variable to customize the application name
app_name: "Open Food Network"
Copy link
Member

Choose a reason for hiding this comment

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

I have one question:
Will all the instances share the same key? and NEW_RELIC_APP_NAME will variate depending on the instance location. for example: "Open Food Network (AU)", "Open Food Network (UK)" ?

Copy link
Member

Choose a reason for hiding this comment

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

That's a good question. In the past we would have set up separate keys but if New Relic supports it then we should use the same key, I think. That we we have all the information in one place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is we should be able to use the same license key for all the instances, and set up a different name for each instance so we can differentiate the data. See below:
New_relic
There is the possibility to create extra license key so we could potentially have a different license key for each instance, all reporting to the same New Relic account. Or have a different user with it's own license key for each instance, but that's probably not needed. It's recommended to create extra license for security reason (key rotation) .
More info here: https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I think that we should roll out with the same key and we can rotate later.

@rioug rioug added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Aug 4, 2023
@rioug
Copy link
Collaborator Author

rioug commented Aug 4, 2023

I tested this on au-staging while working on : openfoodfoundation/ofn-install#888 , so it should be good to merge unless someone else wants to test it as well.

@rioug rioug requested a review from mkllnk August 4, 2023 06:14
It can be enable as needed by setting NEW_RELIC_AGENT_ENABLED env
variable to true and setting a license key
@mkllnk mkllnk merged commit 4b0bffa into openfoodfoundation:master Aug 7, 2023
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants