Skip to content

Commit

Permalink
feat(monitoring): ability to specify clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe committed May 18, 2021
1 parent c1df1ec commit a5a4862
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 97 deletions.
120 changes: 86 additions & 34 deletions .circleci/orbs/helix-post-deploy/orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ commands:
default: ""
description: The name of the deployed action
universal:
type: boolean
default: false
description: The action is deployed in universal runtime
type: string
default: ""
description: "Universal action. Comma-separated list of clouds to monitor: aws, gcloud, azure, adobeio"
universal_host:
type: string
default: "helix-pages.anywhere.run"
Expand Down Expand Up @@ -134,7 +134,7 @@ commands:
actionNS="<< parameters.action_namespace >>"
actionPackage="<< parameters.action_package >>"
actionName="<< parameters.action_name >>"
universal=<< parameters.universal >>
universal="<< parameters.universal >>"
universalHost="<< parameters.universal_host >>"
aws=<< parameters.aws >> #deprecated
adobeioHost="<< parameters.adobeio_host >>"
Expand All @@ -155,50 +155,102 @@ commands:
nrAdobeioName=""
nrAWSURL=""
nrAWSName=""
universal=${universal:-${aws}} # backward compatibility
# statuspage automation
declare -a clouds
if [ "${universal}" == "" ] && [ "${aws}" != "" ]; then
# backward compatibility
universal="aws, adobeio"
fi
if [ "${universal}" != "" ]; then
# extract clouds
IFS=',' read -ra values <<< "${universal}"
for v in "${values[@]}"; do
clouds+=(`echo ${v} | xargs`)
done
fi
# --- statuspage automation -------------------------------------------------
spCloudSuffix=("aws:AWS"
"adobeio:Adobe I/O Runtime")
declare -a spNames
if [ "${spName}${spGroup}" != "" ]; then
spEmail=`node ${toolPath}/statuspage setup --silent \
${spName:+--name "${spName}"} \
${spGroup:+--group "${spGroup}"} \
${incubator:+--incubator ${incubator}} \
${universal:+--universal ${universal}}`
# add component name(s)
if [ "${spName}" != "" ]; then
spNames+=("${spName}")
fi
for cloud in ${clouds[@]}; do
spCloud=""
for ((s=0;s<${#spCloudSuffix[@]};s+=1)); do
suffix=${spCloudSuffix[$s]}
if [[ ${suffix} =~ ${cloud} ]]; then
spCloud=${suffix#*:}
break
fi
done
if [ "${spCloud}" != "" ]; then
spNames+=("${spNames[0]} (${spCloud})")
fi
done
# generate component email(s)
spArgs="--silent"
spArgs+=`for ((i=0;i<${#spNames[@]};i+=1)); do echo " --name \"${spNames[$i]}\""; done`
spArgs+=" ${spGroup:+--group \"${spGroup}\"} ${incubator:+--incubator ${incubator}}"
spEmail=`node ${toolPath}/statuspage setup ${spArgs}`
fi
# new relic automation
# --- new relic automation --------------------------------------------------
declare -a nrNames=()
declare -a nrURLs=()
if [ "${actionName}" == "" ]; then
# extract action name from package name
actionName=`node -e "console.log(require('./package.json').name.replace('@adobe/helix-', ''))"`
fi
# use package version as action version
actionVersion=`node -e "console.log(require('./package.json').version.match(/^[0-9]+/)[0])"`
actionStatus="/_status_check/healthcheck.json"
if [ "${nrName}" == "" ]; then
if [ "${nrName}" != "" ]; then
# use custom name
nrNames+=("${nrName}")
else
# use package name
nrName=`node -e "console.log(require('./package.json').name)"`
nrNames+=(`node -e "console.log(require('./package.json').name)"`)
fi
if [ "${nrURL}" == "" ]; then
if [ ${universal} == true ]; then
# assemble universal runtime url
nrURL="https://${universalHost}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}"
# add adobe i/o url and name as secondary monitor
nrAdobeioURL="https://${adobeioHost}/api/v1/web/${actionNS}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}"
nrAdobeioName="${nrName}.adobeio"
# add AWS url and name as secondary monitor
nrAWSURL="https://${awsApi}.execute-api.${awsRegion}.amazonaws.com/${actionPackage}/${actionName}/v${actionVersion}${actionStatus}"
nrAWSName="${nrName}.aws"
else
# fall back to adobe i/o only
nrURL="https://${adobeioHost}/api/v1/web/${actionNS}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}"
fi
if [ "${nrURL}" != "" ]; then
# use custom url
nrURLs+=("${nrURL}")
elif [ "${universal}" != "" ] && [ ${#clouds[@]} > 0 ]; then
# use universal monitoring
nrURLs+=("https://${universalHost}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}")
# add secondary monitors
for cloud in ${clouds[@]}; do
error=""
if [ "${cloud}" == "aws" ]; then
# add aws url
nrURLs+=("https://${awsApi}.execute-api.${awsRegion}.amazonaws.com/${actionPackage}/${actionName}/v${actionVersion}${actionStatus}")
elif [ "${cloud}" == "adobeio" ]; then
# add adobe i/o url
nrURLs+=("https://${adobeioHost}/api/v1/web/${actionNS}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}")
else
error="Unsupported cloud: ${cloud}"
fi
if [ "${error}" == "" ]; then
## add cloud-specific name
nrNames+=("${nrNames[0]}.${cloud}")
fi
done
else
# fall back to adobe i/o only
nrURLs+="https://${adobeioHost}/api/v1/web/${actionNS}/${actionPackage}/${actionName}@v${actionVersion}${actionStatus}"
fi
node ${toolPath}/newrelic setup --url ${nrURL} \
${nrAdobeioURL:+--url "${nrAdobeioURL}"} \
${nrAWSURL:+--url "${nrAWSURL}"} \
${nrName:+--name "${nrName}"} \
${nrAdobeioName:+--name "${nrAdobeioName}"} \
${nrAWSName:+--name "${nrAWSName}"} \
node ${toolPath}/newrelic setup \
`for ((i=0;i<${#nrURLs[@]};i+=1)); do echo " --url ${nrURLs[$i]}"; done` \
`for ((i=0;i<${#nrNames[@]};i+=1)); do echo " --name ${nrNames[$i]}"; done` \
${spEmail:+--email ${spEmail}} \
${nrType:+--type ${nrType}} \
${nrLocations:+--locations ${nrLocations}} \
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Options:
--page_id, --pageId Statuspage Page ID (or env
$STATUSPAGE_PAGE_ID)
[string] [required]
--name The name of the component [string]
--name The name(s) of the component(s)
[array]
--description The description of the component
[string]
--group The name of an existing component
Expand All @@ -52,8 +53,6 @@ Options:
components [string] [default: false]
--runtime Also monitor the action in Adobe I/O
Runtime [boolean] [default: false]
--universal The action is deployed in universal
runtime [boolean] [default: false]
--silent Reduce output to automation email only
[boolean] [default: false]
Expand Down
18 changes: 4 additions & 14 deletions src/statuspage/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,11 @@ class CLI {

async function updateOrCreateComponent({
// eslint-disable-next-line camelcase
auth, pageId, group, name, description, universal, silent, incubator, incubatorPageId,
auth, pageId, group, name, description, silent, incubator, incubatorPageId,
}) {
setLogger(silent);

const names = [name];
if (universal) {
names.push(`${[name]} (Adobe I/O Runtime)`);
names.push(`${[name]} (AWS)`);
}
const names = Array.isArray(name) ? name : [name];

const emails = [
...await Promise.all(names.map(async (cname) => {
Expand Down Expand Up @@ -253,10 +249,10 @@ class CLI {
required: true,
})
.option('name', {
type: 'string',
type: 'array',
describe: 'The name of the component',
required: config.name === undefined,
default: config.name,
default: [config.name],
})
.option('description', {
type: 'string',
Expand All @@ -282,12 +278,6 @@ class CLI {
required: false,
default: false,
})
.option('universal', {
type: 'boolean',
describe: 'The action is deployed in universal runtime',
required: false,
default: false,
})
.option('silent', {
type: 'boolean',
describe: 'Reduce output to automation email only',
Expand Down
20 changes: 13 additions & 7 deletions test/monitoring/specs/aws_legacy.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@
"--url",
"https://helix-pages.anywhere.run/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--url",
"https://adobeioruntime.net/api/v1/web/helix/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--url",
"https://abcde12345.execute-api.us-east-1.amazonaws.com/helix-services/monitoring-test/v1/_status_check/healthcheck.json",
"--url",
"https://adobeioruntime.net/api/v1/web/helix/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--name",
"@adobe/helix-monitoring-test",
"--name",
"@adobe/helix-monitoring-test.adobeio",
"--name",
"@adobe/helix-monitoring-test.aws",
"--name",
"@adobe/helix-monitoring-test.adobeio",
"--email",
"setup",
"--silent",
"--name",
"foo",
"--universal",
"true"
"\"foo\"",
"--name",
"\"foo",
"(AWS)\"",
"--name",
"\"foo",
"(Adobe",
"I/O",
"Runtime)\""
]
}
4 changes: 3 additions & 1 deletion test/monitoring/specs/newrelic_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"--url",
"https://adobeioruntime.net/api/v1/web/helix/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--name",
"foo - bar"
"foo",
"-",
"bar"
]
}
2 changes: 1 addition & 1 deletion test/monitoring/specs/statuspage_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"setup",
"--silent",
"--group",
"foo"
"\"foo\""
]
}
2 changes: 1 addition & 1 deletion test/monitoring/specs/statuspage_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"setup",
"--silent",
"--name",
"foo"
"\"foo\""
]
}
24 changes: 15 additions & 9 deletions test/monitoring/specs/universal.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parameters": {
"statuspage_name": "foo",
"universal": true,
"universal": "aws, adobeio",
"aws_api": "abcde12345",
"aws_region": "us-east-1"
},
Expand All @@ -10,21 +10,27 @@
"--url",
"https://helix-pages.anywhere.run/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--url",
"https://adobeioruntime.net/api/v1/web/helix/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--url",
"https://abcde12345.execute-api.us-east-1.amazonaws.com/helix-services/monitoring-test/v1/_status_check/healthcheck.json",
"--url",
"https://adobeioruntime.net/api/v1/web/helix/helix-services/monitoring-test@v1/_status_check/healthcheck.json",
"--name",
"@adobe/helix-monitoring-test",
"--name",
"@adobe/helix-monitoring-test.adobeio",
"--name",
"@adobe/helix-monitoring-test.aws",
"--name",
"@adobe/helix-monitoring-test.adobeio",
"--email",
"setup",
"--silent",
"--name",
"foo",
"--universal",
"true"
"\"foo\"",
"--name",
"\"foo",
"(AWS)\"",
"--name",
"\"foo",
"(Adobe",
"I/O",
"Runtime)\""
]
}
}
14 changes: 4 additions & 10 deletions test/statuspage/StatuspageAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,11 @@ class StatuspageAPI extends AbstractAPI {
return (uri, req) => {
ctx.emit(StatuspageAPI.GET_COMPONENTS, uri, req);
const comps = [];
if (!ctx.cfg.new) {
if (!ctx.cfg.new && ctx.cfg.component) {
// there is an existing component
comps.push(ctx.cfg.component);
if (ctx.cfg.universal) {
if (ctx.cfg.awsComponent) {
comps.push(ctx.cfg.awsComponent);
}
if (ctx.cfg.adobeioComponent) {
comps.push(ctx.cfg.adobeioComponent);
}
}
const existingComps = Array.isArray(ctx.cfg.component)
? ctx.cfg.component : [ctx.cfg.component];
existingComps.forEach((comp) => comps.push(comp));
}
if (ctx.cfg.componentGroup) {
// component group is also a component
Expand Down

0 comments on commit a5a4862

Please sign in to comment.