GithubHelp home page GithubHelp logo

newrelic-synthetics-sync's Introduction

New Relic Synthetic Sync

Github action that will sync synthetic script commits to corresponding Synthetic monitors within New Relic.

Currently supports the following for Scripted Browser or Scripted API type monitors:

  • Syncing script changes to existing monitors.
  • Creating new monitors for new scripts committed.

Requirements

  1. Configure your New Relic User key as a repository secret.
  2. Create and configure your Workflow yaml (see examples here) under .github/workflows.

IMPORTANT

  • This action also uses tj-actions/changed-files to detect changes to any js files committed.
  • Filenames of scripts committed should be 1-1 exact with the corresponding monitorName within New Relic.
  • If you plan on creating new monitors from newly committed scripts, each script must have one of the following comments somewhere within, to denote the monitor type (scripted browser or scripted api):
//monitorType: SCRIPT_BROWSER

OR

//monitorType: SCRIPT_API

Usage

name: New Relic Synthetics

# -------------------------------------------------------------------------------------------------------------------------
# Event `push`: Compare the preceding commit -> to the current commit.
# -------------------------------------------------------------------------------------------------------------------------
on: [push]

env:
  NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }} #Required repository secret

jobs:
  sync_synthetic_monitors:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3


      # Detects changes to .js files only in any sub path, formats those filenames/paths as json
      - name: Get Changed Scripts
        id: changed-files
        uses: tj-actions/changed-files@v35
        with:
          separator: ","
          files: |    # Modify this to wherever your specific scripts reside - defaults to any js files
            **/*.js
          json: "true"

      # Proceed with storing filenames/paths in a local file for further processing, ONLY if any .js files have changed or been committed.
      - name: Store Changed Scripts
        if: steps.changed-files.outputs.any_changed == 'true'
        run: |
          echo ${{ steps.changed-files.outputs.all_changed_files }} > monitors.json
          cat monitors.json

      # Parse out js filenames, which should match the entity names within NR, fetch the entity's guid, and update existing monitor or create new one
      - name: Sync Changes to Synthetics
        if: steps.changed-files.outputs.any_changed == 'true'
        uses: ./
        with: # OPTIONAL defaults for creation of new scripts committed - Remove if the only interest is updating existing monitors.
          accountId: 1
          runtime: "new"
          privateLocations: "[{'guid': 'MTQ...'}]"
          publicLocations: "['AWS_AP_EAST_1', 'AWS_US_EAST_2']"
          interval: EVERY_15_MINUTES
          status: ENABLED

Inputs

The following are optional inputs if you wish to automatically create new monitors from newly committed scripts. If these are not included in the workflow, only changes to existing scripts will be sync'd with New Relic.

INPUT TYPE REQUIRED DEFAULT DESCRIPTION
accountId string FALSE "" New Relic account id in which new monitor will be created within
runtime string FALSE "" Synthetics runtime the monitor will use. Options are new (Chrome 100/Node 16.10) or old (Chrome 72/Node 10)
privateLocations string FALSE "" Array of private location guids that the new monitor will execute on. guids can be found within New Relic under Synthetic Monitoring -> Private Locations
publicLocations string FALSE "" Array of public location names that the new monitor will execute on. The AWS region must be used, not the display name. A list of location inputs can be found here
interval string FALSE "" The execution frequency of monitor created. Available options can be found here
status string FALSE "" Whether a new monitor created within New Relic will be enabled or disabled. Accepts ENABLED, DISABLED, or MUTED

Examples

Below are a couple different configurations for various use cases:

Sync modified scripts only
...
  - name: Sync Changes to Synthetics
    if: steps.changed-files.outputs.any_changed == 'true'
    uses: newrelic-experimental/newrelic-synthetics-sync
...
Sync modified scripts with existing monitors and create new monitors with default inputs - 2 private locations and 2 public locations, running on the new runtime every 30 minutes
...
  - name: Sync Changes to Synthetics
    if: steps.changed-files.outputs.any_changed == 'true'
    uses: newrelic-experimental/newrelic-synthetics-sync
    with: # all optional defaults for creation of new scripts committed
      accountId: 123
      runtime: "new"
      privateLocations: "[{'guid': 'xtz'},{'guid': 'abc'}]"
      publicLocations: "['AWS_AP_EAST_1', 'AWS_US_EAST_2']"
      interval: EVERY_30_MINUTES
      status: ENABLED
...

See inputs for more information.

Additional Resources

Contributing

We encourage your contributions to improve Synthetics Sync! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

License

Github Actions New Relic Exporter is licensed under the Apache 2.0 License.

New Relic Synthetics Sync also use source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.

newrelic-synthetics-sync's People

Contributors

khpeet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.