Skip to content

Commit

Permalink
feat: automatic system alerts (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters authored and pcheremu committed Feb 15, 2024
1 parent 1f415fb commit a4f04ee
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 768 deletions.
693 changes: 40 additions & 653 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<the-header :class="$route?.name" />
<div class="container-app">
<NetworkDeprecated v-if="!currentNetwork.maintenance && currentNetwork.name === 'goerli'" />
<IssuesBanner v-if="!currentNetwork.maintenance && currentNetwork.name === 'mainnet'" />
<IndexerDelayAlert v-if="!currentNetwork.maintenance && currentNetwork.name === 'mainnet'" />
<MaintenanceView v-if="currentNetwork.maintenance" />
<router-view v-else />
</div>
Expand All @@ -14,7 +14,7 @@
<script setup lang="ts">
import { useTitle } from "@vueuse/core";
import IssuesBanner from "@/components/IssuesBanner.vue";
import IndexerDelayAlert from "@/components/IndexerDelayAlert.vue";
import NetworkDeprecated from "@/components/NetworkDeprecated.vue";
import TheFooter from "@/components/TheFooter.vue";
import TheHeader from "@/components/header/TheHeader.vue";
Expand Down
31 changes: 0 additions & 31 deletions packages/app/src/components/IssuesBanner.vue

This file was deleted.

26 changes: 6 additions & 20 deletions packages/app/src/components/NetworkDeprecated.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<template v-if="newNetworkUrl">
<div class="deprecated-alert">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M21.0907 18.7005C20.8457 19.1905 20.3449 19.5 19.7971 19.5H4.20288C3.65506 19.5 3.15426 19.1905 2.90927 18.7005C2.69455 18.2711 2.70694 17.7631 2.94232 17.3446L10.9455 3.11671C11.1598 2.73575 11.5629 2.5 12 2.5C12.4371 2.5 12.8402 2.73575 13.0545 3.11671L21.0577 17.3446C21.2931 17.7631 21.3054 18.2711 21.0907 18.7005Z"
stroke="#FFC81A"
/>
<circle cx="12" cy="16" r="1" fill="#FFC81A" />
<path d="M12 14V6" stroke="#FFC81A" />
</svg>
<SystemAlert>
<span
>We are ending our support of Goerli testnet. Please <a :href="newNetworkUrl!">use Sepolia</a>. For more info see
<a target="_blank" href="https://github.com/zkSync-Community-Hub/zkync-developers/discussions/228"
>this announcement</a
>.</span
>
</div>
</SystemAlert>
</template>

<script lang="ts" setup>
import { computed } from "vue";
import { useRoute } from "vue-router";
import SystemAlert from "@/components/common/SystemAlert.vue";
import useContext from "@/composables/useContext";
import { getWindowLocation } from "@/utils/helpers";
Expand All @@ -44,15 +38,7 @@ const newNetworkUrl = computed(() => {
</script>

<style scoped lang="scss">
.deprecated-alert {
@apply flex text-white rounded-2xl border border-amber-400/50 bg-amber-400/10 mb-6 py-3 px-4;
svg {
@apply mr-2 shrink-0;
}
a {
@apply text-inherit;
}
a {
@apply text-inherit;
}
</style>
8 changes: 0 additions & 8 deletions packages/app/src/components/header/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ const hasContent = computed(() => {
.hero-banner-container {
@apply absolute left-0 top-full flex h-64 w-full items-end justify-end overflow-hidden bg-primary-900;
&.mainnet {
@apply h-[27rem] md:h-[23rem] lg:h-[20rem];
}
&.goerli {
@apply h-[25rem] md:h-[23rem] lg:h-[19rem];
}
Expand All @@ -316,10 +312,6 @@ const hasContent = computed(() => {
.home-banner {
@apply h-80;
&.mainnet {
@apply h-[32rem] md:h-[28rem] lg:h-[25rem];
}
&.goerli {
@apply h-[30rem] md:h-[27rem] lg:h-[24rem];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/app/tests/e2e/features/copying.feature

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@willsoto/nestjs-prometheus": "^4.7.0",
"axios": "^1.4.0",
"ethers": "^5.7.1",
"firebase": "^10.7.1",
"nest-winston": "^1.7.0",
"pg": "^8.8.0",
"prom-client": "^14.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/worker/src/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe("HealthController", () => {
});

describe("check", () => {
// it("checks health of the DB", async () => {
// await healthController.check();
// expect(dbHealthCheckerMock.pingCheck).toHaveBeenCalledTimes(1);
// expect(dbHealthCheckerMock.pingCheck).toHaveBeenCalledWith("database");
// });
it("checks health of the DB", async () => {
await healthController.check();
expect(dbHealthCheckerMock.pingCheck).toHaveBeenCalledTimes(1);
expect(dbHealthCheckerMock.pingCheck).toHaveBeenCalledWith("database");
});

it("checks health of the JSON RPC provider", async () => {
await healthController.check();
Expand Down
6 changes: 3 additions & 3 deletions packages/worker/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger, Controller, Get } from "@nestjs/common";
import { HealthCheckService, /*TypeOrmHealthIndicator,*/ HealthCheck, HealthCheckResult } from "@nestjs/terminus";
import { HealthCheckService, TypeOrmHealthIndicator, HealthCheck, HealthCheckResult } from "@nestjs/terminus";
import { JsonRpcHealthIndicator } from "./jsonRpcProvider.health";

@Controller(["health", "ready"])
Expand All @@ -8,7 +8,7 @@ export class HealthController {

constructor(
private readonly healthCheckService: HealthCheckService,
//private readonly dbHealthChecker: TypeOrmHealthIndicator,
private readonly dbHealthChecker: TypeOrmHealthIndicator,
private readonly jsonRpcHealthIndicator: JsonRpcHealthIndicator
) {
this.logger = new Logger(HealthController.name);
Expand All @@ -19,7 +19,7 @@ export class HealthController {
public async check(): Promise<HealthCheckResult> {
try {
return await this.healthCheckService.check([
//() => this.dbHealthChecker.pingCheck("database"),
() => this.dbHealthChecker.pingCheck("database"),
() => this.jsonRpcHealthIndicator.isHealthy("jsonRpcProvider"),
]);
} catch (error) {
Expand Down
43 changes: 0 additions & 43 deletions packages/worker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,12 @@ import { ConfigService } from "@nestjs/config";
import logger from "./logger";
import { AppModule } from "./app.module";

import { initializeApp } from "firebase/app";
import { getFirestore, onSnapshot, doc } from "firebase/firestore";

const firebaseApp = initializeApp({
projectId: "scan-v2",
});
const db = getFirestore(firebaseApp);

const getConfig = async (instanceId: string): Promise<{ fromBlock: string; toBlock: string }> => {
return new Promise((resolve, reject) => {
const unsubscribe = onSnapshot(
doc(db, "config", "worker"),
(data) => {
if (data.exists()) {
const config = data.data() as Record<string, { fromBlock: string; toBlock: string }>;
if (config[instanceId] && config[instanceId].fromBlock && config[instanceId].toBlock) {
unsubscribe();
resolve(config[instanceId]);
}
}
},
(e) => {
logger.error(e);
reject(e);
}
);
});
};

async function bootstrap() {
process.on("uncaughtException", function (error) {
logger.error(error.message, error.stack, "UnhandledExceptions");
process.exit(1);
});

if (process.env.USE_REMOTE_CONFIG === "true") {
const config = await getConfig(process.env.HOSTNAME);
if (!config.fromBlock || !config.toBlock) {
throw new Error("Missing fromBlock or toBlock in config");
}
logger.log(`Using fromBlock: ${config.fromBlock}, toBlock: ${config.toBlock}`);
process.env.FROM_BLOCK = config.fromBlock;
process.env.TO_BLOCK = config.toBlock;
process.env.DISABLE_BATCHES_PROCESSING = "true";
process.env.DISABLE_COUNTERS_PROCESSING = "true";
process.env.DISABLE_OLD_BALANCES_CLEANER = "true";
process.env.DISABLE_BLOCKS_REVERT = "true";
}

const app = await NestFactory.create(AppModule, {
logger,
});
Expand Down

0 comments on commit a4f04ee

Please sign in to comment.