diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index d63d414..ffd7cda 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -3,14 +3,15 @@ on: push: branches: - main + - temporary jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: 20 - name: Install dependencies @@ -18,7 +19,7 @@ jobs: - name: Build run: yarn build - name: Create Sentry release - uses: getsentry/action-release@v1 + uses: getsentry/action-release@v1.7.0 env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_ORG: ${{ secrets.SENTRY_ORG }} @@ -27,3 +28,4 @@ jobs: environment: production version: ${{ github.sha }} sourcemaps: '/lib' + ignore_missing: true diff --git a/cloudbuild.yaml b/cloudbuild.yaml index cb0f0b7..4637ef5 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -23,7 +23,7 @@ steps: args: [ "-c", - "gcloud compute instance-templates create-with-container liquidator-template-$COMMIT_SHA --container-image=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA --container-env=WALLET_ADDRESS=$$WALLET_ADDRESS,WALLET_PRIVATE_KEY=$$WALLET_PRIVATE_KEY,API_TOKEN=$$API_TOKEN,ALCHEMY_API_KEY=$$ALCHEMY_API_KEY,ANKR_API_KEY=$$ANKR_API_KEY,BASESCAN_API_KEY=$$BASESCAN_API_KEY,SLACK_WEBHOOK0=$$SLACK_WEBHOOK0,SLACK_WEBHOOK1=$$SLACK_WEBHOOK1,SLACK_WEBHOOK2=$$SLACK_WEBHOOK2,SENTRY_DSN0=$$SENTRY_DSN0,SENTRY_DSN1=$$SENTRY_DSN1,SENTRY_DSN2=$$SENTRY_DSN2 --machine-type=e2-small --tags=http-server,https-server", + "gcloud compute instance-templates create-with-container liquidator-template-$COMMIT_SHA --container-image=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA --container-env=WALLET_ADDRESS=$$WALLET_ADDRESS,WALLET_PRIVATE_KEY=$$WALLET_PRIVATE_KEY,API_TOKEN=$$API_TOKEN,ALCHEMY_API_KEY=$$ALCHEMY_API_KEY,ANKR_API_KEY=$$ANKR_API_KEY,BASESCAN_API_KEY=$$BASESCAN_API_KEY,SLACK_WEBHOOK0=$$SLACK_WEBHOOK0,SLACK_WEBHOOK1=$$SLACK_WEBHOOK1,SLACK_WEBHOOK2=$$SLACK_WEBHOOK2,SENTRY_DSN0=$$SENTRY_DSN0,SENTRY_DSN1=$$SENTRY_DSN1,SENTRY_DSN2=$$SENTRY_DSN2,GIT_COMMIT_SHA=$COMMIT_SHA --machine-type=e2-small --tags=http-server,https-server", ] secretEnv: [ diff --git a/package.json b/package.json index 5155305..b49857f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "clean": "rm -rf lib" }, "dependencies": { - "@sentry/node": "^7.48.0", + "@sentry/node": "^7.110.0", "@types/node": "^20.12.5", "axios": "^0.25.0", "bottleneck": "^2.19.5", diff --git a/src/example.ts b/src/example.ts index 1bb9395..d211301 100644 --- a/src/example.ts +++ b/src/example.ts @@ -27,14 +27,14 @@ if ( Sentry.init({ dsn: `https://${process.env.SENTRY_DSN0}@${process.env.SENTRY_DSN1}.ingest.sentry.io/${process.env.SENTRY_DSN2}`, sampleRate: 0.1, + tracesSampleRate: 1, enabled: process.env.SENTRY_DSN0 !== undefined && process.env.SENTRY_DSN1 !== undefined && process.env.SENTRY_DSN2 !== undefined, - autoSessionTracking: false, release: process.env.GIT_COMMIT_SHA || undefined, + initialScope: { tags: { "chain_name": chain.name } }, }); - Sentry.setTag("chain_name", chain.name); } const { client, factory, borrowerLens, liquidator } = setupViemFor( diff --git a/src/index.ts b/src/index.ts index 564f19d..c7dcbf9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,10 @@ import { fork } from "child_process"; -import { arbitrum, base, mainnet, optimism } from "viem/chains"; +import express from "express"; import * as Sentry from "@sentry/node"; +import { arbitrum, base, mainnet, optimism } from "viem/chains"; + +const port = process.env.PORT || 8080; +const app = express(); console.log("Starting Liquidator"); if ( @@ -12,11 +16,11 @@ if ( Sentry.init({ dsn: `https://${process.env.SENTRY_DSN0}@${process.env.SENTRY_DSN1}.ingest.sentry.io/${process.env.SENTRY_DSN2}`, sampleRate: 0.1, + tracesSampleRate: 1, enabled: process.env.SENTRY_DSN0 !== undefined && process.env.SENTRY_DSN1 !== undefined && process.env.SENTRY_DSN2 !== undefined, - autoSessionTracking: false, release: process.env.GIT_COMMIT_SHA || undefined, }); } @@ -29,3 +33,28 @@ chains.forEach((chain) => { child.on("error", (err) => Sentry.captureException(err, { tags: { chain } })); // TODO: handle errors and exits }); + +app.get("/liquidator_readiness_check", (req, res) => { + res.send("OK"); +}); + +const server = app.listen(port, () => { + // eslint-disable-next-line no-console + console.log(`Server is running on port ${port}`); +}); + +function shutdown() { + server.close(() => { + process.exit(0); + }); +} + +process.on("SIGTERM", () => { + console.log("Received SIGTERM, shutting down"); + shutdown(); +}); + +process.on("SIGINT", () => { + console.log("Received SIGINT, shutting down"); + shutdown(); +}); diff --git a/yarn.lock b/yarn.lock index 141fe06..a175d8a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -427,51 +427,44 @@ "@noble/hashes" "~1.3.0" "@scure/base" "~1.1.0" -"@sentry-internal/tracing@7.48.0": - version "7.48.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.48.0.tgz#d0c1eac1c046fda5c79d16dc1c918fee3bae3e9d" - integrity sha512-MFAPDTrvCtfSm0/Zbmx7HA0Q5uCfRadOUpN8Y8rP1ndz+329h2kA3mZRCuC+3/aXL11zs2CHUhcAkGjwH2vogg== - dependencies: - "@sentry/core" "7.48.0" - "@sentry/types" "7.48.0" - "@sentry/utils" "7.48.0" - tslib "^1.9.3" - -"@sentry/core@7.48.0": - version "7.48.0" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.48.0.tgz#1a5ec347ab7212d73a99583c2e64989e34e3263a" - integrity sha512-8FYuJTMpyuxRZvlen3gQ3rpOtVInSDmSyXqWEhCLuG/w34AtWoTiW7G516rsAAh6Hy1TP91GooMWbonP3XQNTQ== - dependencies: - "@sentry/types" "7.48.0" - "@sentry/utils" "7.48.0" - tslib "^1.9.3" - -"@sentry/node@^7.48.0": - version "7.48.0" - resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.48.0.tgz#b2f15502b77796bf7bcaa29f2e9ce1420f7c49d1" - integrity sha512-DJyyZaVhv/pUzJPof7es6zYDHeWbNqE0T3tQfLCkShdyfR+Ew8In8W/x2s7S8vq0cfRq0rqv1E6B2/HpVdYO7g== - dependencies: - "@sentry-internal/tracing" "7.48.0" - "@sentry/core" "7.48.0" - "@sentry/types" "7.48.0" - "@sentry/utils" "7.48.0" - cookie "^0.4.1" - https-proxy-agent "^5.0.0" - lru_map "^0.3.3" - tslib "^1.9.3" - -"@sentry/types@7.48.0": - version "7.48.0" - resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.48.0.tgz#57f3c9cf331a5621e82dda04eefcf8c19ee42bc9" - integrity sha512-kkAszZwQ5/v4n7Yyw/DPNRWx7h724mVNRGZIJa9ggUMvTgMe7UKCZZ5wfQmYiKVlGbwd9pxXAcP8Oq15EbByFQ== - -"@sentry/utils@7.48.0": - version "7.48.0" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.48.0.tgz#2866975ea8899aba35b083dd0558cbbe29ee8de1" - integrity sha512-d977sghkFVMfld0LrEyyY2gYrfayLPdDEpUDT+hg5y79r7zZDCFyHtdB86699E5K89MwDZahW7Erk+a1nk4x5w== - dependencies: - "@sentry/types" "7.48.0" - tslib "^1.9.3" +"@sentry-internal/tracing@7.110.0": + version "7.110.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.110.0.tgz#00f2086b0efb8dd5a67831074e52b176aa542d32" + integrity sha512-IIHHa9e/mE7uOMJfNELI8adyoELxOy6u6TNCn5t6fphmq84w8FTc9adXkG/FY2AQpglkIvlILojfMROFB2aaAQ== + dependencies: + "@sentry/core" "7.110.0" + "@sentry/types" "7.110.0" + "@sentry/utils" "7.110.0" + +"@sentry/core@7.110.0": + version "7.110.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.110.0.tgz#2945d3ac0ef116ed313fbfb9da4f483b66fe5bca" + integrity sha512-g4suCQO94mZsKVaAbyD1zLFC5YSuBQCIPHXx9fdgtfoPib7BWjWWePkllkrvsKAv4u8Oq05RfnKOhOMRHpOKqg== + dependencies: + "@sentry/types" "7.110.0" + "@sentry/utils" "7.110.0" + +"@sentry/node@^7.110.0": + version "7.110.0" + resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.110.0.tgz#c75a7568e641ddb48d1636e62aaa37e9589e8806" + integrity sha512-YPfweCSzo/omnx5q1xOEZfI8Em3jnPqj7OM4ObXmoSKEK+kM1oUF3BTRzw5BJOaOCSTBFY1RAsGyfVIyrwxWnA== + dependencies: + "@sentry-internal/tracing" "7.110.0" + "@sentry/core" "7.110.0" + "@sentry/types" "7.110.0" + "@sentry/utils" "7.110.0" + +"@sentry/types@7.110.0": + version "7.110.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.110.0.tgz#c3f252b008cab905097fc71e174191f20bdaf4f3" + integrity sha512-DqYBLyE8thC5P5MuPn+sj8tL60nCd/f5cerFFPcudn5nJ4Zs1eI6lKlwwyHYTEu5c4KFjCB0qql6kXfwAHmTyA== + +"@sentry/utils@7.110.0": + version "7.110.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.110.0.tgz#68ef59359d608a1a6a7205b780196a042ad73ab2" + integrity sha512-VBsdLLN+5tf73fhf/Cm7JIsUJ6y9DkJj8h4I6Mxx0rszrvOyH6S5px40K+V4jdLBzMEvVinC7q2Cbf1YM18BSw== + dependencies: + "@sentry/types" "7.110.0" "@tsconfig/node10@^1.0.7": version "1.0.9" @@ -590,13 +583,6 @@ aes-js@3.0.0: resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d" integrity sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw== -agent-base@6: - version "6.0.2" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" - integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== - dependencies: - debug "4" - arg@^4.1.0: version "4.1.3" resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" @@ -738,11 +724,6 @@ cookie@0.5.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== -cookie@^0.4.1: - version "0.4.2" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432" - integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA== - create-require@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" @@ -755,13 +736,6 @@ debug@2.6.9: dependencies: ms "2.0.0" -debug@4: - version "4.3.4" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" - integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== - dependencies: - ms "2.1.2" - depd@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" @@ -998,14 +972,6 @@ http-errors@2.0.0: statuses "2.0.1" toidentifier "1.0.1" -https-proxy-agent@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6" - integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA== - dependencies: - agent-base "6" - debug "4" - iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -1059,11 +1025,6 @@ logform@^2.3.2, logform@^2.4.0: safe-stable-stringify "^2.3.1" triple-beam "^1.3.0" -lru_map@^0.3.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" - integrity sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ== - make-error@^1.1.1: version "1.3.6" resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" @@ -1116,11 +1077,6 @@ ms@2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== -ms@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== - ms@2.1.3, ms@^2.1.1: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" @@ -1320,11 +1276,6 @@ ts-node@^10.9.2: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -tslib@^1.9.3: - version "1.14.1" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" - integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== - type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"