From a470ccc60e9d8696854038eef90a8cf5e20ed9c1 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 8 Sep 2023 15:04:17 +0200 Subject: [PATCH 1/6] chore: update commands to support forest-0.13.0 (#255) --- archival-snapshots-generate/README.md | 2 +- archival-snapshots-generate/src/main.rs | 7 ++----- .../daily_snapshot/service/upload_filops_snapshot.sh | 2 +- .../modules/daily_snapshot/service/upload_snapshot.sh | 8 ++++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/archival-snapshots-generate/README.md b/archival-snapshots-generate/README.md index 68e7c0f1a..3c1c38f12 100644 --- a/archival-snapshots-generate/README.md +++ b/archival-snapshots-generate/README.md @@ -2,7 +2,7 @@ This tool will generate lite and diff snapshots provided a full snapshot. # Installation -Install it with `cargo install --path .`. This tool also requires `forest-cli` in PATH. See more [here](https://github.com/ChainSafe/forest#installation). +Install it with `cargo install --path .`. This tool also requires `forest-tool` in PATH. See more [here](https://github.com/ChainSafe/forest#installation). ``` Usage: archival-snapshots-generate [OPTIONS] diff --git a/archival-snapshots-generate/src/main.rs b/archival-snapshots-generate/src/main.rs index 346e4dedd..bdcff3bbc 100644 --- a/archival-snapshots-generate/src/main.rs +++ b/archival-snapshots-generate/src/main.rs @@ -35,9 +35,6 @@ struct Args { } fn main() -> anyhow::Result<()> { - if which::which("forest-cli").is_err() { - bail!("forest-cli is not installed"); - } if which::which("forest-tool").is_err() { bail!("forest-tool is not installed"); } @@ -129,7 +126,7 @@ fn generate_lite_snapshot( snapshot_file: &Path, ) -> anyhow::Result<()> { debug!("Generating lite snapshot for epoch {epoch}"); - std::process::Command::new("forest-cli") + std::process::Command::new("forest-tool") .args([ "archive", "export", @@ -168,7 +165,7 @@ fn generate_diff_snapshot( return Ok(()); } - std::process::Command::new("forest-cli") + std::process::Command::new("forest-tool") .args([ "archive", "export", diff --git a/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh b/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh index 5f4de22fd..5d6ece2cd 100644 --- a/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh +++ b/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh @@ -34,7 +34,7 @@ send_slack_alert() { COMMANDS=$(cat << HEREDOC set -eux -cd forest_db/filops && forest-cli --chain $CHAIN snapshot fetch --vendor filops +cd forest_db/filops && forest-tool snapshot fetch --vendor filops --chain $CHAIN # Get the most recently downloaded snapshot's name DOWNLOADED_SNAPSHOT_NAME=\$(basename \$(find . -name "filops_snapshot_$CHAIN*" -type f -print0 | xargs -r -0 ls -1 -t | head -1)) diff --git a/terraform/modules/daily_snapshot/service/upload_snapshot.sh b/terraform/modules/daily_snapshot/service/upload_snapshot.sh index f667dfdce..7d0ba1353 100755 --- a/terraform/modules/daily_snapshot/service/upload_snapshot.sh +++ b/terraform/modules/daily_snapshot/service/upload_snapshot.sh @@ -59,7 +59,7 @@ echo "Snapshot: $NEWEST_SNAPSHOT" # spawn a task in the background to periodically write Prometheus metrics to a file write_metrics & -forest-cli --config config.toml --chain "$CHAIN_NAME" db clean --force +forest-tool db destroy --force --config config.toml --chain "$CHAIN_NAME" forest --config config.toml --chain "$CHAIN_NAME" --import-snapshot "$NEWEST_SNAPSHOT" --halt-after-import forest --config config.toml --chain "$CHAIN_NAME" --no-gc --save-token=token.txt --detach timeout "$SYNC_TIMEOUT" forest-cli --chain "$CHAIN_NAME" sync wait @@ -68,10 +68,10 @@ forest-cli --token=\$(cat token.txt) shutdown --force # Run full checks only for calibnet, given that it takes too long for mainnet. if [ "$CHAIN_NAME" = "calibnet" ]; then - forest-cli snapshot validate --check-network "$CHAIN_NAME" forest_db/forest_snapshot_*.forest.car.zst + forest-tool snapshot validate --check-network "$CHAIN_NAME" forest_db/forest_snapshot_*.forest.car.zst else - forest-cli archive info forest_db/forest_snapshot_*.forest.car.zst - forest-cli snapshot validate --check-links 0 --check-network "$CHAIN_NAME" --check-stateroots 5 forest_db/forest_snapshot_*.forest.car.zst + forest-tool archive info forest_db/forest_snapshot_*.forest.car.zst + forest-tool snapshot validate --check-links 0 --check-network "$CHAIN_NAME" --check-stateroots 5 forest_db/forest_snapshot_*.forest.car.zst fi From b9dc1f165214029ba6866a6e75091cfffd691e71 Mon Sep 17 00:00:00 2001 From: Guillaume Potier Date: Fri, 8 Sep 2023 15:24:16 +0200 Subject: [PATCH 2/6] fix: forest binary reorg (#216) Signed-off-by: samuelarogbonlo Co-authored-by: samuelarogbonlo Co-authored-by: Samuel Arogbonlo <47984109+samuelarogbonlo@users.noreply.github.com> --- terraform/forest-calibnet/main.tf | 1 + terraform/forest-mainnet/main.tf | 1 + terraform/lotus-mainnet/main.tf | 1 + terraform/modules/daily_snapshot/main.tf | 2 +- .../modules/daily_snapshot/service/upload_filops_snapshot.sh | 1 + terraform/modules/daily_snapshot/service/upload_snapshot.sh | 1 + terraform/modules/filecoin_node/firewall.tf | 2 +- terraform/modules/filecoin_node/forest.sh | 2 +- terraform/modules/filecoin_node/variable.tf | 5 +++++ 9 files changed, 13 insertions(+), 3 deletions(-) diff --git a/terraform/forest-calibnet/main.tf b/terraform/forest-calibnet/main.tf index e960c8e26..7526d774c 100644 --- a/terraform/forest-calibnet/main.tf +++ b/terraform/forest-calibnet/main.tf @@ -24,6 +24,7 @@ module "calibnet" { attach_volume = false destination_addresses = var.destination_addresses chain = var.chain + rpc_port = "2345" project = var.project fw_name = var.fw_name NR_LICENSE_KEY = var.NR_LICENSE_KEY diff --git a/terraform/forest-mainnet/main.tf b/terraform/forest-mainnet/main.tf index a52c1d121..655475548 100644 --- a/terraform/forest-mainnet/main.tf +++ b/terraform/forest-mainnet/main.tf @@ -24,6 +24,7 @@ module "mainnet" { initial_filesystem_type = var.initial_filesystem_type volume_size = var.volume_size attach_volume = false + rpc_port = "2345" destination_addresses = var.destination_addresses chain = var.chain volume_name = var.volume_name diff --git a/terraform/lotus-mainnet/main.tf b/terraform/lotus-mainnet/main.tf index aecb83c94..4cfd5ef3b 100644 --- a/terraform/lotus-mainnet/main.tf +++ b/terraform/lotus-mainnet/main.tf @@ -30,6 +30,7 @@ module "lotus-mainnet" { fw_name = "lotus-mainnet-fw" script = "lotus.sh" forest_user = "forest" + rpc_port = "1234" NR_LICENSE_KEY = var.NR_LICENSE_KEY NEW_RELIC_API_KEY = var.NEW_RELIC_API_KEY NEW_RELIC_ACCOUNT_ID = var.NEW_RELIC_ACCOUNT_ID diff --git a/terraform/modules/daily_snapshot/main.tf b/terraform/modules/daily_snapshot/main.tf index 9632ca3ba..64055cba1 100644 --- a/terraform/modules/daily_snapshot/main.tf +++ b/terraform/modules/daily_snapshot/main.tf @@ -141,7 +141,7 @@ resource "digitalocean_firewall" "forest-firewall" { inbound_rule { protocol = "tcp" - port_range = "1234" + port_range = "2345" source_addresses = var.source_addresses } diff --git a/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh b/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh index 5d6ece2cd..92976fa44 100644 --- a/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh +++ b/terraform/modules/daily_snapshot/service/upload_filops_snapshot.sh @@ -36,6 +36,7 @@ COMMANDS=$(cat << HEREDOC set -eux cd forest_db/filops && forest-tool snapshot fetch --vendor filops --chain $CHAIN + # Get the most recently downloaded snapshot's name DOWNLOADED_SNAPSHOT_NAME=\$(basename \$(find . -name "filops_snapshot_$CHAIN*" -type f -print0 | xargs -r -0 ls -1 -t | head -1)) diff --git a/terraform/modules/daily_snapshot/service/upload_snapshot.sh b/terraform/modules/daily_snapshot/service/upload_snapshot.sh index 7d0ba1353..43b977639 100755 --- a/terraform/modules/daily_snapshot/service/upload_snapshot.sh +++ b/terraform/modules/daily_snapshot/service/upload_snapshot.sh @@ -60,6 +60,7 @@ echo "Snapshot: $NEWEST_SNAPSHOT" write_metrics & forest-tool db destroy --force --config config.toml --chain "$CHAIN_NAME" + forest --config config.toml --chain "$CHAIN_NAME" --import-snapshot "$NEWEST_SNAPSHOT" --halt-after-import forest --config config.toml --chain "$CHAIN_NAME" --no-gc --save-token=token.txt --detach timeout "$SYNC_TIMEOUT" forest-cli --chain "$CHAIN_NAME" sync wait diff --git a/terraform/modules/filecoin_node/firewall.tf b/terraform/modules/filecoin_node/firewall.tf index e53b2362f..4adc889f9 100644 --- a/terraform/modules/filecoin_node/firewall.tf +++ b/terraform/modules/filecoin_node/firewall.tf @@ -9,7 +9,7 @@ resource "digitalocean_firewall" "forest_firewall" { inbound_rule { protocol = "tcp" - port_range = "1234" + port_range = var.rpc_port source_addresses = var.source_addresses } diff --git a/terraform/modules/filecoin_node/forest.sh b/terraform/modules/filecoin_node/forest.sh index a222feef8..2d0f1e46b 100644 --- a/terraform/modules/filecoin_node/forest.sh +++ b/terraform/modules/filecoin_node/forest.sh @@ -56,7 +56,7 @@ sudo --user="${NEW_USER}" -- \ --name=forest-"${CHAIN}" \ --env "FOREST_GC_TRIGGER_FACTOR=1.4" \ --volume=/home/"${NEW_USER}"/forest_data:/home/"${NEW_USER}"/forest_data:z \ - --publish=1234:1234 \ + --publish=2345:2345 \ --publish=6116:6116 \ --restart=always \ ghcr.io/chainsafe/forest:latest \ diff --git a/terraform/modules/filecoin_node/variable.tf b/terraform/modules/filecoin_node/variable.tf index 7e1806707..b27837225 100644 --- a/terraform/modules/filecoin_node/variable.tf +++ b/terraform/modules/filecoin_node/variable.tf @@ -55,6 +55,11 @@ variable "destination_addresses" { type = list(string) } +variable "rpc_port" { + description = "RPC Port for nodes" + type = string +} + variable "chain" { description = "The chain tag to apply to resources." type = string From e0b32f078928c86ba1f781bc36ab026fe1a51418 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Thu, 14 Sep 2023 15:52:51 +0200 Subject: [PATCH 3/6] feat: cf worker for fetching most recent snapshots (#261) --- cf/latest-snapshot/.editorconfig | 13 +++++++++ cf/latest-snapshot/.prettierrc | 19 ++++++++++++++ cf/latest-snapshot/README.md | 12 +++++++++ cf/latest-snapshot/package.json | 14 ++++++++++ cf/latest-snapshot/src/index.ts | 45 ++++++++++++++++++++++++++++++++ cf/latest-snapshot/tsconfig.json | 12 +++++++++ cf/latest-snapshot/wrangler.toml | 13 +++++++++ 7 files changed, 128 insertions(+) create mode 100644 cf/latest-snapshot/.editorconfig create mode 100644 cf/latest-snapshot/.prettierrc create mode 100644 cf/latest-snapshot/README.md create mode 100644 cf/latest-snapshot/package.json create mode 100644 cf/latest-snapshot/src/index.ts create mode 100644 cf/latest-snapshot/tsconfig.json create mode 100644 cf/latest-snapshot/wrangler.toml diff --git a/cf/latest-snapshot/.editorconfig b/cf/latest-snapshot/.editorconfig new file mode 100644 index 000000000..64ab2601f --- /dev/null +++ b/cf/latest-snapshot/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = tab +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space diff --git a/cf/latest-snapshot/.prettierrc b/cf/latest-snapshot/.prettierrc new file mode 100644 index 000000000..557d4d5a7 --- /dev/null +++ b/cf/latest-snapshot/.prettierrc @@ -0,0 +1,19 @@ +{ + "semi": true, + "printWidth": 100, + "singleQuote": true, + "bracketSpacing": true, + "insertPragma": false, + "requirePragma": false, + "jsxSingleQuote": false, + "bracketSameLine": false, + "embeddedLanguageFormatting": "auto", + "htmlWhitespaceSensitivity": "css", + "vueIndentScriptAndStyle": true, + "quoteProps": "consistent", + "proseWrap": "preserve", + "trailingComma": "es5", + "arrowParens": "avoid", + "useTabs": true, + "tabWidth": 2 +} diff --git a/cf/latest-snapshot/README.md b/cf/latest-snapshot/README.md new file mode 100644 index 000000000..9f675ead3 --- /dev/null +++ b/cf/latest-snapshot/README.md @@ -0,0 +1,12 @@ +# Snapshot redirect worker + +This worker acts on two endpoints: + +- `https://forest-archive.chainsafe.dev/latest/calibnet/` +- `https://forest-archive.chainsafe.dev/latest/mainnet/` + +These links will download the latest available snapshot for calibnet and mainnet, respectively. + +# Local deployment + +Use `wrangler dev` to deploy a local version of this worker which will use the `forest-archive-dev` bucket rather than the production `forest-archive` bucket. Merging changes to this worker will automatically deploy them. diff --git a/cf/latest-snapshot/package.json b/cf/latest-snapshot/package.json new file mode 100644 index 000000000..d9d03b086 --- /dev/null +++ b/cf/latest-snapshot/package.json @@ -0,0 +1,14 @@ +{ + "name": "forest-latest-snapshot", + "version": "0.0.0", + "private": true, + "scripts": { + "deploy": "wrangler deploy src/index.ts", + "dev": "wrangler dev src/index.ts --local", + "start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20230904.0", + "wrangler": "^3.0.0" + } +} diff --git a/cf/latest-snapshot/src/index.ts b/cf/latest-snapshot/src/index.ts new file mode 100644 index 000000000..1eb008704 --- /dev/null +++ b/cf/latest-snapshot/src/index.ts @@ -0,0 +1,45 @@ +interface Env { + FOREST_ARCHIVE: R2Bucket, +} + +function basename(path: String) { + return path.split('/').reverse()[0]; +} + +// Directly fetch the data for the latest snapshot of a given chain (eg. calibnet or mainnet) +async function get_latest(env: Env, chain: string): Promise { + const listed = await env.FOREST_ARCHIVE.list({ prefix: chain + "/latest/" }); + let latest = listed.objects.at(-1); + if (latest == null) { + return new Response(`No latest snapshot found ${chain}`, { + status: 404, + }); + } else { + // Should we support range queries? + const object = await env.FOREST_ARCHIVE.get(latest.key); + if (object === null) { + return new Response('No latest snapshot found', { + status: 404, + }); + } + const headers = new Headers(); + object.writeHttpMetadata(headers); + headers.set('etag', object.httpEtag); + let encoded_name = encodeURIComponent(basename(object.key)); + // Tell browsers and aria2c which filename to use. For 'wget', you have to use `--trust-server-names`. + headers.set('content-disposition', `attachment; filename*=UTF-8''${encoded_name}; filename="${encoded_name}"`); + + return new Response(object.body, { + headers, + }); + } +} + +export default { + async fetch(request: Request, env: Env): Promise { + const url = new URL(request.url); + const chain = (url.pathname.match(/\/latest\/(\w*)/) || ["undefined"])[1]; + + return await get_latest(env, chain); + }, +}; diff --git a/cf/latest-snapshot/tsconfig.json b/cf/latest-snapshot/tsconfig.json new file mode 100644 index 000000000..3ca1f9899 --- /dev/null +++ b/cf/latest-snapshot/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "noEmit": true, + "module": "esnext", + "target": "esnext", + "lib": ["esnext"], + "strict": true, + "moduleResolution": "node", + "types": ["@cloudflare/workers-types", "@types/jest"] + }, + "exclude": ["node_modules", "dist"] +} diff --git a/cf/latest-snapshot/wrangler.toml b/cf/latest-snapshot/wrangler.toml new file mode 100644 index 000000000..cd6fc7a68 --- /dev/null +++ b/cf/latest-snapshot/wrangler.toml @@ -0,0 +1,13 @@ +name = "forest-latest-snapshot" +main = "./src/index.ts" + +compatibility_date = "2022-06-30" + +routes = [ + { pattern = "forest-archive.chainsafe.dev/latest/calibnet/", zone_name = "chainsafe.dev" }, + { pattern = "forest-archive.chainsafe.dev/latest/mainnet/", zone_name = "chainsafe.dev" }, +] + +[[r2_buckets]] +binding = 'FOREST_ARCHIVE' # can be any valid JavaScript variable name +bucket_name = 'forest-archive' From f3b5b418b3725a2f463026ad71592750b98effea Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Mon, 18 Sep 2023 11:16:17 +0200 Subject: [PATCH 4/6] feat: cf worker for pruning snapshots (#260) --- cf/prune-latest/README.md | 7 +++++++ cf/prune-latest/package.json | 14 ++++++++++++++ cf/prune-latest/src/index.ts | 26 ++++++++++++++++++++++++++ cf/prune-latest/tsconfig.json | 12 ++++++++++++ cf/prune-latest/wrangler.toml | 16 ++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 cf/prune-latest/README.md create mode 100644 cf/prune-latest/package.json create mode 100644 cf/prune-latest/src/index.ts create mode 100644 cf/prune-latest/tsconfig.json create mode 100644 cf/prune-latest/wrangler.toml diff --git a/cf/prune-latest/README.md b/cf/prune-latest/README.md new file mode 100644 index 000000000..e9da71dbe --- /dev/null +++ b/cf/prune-latest/README.md @@ -0,0 +1,7 @@ +# Deployment + +This worker is automatically deployed when modified. To test locally, run `wrangler dev`. This will run the worker against the development bucket `forest-archive-dev`. Once the worker is deployed to production, it'll use the `forest-archive` bucket. + +# Pruning + +We upload new Filecoin snapshots to CloudFlare every hour and keep only the 10 most recent. The CloudFlare worker script is triggered automatically every hour. diff --git a/cf/prune-latest/package.json b/cf/prune-latest/package.json new file mode 100644 index 000000000..218df7a32 --- /dev/null +++ b/cf/prune-latest/package.json @@ -0,0 +1,14 @@ +{ + "name": "template-worker-r2", + "version": "0.0.0", + "private": true, + "scripts": { + "deploy": "wrangler deploy src/index.ts", + "dev": "wrangler dev src/index.ts --local", + "start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20230904.0", + "wrangler": "^3.0.0" + } +} diff --git a/cf/prune-latest/src/index.ts b/cf/prune-latest/src/index.ts new file mode 100644 index 000000000..af873c419 --- /dev/null +++ b/cf/prune-latest/src/index.ts @@ -0,0 +1,26 @@ +export interface Env { + FOREST_ARCHIVE: R2Bucket +} + +// Number of recent snapshots to keep. Roughly 1 new snapshot is uploaded every hour. +const KEEP_COUNT: number = 10; + +async function prune(env: Env, chain: string): Promise { + const listed = await env.FOREST_ARCHIVE.list({ prefix: chain + "/latest/" }); + // objects are listed chronologically. Reverse to keep the newest snapshots. + listed.objects.reverse(); + for (let i: number = KEEP_COUNT; i < listed.objects.length; i++) { + await env.FOREST_ARCHIVE.delete(listed.objects[i].key); + } + const pruned = Math.max(listed.objects.length - KEEP_COUNT, 0); + const kept = listed.objects.length - pruned; + return `Pruned: ${pruned}. Kept: ${kept}`; +} + +export default { + async fetch(request: Request, env: Env): Promise { + const calibnet = await prune(env, 'calibnet'); + const mainnet = await prune(env, 'mainnet'); + return new Response(`Calibnet: ${calibnet}\nMainnet: ${mainnet}\n`); + } +}; diff --git a/cf/prune-latest/tsconfig.json b/cf/prune-latest/tsconfig.json new file mode 100644 index 000000000..3ca1f9899 --- /dev/null +++ b/cf/prune-latest/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "noEmit": true, + "module": "esnext", + "target": "esnext", + "lib": ["esnext"], + "strict": true, + "moduleResolution": "node", + "types": ["@cloudflare/workers-types", "@types/jest"] + }, + "exclude": ["node_modules", "dist"] +} diff --git a/cf/prune-latest/wrangler.toml b/cf/prune-latest/wrangler.toml new file mode 100644 index 000000000..e16dee3cc --- /dev/null +++ b/cf/prune-latest/wrangler.toml @@ -0,0 +1,16 @@ +name = "forest-prune-latest" +main = "./src/index.ts" + +compatibility_date = "2022-06-30" + +routes = [ + { pattern = "forest-archive.chainsafe.dev/prune/", zone_name = "chainsafe.dev" }, +] + +[[r2_buckets]] +binding = 'FOREST_ARCHIVE' # can be any valid JavaScript variable name +bucket_name = 'forest-archive' +preview_bucket_name = 'forest-archive-dev' + +[triggers] +crons = ["0 * * * *"] From 6d8bcb6f997b7e889e0e3f1703cb08be619dca82 Mon Sep 17 00:00:00 2001 From: Samuel Arogbonlo <47984109+samuelarogbonlo@users.noreply.github.com> Date: Tue, 19 Sep 2023 08:27:36 +0100 Subject: [PATCH 5/6] fix: update snapshot-check slack error message to follow conventions (#263) Signed-off-by: samuelarogbonlo --- .../packages/monitor-snapshot/main/__main__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/do_function/monitor_snapshots/packages/monitor-snapshot/main/__main__.py b/do_function/monitor_snapshots/packages/monitor-snapshot/main/__main__.py index 9ec6c8f0b..1205aa930 100644 --- a/do_function/monitor_snapshots/packages/monitor-snapshot/main/__main__.py +++ b/do_function/monitor_snapshots/packages/monitor-snapshot/main/__main__.py @@ -25,9 +25,6 @@ def slack_alert(message, thread_ts=None): client = WebClient(token=os.environ['SLACK_TOKEN']) CHANNEL_NAME = '#forest-notifications' - # Format message as a JSON-like string for better readability. - message = f'```{json.dumps(message, indent=4, ensure_ascii=False)}```' - # Try sending message, catch and print any errors. try: response = client.chat_postMessage(channel=CHANNEL_NAME, text=message, thread_ts=thread_ts) @@ -141,7 +138,7 @@ def main(): if not checks_passed: thread = slack_alert("⛔ Snapshot check failed. 🔥🌲🔥") for error_message in error_messages: - slack_alert({"error": error_message}, thread_ts=thread) + slack_alert(error_message, thread_ts=thread) return { "result": "⛔ failure", "message": "Some checks did not pass. Please review the issues reported. Let's fix them and keep the forest green!. 🔥🌲🔥" From 4a2d495e5397ac1347f14db8d0cb48ed948d408b Mon Sep 17 00:00:00 2001 From: Samuel Arogbonlo <47984109+samuelarogbonlo@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:21:28 +0100 Subject: [PATCH 6/6] chore: install new relic on the benchmark service (#258) Signed-off-by: samuelarogbonlo --- .github/workflows/deploy-benchmark.yml | 2 ++ terraform/benchmark/.terraform.lock.hcl | 3 ++ terraform/benchmark/main.tf | 2 ++ terraform/benchmark/variable.tf | 12 +++++++ terraform/modules/benchmark/main.tf | 3 ++ terraform/modules/benchmark/service/init.sh | 34 ++++++++++++++++++++ terraform/modules/benchmark/variable.tf | 18 +++++++++++ terraform/modules/daily_snapshot/variable.tf | 2 +- terraform/modules/filecoin_node/variable.tf | 2 +- terraform/modules/sync_check/variable.tf | 2 +- 10 files changed, 77 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-benchmark.yml b/.github/workflows/deploy-benchmark.yml index 33082b43f..57ca13898 100644 --- a/.github/workflows/deploy-benchmark.yml +++ b/.github/workflows/deploy-benchmark.yml @@ -34,5 +34,7 @@ jobs: aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} slack_token: ${{ secrets.SLACK_TOKEN }} + new_relic_account_id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }} + new_relic_api_key: ${{ secrets.NEW_RELIC_API_KEY }} working_directory: terraform/benchmark environment: Benchmark Service diff --git a/terraform/benchmark/.terraform.lock.hcl b/terraform/benchmark/.terraform.lock.hcl index e4f85802d..ae80807ad 100644 --- a/terraform/benchmark/.terraform.lock.hcl +++ b/terraform/benchmark/.terraform.lock.hcl @@ -5,6 +5,7 @@ provider "registry.terraform.io/digitalocean/digitalocean" { version = "2.29.0" constraints = "~> 2.0" hashes = [ + "h1:KSmD5RdWr/Go4Q5GlY9QsfSm1vtKxBJjJe3M5gaQXjg=", "h1:OLSxMaqLOUl6DjQ3vz14odCyMCcLA63ltBNPgrIQHG4=", "zh:0af0a1a2de818c5dc8ee7ad4dc4731452848e84cfa0c1ce514af1c7aad15c53c", "zh:27229f3162b4142be48554f56227265982f3b74e4c79fa5d2528c8a3912d1e19", @@ -29,6 +30,7 @@ provider "registry.terraform.io/hashicorp/external" { version = "2.3.1" constraints = "~> 2.1" hashes = [ + "h1:9rJggijNdRdFk//ViQPGZdK0xu9XU/9qBDijNsZJMg0=", "h1:bROCw6g5D/3fFnWeJ01L4IrdnJl1ILU8DGDgXCtYzaY=", "zh:001e2886dc81fc98cf17cf34c0d53cb2dae1e869464792576e11b0f34ee92f54", "zh:2eeac58dd75b1abdf91945ac4284c9ccb2bfb17fa9bdb5f5d408148ff553b3ee", @@ -49,6 +51,7 @@ provider "registry.terraform.io/hashicorp/local" { version = "2.4.0" constraints = "~> 2.1" hashes = [ + "h1:Bs7LAkV/iQTLv72j+cTMrvx2U3KyXrcVHaGbdns1NcE=", "h1:R97FTYETo88sT2VHfMgkPU3lzCsZLunPftjSI5vfKe8=", "zh:53604cd29cb92538668fe09565c739358dc53ca56f9f11312b9d7de81e48fab9", "zh:66a46e9c508716a1c98efbf793092f03d50049fa4a83cd6b2251e9a06aca2acf", diff --git a/terraform/benchmark/main.tf b/terraform/benchmark/main.tf index e445d4ef2..94d9a68d7 100644 --- a/terraform/benchmark/main.tf +++ b/terraform/benchmark/main.tf @@ -39,6 +39,8 @@ module "benchmark" { AWS_ACCESS_KEY_ID = var.AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY = var.AWS_SECRET_ACCESS_KEY digitalocean_token = var.do_token + NEW_RELIC_API_KEY = var.NEW_RELIC_API_KEY + NEW_RELIC_ACCOUNT_ID = var.NEW_RELIC_ACCOUNT_ID } # This ip address may be used in the future by monitoring software diff --git a/terraform/benchmark/variable.tf b/terraform/benchmark/variable.tf index 7205d992d..c4872c2a9 100644 --- a/terraform/benchmark/variable.tf +++ b/terraform/benchmark/variable.tf @@ -17,3 +17,15 @@ variable "slack_token" { description = "slack access token" type = string } + +variable "NEW_RELIC_API_KEY" { + description = "New Relic API KEY" + default = "" + type = string +} + +variable "NEW_RELIC_ACCOUNT_ID" { + description = "New Relic Account ID" + default = "" + type = string +} diff --git a/terraform/modules/benchmark/main.tf b/terraform/modules/benchmark/main.tf index 182f05215..d5c510f5b 100644 --- a/terraform/modules/benchmark/main.tf +++ b/terraform/modules/benchmark/main.tf @@ -65,6 +65,9 @@ locals { "echo 'export SLACK_NOTIF_CHANNEL=\"${var.slack_channel}\"' >> .forest_env", "echo 'export BENCHMARK_BUCKET=\"${var.benchmark_bucket}\"' >> .forest_env", "echo 'export BENCHMARK_ENDPOINT=\"${var.benchmark_endpoint}\"' >> .forest_env", + "echo 'export NEW_RELIC_API_KEY=\"${var.NEW_RELIC_API_KEY}\"' >> .forest_env", + "echo 'export NEW_RELIC_ACCOUNT_ID=\"${var.NEW_RELIC_ACCOUNT_ID}\"' >> .forest_env", + "echo 'export NEW_RELIC_REGION=\"${var.NEW_RELIC_REGION}\"' >> .forest_env", "echo 'export BASE_FOLDER=\"/chainsafe\"' >> .forest_env", "echo '. ~/.forest_env' >> .bashrc", ". ~/.forest_env", diff --git a/terraform/modules/benchmark/service/init.sh b/terraform/modules/benchmark/service/init.sh index 9e0b4f461..4770d2cc7 100755 --- a/terraform/modules/benchmark/service/init.sh +++ b/terraform/modules/benchmark/service/init.sh @@ -18,3 +18,37 @@ sudo docker run --detach \ --restart unless-stopped \ benchmark \ /bin/bash -c "ruby run_benchmark.rb" + +# If New Relic license key and API key are provided, +# install the new relic agent and New relic agent and OpenMetrics Prometheus integration. +if [ -n "${NEW_RELIC_API_KEY}" ]; then + curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && \ + sudo NEW_RELIC_API_KEY="${NEW_RELIC_API_KEY}" \ + NEW_RELIC_ACCOUNT_ID="${NEW_RELIC_ACCOUNT_ID}" \ + NEW_RELIC_REGION="${NEW_RELIC_REGION}" \ + /usr/local/bin/newrelic install -y + +# The provided configurations are specific to New Relic. To gain a deeper understanding of these configuration details, you can visit: +# https://docs.newrelic.com/docs/infrastructure/install-infrastructure-agent/configuration/infrastructure-agent-configuration-settings/#offline-time-to-reset +cat >> /etc/newrelic-infra.yml <