From 94bd1c10ecb257fd5cea09d9f8c0731c6e9e2ec2 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Sat, 1 Feb 2025 21:27:27 -0800 Subject: [PATCH] [testing] Simplify log and metric collection Update to use the avalanchego nix flake to install promtail and prometheus and have tmpnet run them, removing the need for the run_prometheus.sh and run_promtail.sh scripts. --- .github/workflows/tests.yml | 30 ++++----- flake.lock | 59 ++++++++++++++++++ flake.nix | 24 ++++++++ go.mod | 4 +- go.sum | 12 ++-- scripts/run_prometheus.sh | 120 ------------------------------------ scripts/run_promtail.sh | 115 ---------------------------------- scripts/versions.sh | 2 +- 8 files changed, 106 insertions(+), 260 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100755 scripts/run_prometheus.sh delete mode 100755 scripts/run_promtail.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 479877a8b9..36db584f89 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -147,18 +147,15 @@ jobs: shell: bash run: ./scripts/build.sh - name: Run Warp E2E Tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@v1.11.13 + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@424f7dc65171573bda0dd3537a0520febf1a73eb with: - run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego ./scripts/run_ginkgo_warp.sh - prometheus_id: ${{ secrets.PROMETHEUS_ID || '' }} + run: ./scripts/run_ginkgo_warp.sh + run_env: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego + artifact_prefix: warp + prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} - loki_id: ${{ secrets.LOKI_ID || '' }} + loki_username: ${{ secrets.LOKI_ID || '' }} loki_password: ${{ secrets.LOKI_PASSWORD || '' }} - - name: Upload tmpnet network dir for warp testing - uses: ava-labs/avalanchego/.github/actions/upload-tmpnet-artifact@v1-actions - if: always() - with: - name: warp-tmpnet-data e2e_load: name: e2e load tests runs-on: ubuntu-latest @@ -178,18 +175,15 @@ jobs: shell: bash run: ./scripts/build.sh - name: Run E2E Load Tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@v1.11.13 + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@424f7dc65171573bda0dd3537a0520febf1a73eb with: - run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego ./scripts/run_ginkgo_load.sh - prometheus_id: ${{ secrets.PROMETHEUS_ID || '' }} + run: ./scripts/run_ginkgo_load.sh + run_env: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego + artifact_prefix: load + prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} - loki_id: ${{ secrets.LOKI_ID || '' }} + loki_username: ${{ secrets.LOKI_ID || '' }} loki_password: ${{ secrets.LOKI_PASSWORD || '' }} - - name: Upload tmpnet network dir for load testing - uses: ava-labs/avalanchego/.github/actions/upload-tmpnet-artifact@v1-actions - if: always() - with: - name: load-tmpnet-data test_build_image: name: Image build runs-on: ubuntu-latest diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..e32b17f61d --- /dev/null +++ b/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "avalanchego": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1740253925, + "narHash": "sha256-Y59RYfnIfw7w1cR6hjP6wuwKdpZXtEDs6qlqa3oYZ0E=", + "owner": "ava-labs", + "repo": "avalanchego", + "rev": "194a2d3e1ff668d601005b5fd60bd74384ced90d", + "type": "github" + }, + "original": { + "owner": "ava-labs", + "ref": "194a2d3e1ff668d601005b5fd60bd74384ced90d", + "repo": "avalanchego", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1721949857, + "narHash": "sha256-DID446r8KsmJhbCzx4el8d9SnPiE8qa6+eEQOJ40vR0=", + "rev": "a1cc729dcbc31d9b0d11d86dc7436163548a9665", + "revCount": 633481, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2405.633481%2Brev-a1cc729dcbc31d9b0d11d86dc7436163548a9665/0190ef32-8438-79be-9d83-2e97dc792840/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2405.%2A.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", + "revCount": 637546, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2405.637546%2Brev-b134951a4c9f3c995fd7be05f3243f8ecd65d798/01941dc2-2ab2-7453-8ebd-88712e28efae/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2405.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "avalanchego": "avalanchego", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..1b5221f210 --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + # To use: + # - install nix: https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#install-nix + # - run `nix develop` or use direnv (https://direnv.net/) + # - for quieter direnv output, set `export DIRENV_LOG_FORMAT=` + + description = "Subnet-EVM development environment"; + + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*.tar.gz"; + avalanchego.url = "github:ava-labs/avalanchego?ref=424f7dc65171573bda0dd3537a0520febf1a73eb"; + }; + + outputs = { self, nixpkgs, avalanchego, ... }: + let + allSystems = builtins.attrNames avalanchego.devShells; + forAllSystems = nixpkgs.lib.genAttrs allSystems; + in { + # Define the development shells for this repository + devShells = forAllSystems (system: { + default = avalanchego.devShells.${system}.default; + }); + }; +} diff --git a/go.mod b/go.mod index c77e869795..2debb855a3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.6 require ( github.com/VictoriaMetrics/fastcache v1.12.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/avalanchego v1.12.3-0.20250218154446-f1ec9a13b90a + github.com/ava-labs/avalanchego v1.12.3-0.20250224213359-424f7dc65171 github.com/cespare/cp v0.1.0 github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 github.com/davecgh/go-spew v1.1.1 @@ -57,7 +57,7 @@ require ( require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect - github.com/ava-labs/coreth v0.14.1-rc.1.0.20250217192834-6060a4a6a6d3 // indirect + github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect diff --git a/go.sum b/go.sum index f5f6740c90..03b21d08b8 100644 --- a/go.sum +++ b/go.sum @@ -60,10 +60,10 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/avalanchego v1.12.3-0.20250218154446-f1ec9a13b90a h1:cBuGdwpaB1TBnfHS0w7oJyBJlM2UGOS4CEioxqMCG2g= -github.com/ava-labs/avalanchego v1.12.3-0.20250218154446-f1ec9a13b90a/go.mod h1:pgUuh27zaeaXeMiIqqu/OWpbAhJQkYMJMft6nxXG9FE= -github.com/ava-labs/coreth v0.14.1-rc.1.0.20250217192834-6060a4a6a6d3 h1:0OrQidq+b3kb7KlnDqc5mkB/73i1zxYEMiXioWSU4+w= -github.com/ava-labs/coreth v0.14.1-rc.1.0.20250217192834-6060a4a6a6d3/go.mod h1:/XrU+CAm/0wiY5Ui05TLj2/n+czbCV6/Qrw/UMWp5aI= +github.com/ava-labs/avalanchego v1.12.3-0.20250224213359-424f7dc65171 h1:+2PsU3HZw4sAA0q9WM8/P8K421m34s8amOxhmx6Y5pA= +github.com/ava-labs/avalanchego v1.12.3-0.20250224213359-424f7dc65171/go.mod h1:DfZ1/FHFxr1XnpDMfbMmex8bKxAtIISCGASdMUNFXtY= +github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450 h1:xSoL6plkPrb2w21v4JRnQg3BIJSg2svBHXyil09RMAg= +github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450/go.mod h1:AEQcF8MWrKH0sS114wEZlkSfeGF5F66xTbQYqqimNLI= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -378,6 +378,8 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -468,6 +470,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= diff --git a/scripts/run_prometheus.sh b/scripts/run_prometheus.sh deleted file mode 100755 index dce9ef1e30..0000000000 --- a/scripts/run_prometheus.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Starts a prometheus instance in agent-mode, forwarding to a central -# instance. Intended to enable metrics collection from temporary networks running -# locally and in CI. -# -# The prometheus instance will remain running in the background and will forward -# metrics to the central instance for all tmpnet networks. -# -# To stop it: -# -# $ kill -9 `cat ~/.tmpnet/prometheus/run.pid` && rm ~/.tmpnet/prometheus/run.pid -# - -# e.g., -# PROMETHEUS_ID= PROMETHEUS_PASSWORD= ./scripts/run_prometheus.sh -if ! [[ "$0" =~ scripts/run_prometheus.sh ]]; then - echo "must be run from repository root" - exit 255 -fi - -PROMETHEUS_WORKING_DIR="${HOME}/.tmpnet/prometheus" -PIDFILE="${PROMETHEUS_WORKING_DIR}"/run.pid - -# First check if an agent-mode prometheus is already running. A single instance can collect -# metrics from all local temporary networks. -if pgrep --pidfile="${PIDFILE}" -f 'prometheus.*enable-feature=agent' &> /dev/null; then - echo "prometheus is already running locally with --enable-feature=agent" - exit 0 -fi - -PROMETHEUS_URL="${PROMETHEUS_URL:-https://prometheus-poc.avax-dev.network}" -if [[ -z "${PROMETHEUS_URL}" ]]; then - echo "Please provide a value for PROMETHEUS_URL" - exit 1 -fi - -PROMETHEUS_ID="${PROMETHEUS_ID:-}" -if [[ -z "${PROMETHEUS_ID}" ]]; then - echo "Please provide a value for PROMETHEUS_ID" - exit 1 -fi - -PROMETHEUS_PASSWORD="${PROMETHEUS_PASSWORD:-}" -if [[ -z "${PROMETHEUS_PASSWORD}" ]]; then - echo "Plase provide a value for PROMETHEUS_PASSWORD" - exit 1 -fi - -# This was the LTS version when this script was written. Probably not -# much reason to update it unless something breaks since the usage -# here is only to collect metrics from temporary networks. -VERSION="2.45.3" - -# Ensure the prometheus command is locally available -CMD=prometheus -if ! command -v "${CMD}" &> /dev/null; then - # Try to use a local version - CMD="${PWD}/bin/prometheus" - if ! command -v "${CMD}" &> /dev/null; then - echo "prometheus not found, attempting to install..." - - # Determine the arch - if which sw_vers &> /dev/null; then - echo "on macos, only amd64 binaries are available so rosetta is required on apple silicon machines." - echo "to avoid using rosetta, install via homebrew: brew install prometheus" - DIST=darwin - else - ARCH="$(uname -i)" - if [[ "${ARCH}" != "x86_64" ]]; then - echo "on linux, only amd64 binaries are available. manual installation of prometheus is required." - exit 1 - else - DIST="linux" - fi - fi - - # Install the specified release - PROMETHEUS_FILE="prometheus-${VERSION}.${DIST}-amd64" - URL="https://github.com/prometheus/prometheus/releases/download/v${VERSION}/${PROMETHEUS_FILE}.tar.gz" - curl -s -L "${URL}" | tar zxv -C /tmp > /dev/null - mkdir -p "$(dirname "${CMD}")" - cp /tmp/"${PROMETHEUS_FILE}/prometheus" "${CMD}" - fi -fi - -# Configure prometheus -FILE_SD_PATH="${PROMETHEUS_WORKING_DIR}/file_sd_configs" -mkdir -p "${FILE_SD_PATH}" - -echo "writing configuration..." -cat >"${PROMETHEUS_WORKING_DIR}"/prometheus.yaml < prometheus.log 2>&1 & -echo $! > "${PIDFILE}" -echo "running with pid $(cat "${PIDFILE}")" diff --git a/scripts/run_promtail.sh b/scripts/run_promtail.sh deleted file mode 100755 index 5811dcf06f..0000000000 --- a/scripts/run_promtail.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Starts a promtail instance to collect logs from temporary networks -# running locally and in CI. -# -# The promtail instance will remain running in the background and will forward -# logs to the central instance for all tmpnet networks. -# -# To stop it: -# -# $ kill -9 `cat ~/.tmpnet/promtail/run.pid` && rm ~/.tmpnet/promtail/run.pid -# - -# e.g., -# LOKI_ID= LOKI_PASSWORD= ./scripts/run_promtail.sh -if ! [[ "$0" =~ scripts/run_promtail.sh ]]; then - echo "must be run from repository root" - exit 255 -fi - -PROMTAIL_WORKING_DIR="${HOME}/.tmpnet/promtail" -PIDFILE="${PROMTAIL_WORKING_DIR}"/run.pid - -# First check if promtail is already running. A single instance can -# collect logs from all local temporary networks. -if pgrep --pidfile="${PIDFILE}" &> /dev/null; then - echo "promtail is already running" - exit 0 -fi - -LOKI_URL="${LOKI_URL:-https://loki-poc.avax-dev.network}" -if [[ -z "${LOKI_URL}" ]]; then - echo "Please provide a value for LOKI_URL" - exit 1 -fi - -LOKI_ID="${LOKI_ID:-}" -if [[ -z "${LOKI_ID}" ]]; then - echo "Please provide a value for LOKI_ID" - exit 1 -fi - -LOKI_PASSWORD="${LOKI_PASSWORD:-}" -if [[ -z "${LOKI_PASSWORD}" ]]; then - echo "Plase provide a value for LOKI_PASSWORD" - exit 1 -fi - -# Version as of this writing -VERSION="v2.9.5" - -# Ensure the promtail command is locally available -CMD=promtail -if ! command -v "${CMD}" &> /dev/null; then - # Try to use a local version - CMD="${PWD}/bin/promtail" - if ! command -v "${CMD}" &> /dev/null; then - echo "promtail not found, attempting to install..." - # Determine the arch - if which sw_vers &> /dev/null; then - DIST="darwin-$(uname -m)" - else - ARCH="$(uname -i)" - if [[ "${ARCH}" == "aarch64" ]]; then - ARCH="arm64" - elif [[ "${ARCH}" == "x86_64" ]]; then - ARCH="amd64" - fi - DIST="linux-${ARCH}" - fi - - # Install the specified release - PROMTAIL_FILE="promtail-${DIST}" - ZIP_PATH="/tmp/${PROMTAIL_FILE}.zip" - BIN_DIR="$(dirname "${CMD}")" - URL="https://github.com/grafana/loki/releases/download/${VERSION}/promtail-${DIST}.zip" - curl -L -o "${ZIP_PATH}" "${URL}" - unzip "${ZIP_PATH}" -d "${BIN_DIR}" - mv "${BIN_DIR}/${PROMTAIL_FILE}" "${CMD}" - fi -fi - -# Configure promtail -FILE_SD_PATH="${PROMTAIL_WORKING_DIR}/file_sd_configs" -mkdir -p "${FILE_SD_PATH}" - -echo "writing configuration..." -cat >"${PROMTAIL_WORKING_DIR}"/promtail.yaml < promtail.log 2>&1 & -echo $! > "${PIDFILE}" -echo "running with pid $(cat "${PIDFILE}")" diff --git a/scripts/versions.sh b/scripts/versions.sh index 2b27dadefc..c310961834 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -4,5 +4,5 @@ # shellcheck disable=SC2034 # Don't export them as they're used in the context of other calls -AVALANCHE_VERSION=${AVALANCHE_VERSION:-'f1ec9a13'} +AVALANCHE_VERSION=${AVALANCHE_VERSION:-'424f7dc65171573bda0dd3537a0520febf1a73eb'} GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'}