Skip to content

Commit 7bcc953

Browse files
committed
feat: creates an action that changes the config from deployments in our canaries and refactors fleet_deployment.sh to use the fleet API in newrelic-cli
1 parent f2ee293 commit 7bcc953

3 files changed

Lines changed: 184 additions & 132 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: 🔁🐤 Scheduled onhost canary config rotation
2+
3+
# Every 6 hours, deploy the *next* config version in an ordered set to the
4+
# canary fleet using test/onhost-canaries/scripts/fleet_deployment.sh.
5+
# Each run advances one step through the set; after the last entry it wraps
6+
# back to the first. This is a rotation (one deployment per run), not a matrix
7+
# fan-out.
8+
9+
on:
10+
schedule:
11+
# Every 6 hours (UTC). Minute offset from :00 to dodge the top-of-hour
12+
# scheduler backlog that delays cron workflows on GitHub-hosted runners.
13+
- cron: "17 */6 * * *"
14+
15+
permissions:
16+
contents: read
17+
18+
concurrency:
19+
# Never overlap rotation runs (each run already deploys every environment/platform combination).
20+
group: scheduled-onhost-canary-config-rotation
21+
cancel-in-progress: false
22+
23+
env:
24+
# AC Staging Account `host-canaries-staging` fleet
25+
FLEET_ID_STAGING: "MTIyMTMwNjh8TkdFUHxGTEVFVHwwMTlhZTNiNS01Yjg5LTdkNjYtYWU0MC1lNmZkOTY2ZDFhMDA"
26+
WINDOWS_FLEET_ID_STAGING: "MTIyMTMwNjh8TkdFUHxGTEVFVHwwMTljMjNjYy0yM2I2LTc1OTYtODBkNy0yMzAzYWIyYzcwMTA"
27+
# AC US Production Account `host-canaries-production` fleet
28+
FLEET_ID_PRODUCTION: "NjQyNTg2NXxOR0VQfEZMRUVUfDAxOWFlM2EyLTA3OTctNzczYS05Y2JjLWMzNzZkMjAwMWFkZg"
29+
WINDOWS_FLEET_ID_PRODUCTION: "NjQyNTg2NXxOR0VQfEZMRUVUfDAxOWMyMjljLWVhYTQtN2JmNi04YWIyLTU2ZWI0YjE2ZWZjZQ"
30+
31+
# Ordered set of agent specs to rotate through, one per line:
32+
# <agentType>:<version>:<configVersionId>
33+
# Agent type, version and config version are paired here so they always rotate
34+
# together and stay matched. One deployment per run advances to the next entry,
35+
# wrapping to the first after the last.
36+
# We don't have 'latest' OCI packages, so I've set them to a fixed version.
37+
# First -> NRInfra 1.77.1 (canaries-infra-config)
38+
# Second -> NRDOT 1.19.0 (canaries-nrdot)
39+
AGENT_SPECS_LINUX: >-
40+
NRInfra:1.77.1:NjQyNTg2NXxOR0VQfEFHRU5UX0NPTkZJR1VSQVRJT05fVkVSU0lPTnwwMTlmNGM3Yi1lYjAyLTc1MmQtOGViOC0zNDYyMWM2ZDRkMzQ
41+
NRDOT:1.19.0:NjQyNTg2NXxOR0VQfEFHRU5UX0NPTkZJR1VSQVRJT05fVkVSU0lPTnwwMTlmNGM3Yy05M2Y3LTcyMjctODJmZS01OGYwMjcyMDViMDI
42+
# First -> NRInfra 1.77.1 (canaries-infra-config-windows)
43+
# Second -> NRDOT 1.19.0 (canaries-nrdot-windows)
44+
AGENT_SPECS_WINDOWS: >-
45+
NRInfra:1.77.1:NjQyNTg2NXxOR0VQfEFHRU5UX0NPTkZJR1VSQVRJT05fVkVSU0lPTnwwMTlmNGNjNC0zNmU1LTdmMmQtYjIyMS1mM2ZjY2QzOTAwOTg
46+
NRDOT:1.19.0:NjQyNTg2NXxOR0VQfEFHRU5UX0NPTkZJR1VSQVRJT05fVkVSU0lPTnwwMTlmNGNjNC1kMTE0LTdmMzktYWRmZS02ZTY4ZWFiYWZkY2Y
47+
48+
jobs:
49+
rotate-config-deployment:
50+
name: Deploy next config in rotation (${{ matrix.environment }} / ${{ matrix.platform }})
51+
runs-on: linux-4-core-nr-control
52+
strategy:
53+
# Every run deploys all environment/platform combinations; a failure on one
54+
# must not skip the others.
55+
fail-fast: false
56+
matrix:
57+
environment: [staging, production]
58+
platform: [linux, windows]
59+
steps:
60+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
61+
62+
- name: Resolve fleet and select agent spec (rotating)
63+
id: target
64+
env:
65+
PLATFORM: ${{ matrix.platform }}
66+
ENVIRONMENT: ${{ matrix.environment }}
67+
run: |
68+
# Pick this platform's fleet id (per environment) and its ordered spec list.
69+
if [ "${PLATFORM}" = "windows" ]; then
70+
SPECS_STR="${AGENT_SPECS_WINDOWS}"
71+
if [ "${ENVIRONMENT}" = "production" ]; then
72+
FLEET_ID="${WINDOWS_FLEET_ID_PRODUCTION}"
73+
else
74+
FLEET_ID="${WINDOWS_FLEET_ID_STAGING}"
75+
fi
76+
else
77+
SPECS_STR="${AGENT_SPECS_LINUX}"
78+
if [ "${ENVIRONMENT}" = "production" ]; then
79+
FLEET_ID="${FLEET_ID_PRODUCTION}"
80+
else
81+
FLEET_ID="${FLEET_ID_STAGING}"
82+
fi
83+
fi
84+
85+
# Split the whitespace-separated specs. Each entry is a full
86+
# <agentType>:<version>:<configVersionId> spec.
87+
read -ra SPECS <<< "${SPECS_STR}"
88+
COUNT=${#SPECS[@]}
89+
90+
# github.run_number increments on every run of this workflow, so
91+
# ((run_number - 1) % COUNT) walks the set in order starting at the
92+
# first entry and wraps back to the first after the last. Both platforms
93+
# share the same run number, so they rotate to the same position.
94+
RUN_NUMBER=${{ github.run_number }}
95+
INDEX=$(( (RUN_NUMBER - 1) % COUNT ))
96+
SPEC="${SPECS[$INDEX]}"
97+
98+
echo "[${PLATFORM}] rotation: run #${RUN_NUMBER} -> index ${INDEX} of ${COUNT} -> ${SPEC}"
99+
echo "fleet_id=${FLEET_ID}" >> "$GITHUB_OUTPUT"
100+
echo "spec=${SPEC}" >> "$GITHUB_OUTPUT"
101+
102+
- name: Create and deploy fleet deployment
103+
env:
104+
NEW_RELIC_API_KEY: ${{ matrix.environment == 'production' && secrets.AC_PROD_E2E_API_KEY || secrets.AC_FC_STAG_E2E_API_KEY }}
105+
FLEET_ID: ${{ steps.target.outputs.fleet_id }}
106+
ENVIRONMENT: ${{ matrix.environment }}
107+
run: |
108+
chmod +x test/onhost-canaries/scripts/fleet_deployment.sh
109+
test/onhost-canaries/scripts/fleet_deployment.sh \
110+
"${{ steps.target.outputs.spec }}"

test/onhost-canaries/scripts/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Script to create and trigger Fleet Control deployments for on-host canaries.
44

55
## Overview
66

7-
The `fleet_deployment.sh` script creates a Fleet Control deployment that defines the desired state of agents in a fleet and triggers the rollout through the ring deployment policy.
7+
The `fleet_deployment.sh` script creates a Fleet Control deployment that defines the desired state of agents in a fleet and triggers the rollout through the ring deployment policy. It drives the [New Relic CLI](https://github.com/newrelic/newrelic-cli) (`newrelic fleetcontrol deployment ...`) rather than calling NerdGraph directly.
88

99
### Two-Step Process
1010

11-
1. **fleetControlCreateFleetDeployment** — Creates the deployment definition
12-
2. **fleetControlDeploy** — Pushes it through the ring policy to the fleet
11+
1. **`newrelic fleetcontrol deployment create`** — Creates the deployment definition
12+
2. **`newrelic fleetcontrol deployment deploy`** — Pushes it through the ring policy to the fleet
1313

1414
## Prerequisites
1515

@@ -18,18 +18,21 @@ The `fleet_deployment.sh` script creates a Fleet Control deployment that defines
1818
- `bash` (tested with bash 5.x)
1919
- `curl`
2020
- `jq`
21+
- `newrelic` CLI — installed automatically by the script if not already on `PATH`
2122

2223
### Required Environment Variables
2324

2425
Set these environment variables before running the script:
2526

2627
```bash
27-
export NEW_RELIC_API_KEY="<your-api-key>" # NerdGraph User API key
28+
export NEW_RELIC_API_KEY="<your-api-key>" # NerdGraph User API key (NRAK-...)
2829
export FLEET_ID="<fleet-entity-guid>" # Fleet entity GUID
29-
export SCOPE_ORG_ID="<organization-guid>" # Organization GUID for deployment scope
3030
export ENVIRONMENT="staging" # "staging" or "production"
3131
```
3232

33+
> The deployment scope (organization) is derived automatically by the CLI from the API key.
34+
> `ENVIRONMENT` is mapped to the CLI's `NEW_RELIC_REGION` (`staging``Staging`, `production``US`).
35+
3336
## Usage
3437

3538
### Purpose
@@ -72,7 +75,6 @@ Deploy Infrastructure Agent version 1.76.1 with a specific configuration:
7275
```bash
7376
export NEW_RELIC_API_KEY="NRAK-XXXX"
7477
export FLEET_ID="MTIyMTMwNjh8TkdFUHxGTEVFVHwwMTlhZTNiNS01Yjg5LTdkNjYtYWU0MC1lNmZkOTY2ZDFhMDA"
75-
export SCOPE_ORG_ID="9d789cca-f661-458d-be06-882d1e6e409d"
7678
export ENVIRONMENT="staging"
7779

7880
./fleet_deployment.sh "NRInfra:1.76.1:MTIyMTMwNjh8TkdFUHxBR0VOVF9DT05GSUdVUkFUSU9OX1ZFUlNJT058MDE5YzdhYWEtNmM4My03NWFhLWIzYmEtOTE0MjIzZDU0Mjk1"
@@ -101,9 +103,8 @@ Example output:
101103
[2026-06-10 11:34:52] =======================================
102104
[2026-06-10 11:34:52] Fleet Deployment Script
103105
[2026-06-10 11:34:52] =======================================
104-
[2026-06-10 11:34:52] Environment : staging
106+
[2026-06-10 11:34:52] Environment : staging (region: Staging)
105107
[2026-06-10 11:34:52] Fleet ID : MTIyMTMwNjh8TkdFUHxGTEVFVHwwMTlhZTNiNS01Yjg5LTdkNjYtYWU0MC1lNmZkOTY2ZDFhMDA
106-
[2026-06-10 11:34:52] Scope Org ID : 9d789cca-f661-458d-be06-882d1e6e409d
107108
[2026-06-10 11:34:52] Deployment : canary-deployment-20260610-113452
108109
[2026-06-10 11:34:52] Agents : NRInfra:1.76.1:MTIyMTMwNjh8TkdFUHxBR0VOVF9DT05GSUdVUkFUSU9OX1ZFUlNJT058MDE5YzdhYWEtNmM4My03NWFhLWIzYmEtOTE0MjIzZDU0Mjk1
109110
[2026-06-10 11:34:52] =======================================

0 commit comments

Comments
 (0)