Skip to content

Commit 0389b29

Browse files
authored
Merge pull request #4 from shu-unifra/balance-checker
Balance checker
2 parents 923176a + bb38ca6 commit 0389b29

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ DESCRIPTION
509509
EXAMPLES
510510
$ scrollsdk setup configs
511511
512-
$ scrollsdk setup configs --image-tag v0.0.25
512+
$ scrollsdk setup configs --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1
513513
514514
$ scrollsdk setup configs --configs-dir custom-configs
515515
```

src/commands/setup/configs.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class SetupConfigs extends Command {
1414

1515
static override examples = [
1616
'<%= config.bin %> <%= command.id %>',
17-
'<%= config.bin %> <%= command.id %> --image-tag v0.0.25',
17+
'<%= config.bin %> <%= command.id %> --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1',
1818
'<%= config.bin %> <%= command.id %> --configs-dir custom-configs',
1919
]
2020

@@ -427,7 +427,7 @@ export default class SetupConfigs extends Command {
427427
}
428428

429429
private async getDockerImageTag(providedTag: string | undefined): Promise<string> {
430-
const defaultTag = 'gen-configs-v0.0.25';
430+
const defaultTag = 'gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1';
431431

432432
if (!providedTag) {
433433
return defaultTag;
@@ -519,6 +519,20 @@ export default class SetupConfigs extends Command {
519519
}
520520
}
521521

522+
try {
523+
this.log(chalk.blue(`generating balance-checker alert rules file...`));
524+
const scrollMonitorProductionFilePath = path.join(targetDir, "scroll-monitor-production.yaml");
525+
const balanceCheckerConfigFilePath = path.join(targetDir, "balance-checker-config.yaml");
526+
const addedAlertRules = this.generateAlertRules(balanceCheckerConfigFilePath);
527+
const existingContent = fs.readFileSync(scrollMonitorProductionFilePath, 'utf8');
528+
const existingYaml = yaml.load(existingContent) as any;
529+
existingYaml["kube-prometheus-stack"].additionalPrometheusRules = addedAlertRules;
530+
fs.writeFileSync(scrollMonitorProductionFilePath, yaml.dump(existingYaml, { indent: 2 }));
531+
}
532+
catch {
533+
this.error(`generating balance-checker alert rules file failed`);
534+
}
535+
522536
// Remove source files after all processing is complete
523537
for (const mapping of fileMappings) {
524538
const sourcePath = path.join(sourceDir, mapping.source);
@@ -705,4 +719,40 @@ export default class SetupConfigs extends Command {
705719

706720
this.log(chalk.green('Configuration setup completed.'))
707721
}
708-
}
722+
723+
private generateAlertRules(sourcePath: string): any {
724+
const yamlContent = fs.readFileSync(sourcePath, 'utf8');
725+
const parsedYaml = yaml.load(yamlContent) as any;
726+
const jsonConfig = JSON.parse(parsedYaml.scrollConfig);
727+
const { addresses } = jsonConfig;
728+
729+
const alertRules =
730+
[
731+
{
732+
groups: [
733+
{
734+
name: "balance-cheker-group",
735+
rules: addresses.map((item: { address: string, min_balance_ether: string; name: string; rpc_url: string }) => ({
736+
alert: `ether_balance_of_${item.name}`,
737+
annotations: {
738+
description: `Balance of ${item.name} (${item.address}) is less than threshold ${item.min_balance_ether}`,
739+
summary: `Balance of ${item.name} is less than threshold ${item.min_balance_ether}`
740+
},
741+
expr: `ether_balance_of_${item.name} < ${item.min_balance_ether}`,
742+
for: '5m',
743+
labels: {
744+
severity: 'critical'
745+
}
746+
}))
747+
}],
748+
labels: {
749+
release: "scroll-monitor",
750+
role: "alert-rules"
751+
},
752+
name: "balance-cheker"
753+
}
754+
];
755+
return alertRules;
756+
}
757+
758+
}

0 commit comments

Comments
 (0)