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

feat: allow sending alerts to another account #179

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codebuild/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ env:
dev_FIREBASE_CLIENT_X509_CERT_URL: "WalletService/dev:FIREBASE_CLIENT_X509_CERT_URL"
dev_ALERT_MANAGER_REGION: "WalletService/dev:ALERT_MANAGER_REGION"
dev_ALERT_MANAGER_TOPIC: "WalletService/dev:ALERT_MANAGER_TOPIC"
dev_ALERT_MANAGER_ACCOUNT_ID: "WalletService/dev:ALERT_MANAGER_ACCOUNT_ID"
# Testnet secrets
testnet_ACCOUNT_ID: "WalletService/testnet:account_id"
testnet_AUTH_SECRET: "WalletService/testnet:auth_secret"
Expand All @@ -114,6 +115,7 @@ env:
testnet_FIREBASE_CLIENT_X509_CERT_URL: "WalletService/testnet:FIREBASE_CLIENT_X509_CERT_URL"
testnet_ALERT_MANAGER_REGION: "WalletService/testnet:ALERT_MANAGER_REGION"
testnet_ALERT_MANAGER_TOPIC: "WalletService/testnet:ALERT_MANAGER_TOPIC"
testnet_ALERT_MANAGER_ACCOUNT_ID: "WalletService/testnet:ALERT_MANAGER_ACCOUNT_ID"
# Mainnet Staging secrets
mainnet_staging_ACCOUNT_ID: "WalletService/mainnet_staging:account_id"
mainnet_staging_AUTH_SECRET: "WalletService/mainnet_staging:auth_secret"
Expand All @@ -139,6 +141,7 @@ env:
mainnet_staging_FIREBASE_CLIENT_X509_CERT_URL: "WalletService/mainnet_staging:FIREBASE_CLIENT_X509_CERT_URL"
mainnet_staging_ALERT_MANAGER_REGION: "WalletService/mainnet_staging:ALERT_MANAGER_REGION"
mainnet_staging_ALERT_MANAGER_TOPIC: "WalletService/mainnet_staging:ALERT_MANAGER_TOPIC"
mainnet_staging_ALERT_MANAGER_ACCOUNT_ID: "WalletService/mainnet_staging:ALERT_MANAGER_ACCOUNT_ID"
# Mainnet secrets
mainnet_ACCOUNT_ID: "WalletService/mainnet:account_id"
mainnet_AUTH_SECRET: "WalletService/mainnet:auth_secret"
Expand All @@ -164,6 +167,7 @@ env:
mainnet_FIREBASE_CLIENT_X509_CERT_URL: "WalletService/mainnet:FIREBASE_CLIENT_X509_CERT_URL"
mainnet_ALERT_MANAGER_REGION: "WalletService/mainnet:ALERT_MANAGER_REGION"
mainnet_ALERT_MANAGER_TOPIC: "WalletService/mainnet:ALERT_MANAGER_TOPIC"
mainnet_ALERT_MANAGER_ACCOUNT_ID: "WalletService/mainnet:ALERT_MANAGER_ACCOUNT_ID"
phases:
install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/utils/alerting.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export const addAlert = async (

const {
ACCOUNT_ID,
ALERT_MANAGER_ACCOUNT_ID,
ALERT_MANAGER_REGION,
ALERT_MANAGER_TOPIC,
} = process.env;

const QUEUE_URL = `https://sqs.${ALERT_MANAGER_REGION}.amazonaws.com/${ACCOUNT_ID}/${ALERT_MANAGER_TOPIC}`;
const account_id = ALERT_MANAGER_ACCOUNT_ID || ACCOUNT_ID;

Choose a reason for hiding this comment

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

suggestion(non-breaking): Add a comment or another more visible documentation informing that, if the ALERT_MANAGER_ACCOUNT_ID is not informed, the wallet service's own ACCOUNT_ID will be used as default to reach the Alert Manager.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added in 967ddb2.

const QUEUE_URL = `https://sqs.${ALERT_MANAGER_REGION}.amazonaws.com/${account_id}/${ALERT_MANAGER_TOPIC}`;

const client = new SQSClient({
endpoint: QUEUE_URL,
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const PUSH_NOTIFICATION_LAMBDA_REGION = process.env.PUSH_NOTIFICATION_LAM
export const ACCOUNT_ID = process.env.ACCOUNT_ID;
export const ALERT_MANAGER_REGION = process.env.ALERT_MANAGER_REGION;
export const ALERT_MANAGER_TOPIC = process.env.ALERT_MANAGER_TOPIC;
export const ALERT_MANAGER_ACCOUNT_ID = process.env.ALERT_MANAGER_ACCOUNT_ID;
export const AWS_REGION = process.env.AWS_REGION;

// Healthcheck configuration
Expand Down
4 changes: 4 additions & 0 deletions packages/wallet-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ PUSH_ALLOWED_PROVIDERS=android

Do not modify the `STAGE` variable. The other variables should be updated accordingly.

The following variables are optional:

- `ALERT_MANAGER_ACCOUNT_ID`: Account ID to send alerts to. If not set, `ACCOUNT_ID` will be used instead. If neither is set, alerting will not work.

### AWS cli credentials

You need to have `awscli` [configured with your credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html).
Expand Down
7 changes: 4 additions & 3 deletions packages/wallet-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ custom:
topics: # SNS Topics to send alerts to
major:
alarm:
topic: arn:aws:sns:${self:provider.region}:${self:provider.environment.ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-major
topic: arn:aws:sns:${self:provider.region}:${self:provider.environment.ALERT_MANAGER_ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-major
minor:
alarm:
topic: arn:aws:sns:${self:provider.region}:${self:provider.environment.ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-minor
topic: arn:aws:sns:${self:provider.region}:${self:provider.environment.ALERT_MANAGER_ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-minor
definitions: # Definition of alarms
majorFunctionErrors:
description: "Too many errors in hathor-wallet-service. Runbook: https://github.com/HathorNetwork/ops-tools/blob/master/docs/runbooks/wallet-service/errors-in-logs.md"
Expand Down Expand Up @@ -149,7 +149,7 @@ provider:
- sqs:*
Resource:
- Fn::GetAtt: [ WalletServiceNewTxQueue, Arn ]
- arn:aws:sqs:${self:provider.environment.ALERT_MANAGER_REGION}:${self:provider.environment.ACCOUNT_ID}:${self:provider.environment.ALERT_MANAGER_TOPIC}
- arn:aws:sqs:${self:provider.environment.ALERT_MANAGER_REGION}:${self:provider.environment.ALERT_MANAGER_ACCOUNT_ID}:${self:provider.environment.ALERT_MANAGER_TOPIC}
vpc:
securityGroupIds:
- ${env:AWS_VPC_DEFAULT_SG_ID}
Expand Down Expand Up @@ -208,6 +208,7 @@ provider:
LOG_LEVEL: ${env:LOG_LEVEL}
ALERT_MANAGER_REGION: ${env:ALERT_MANAGER_REGION}
ALERT_MANAGER_TOPIC: ${env:ALERT_MANAGER_TOPIC}
ALERT_MANAGER_ACCOUNT_ID: ${env:ALERT_MANAGER_ACCOUNT_ID}

functions:
getLatestBlock:
Expand Down
Loading