Skip to content

Commit

Permalink
Merge pull request #3 from shu-unifra/scroll-monitor
Browse files Browse the repository at this point in the history
support grafana domain
  • Loading branch information
dghelm authored Oct 25, 2024
2 parents 85ecf66 + ea567d9 commit 923176a
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/commands/setup/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ export default class SetupDomains extends Command {
ROLLUPSCAN_API_URI: `${protocol}://rollup-explorer-backend.${urlEnding}/api`,
EXTERNAL_EXPLORER_URI_L2: `${protocol}://blockscout.${urlEnding}`,
ADMIN_SYSTEM_DASHBOARD_URI: `${protocol}://admin-system-dashboard.${urlEnding}`,
GRAFANA_URI: `${protocol}://grafana.${urlEnding}`,
};


if (usesAnvil) {
domainConfig.EXTERNAL_RPC_URI_L1 = `${protocol}://l1-devnet.${urlEnding}`;
domainConfig.EXTERNAL_EXPLORER_URI_L1 = `${protocol}://l1-explorer.${urlEnding}`;
Expand All @@ -198,6 +200,7 @@ export default class SetupDomains extends Command {
RPC_GATEWAY_HOST: `l2-rpc.${urlEnding}`,
BLOCKSCOUT_HOST: `blockscout.${urlEnding}`,
ADMIN_SYSTEM_DASHBOARD_HOST: `admin-system-dashboard.${urlEnding}`,
GRAFANA_HOST: `grafana.${urlEnding}`,
...(usesAnvil ? { L1_DEVNET_HOST: `l1-devnet.${urlEnding}`, L1_EXPLORER_HOST: `l1-explorer.${urlEnding}` } : {}),
};
} else {
Expand Down Expand Up @@ -239,6 +242,10 @@ export default class SetupDomains extends Command {
message: 'Enter ADMIN_SYSTEM_DASHBOARD_HOST:',
default: existingConfig.ingress?.ADMIN_SYSTEM_DASHBOARD_HOST || 'admin-system-dashboard.scrollsdk',
}),
GRAFANA_HOST: await input({
message: 'Enter GRAFANA_HOST:',
default: existingConfig.ingress?.GRAFANA_HOST || 'grafana.scrollsdk',
}),
};

if (usesAnvil) {
Expand Down Expand Up @@ -273,6 +280,10 @@ export default class SetupDomains extends Command {
message: 'Enter ADMIN_SYSTEM_DASHBOARD_URI:',
default: existingConfig.frontend?.ADMIN_SYSTEM_DASHBOARD_URI || `${protocol}://${ingressConfig.ADMIN_SYSTEM_DASHBOARD_HOST}`,
}),
GRAFANA_URI: await input({
message: 'Enter GRAFANA_URI:',
default: existingConfig.frontend?.GRAFANA_URI || `${protocol}://${ingressConfig.GRAFANA_HOST}`,
}),
};

if (usesAnvil) {
Expand Down
41 changes: 41 additions & 0 deletions src/commands/setup/prep-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class SetupPrepCharts extends Command {
'L1_DEVNET_HOST': 'ingress.L1_DEVNET_HOST',
'L1_EXPLORER_HOST': 'ingress.L1_EXPLORER_HOST',
'RPC_GATEWAY_WS_HOST': 'ingress.RPC_GATEWAY_WS_HOST',
'GRAFANA_HOST': 'ingress.GRAFANA_HOST',
// Add more mappings as needed
}

Expand Down Expand Up @@ -236,6 +237,46 @@ export default class SetupPrepCharts extends Command {
}
}

if (productionYaml.grafana) {
let ingressUpdated = false;
let ingressValue = productionYaml.grafana.ingress;
if (ingressValue && typeof ingressValue === 'object' && 'hosts' in ingressValue) {
const hosts = ingressValue.hosts as Array<string>;
if (Array.isArray(hosts)) {
for (let i = 0; i < hosts.length; i++) {
if (typeof (hosts[i]) === 'string') {
let configValue: string | undefined;
configValue = this.getConfigValue("ingress.GRAFANA_HOST");

if (configValue && (configValue !== hosts[i])) {
changes.push({ key: `ingress.hosts[${i}]`, oldValue: hosts[i], newValue: configValue });
hosts[i] = configValue;
ingressUpdated = true;
}
}
}
}
}

if (ingressUpdated) {
updated = true;
// Update the tls section if it exists
for (const [ingressKey, ingressValue] of Object.entries(productionYaml.grafana.ingress)) {
if (ingressValue && typeof ingressValue === 'object' && 'tls' in ingressValue && 'hosts' in ingressValue) {
const tlsEntries = ingressValue.tls as Array<{ hosts: string[] }>;
const hosts = ingressValue.hosts as Array<{ host: string }>;
if (Array.isArray(tlsEntries) && Array.isArray(hosts)) {
tlsEntries.forEach((tlsEntry) => {
if (Array.isArray(tlsEntry.hosts)) {
tlsEntry.hosts = hosts.map((host) => host.host);
}
});
}
}
}
}
}

if (updated) {
this.log(`\nFor ${chalk.cyan(file)}:`)
this.log(chalk.green('Changes:'))
Expand Down
93 changes: 93 additions & 0 deletions src/commands/setup/tls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,98 @@ spec:
const ingressTypes = ['main', 'websocket']
let updated = false


/*
grafana:
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
tls:
- secretName: admin-system-dashboard-tls
hosts:
- grafana.scsdk.unifra.xyz
hosts:
- grafana.scsdk.unifra.xyz
*/
if (yamlContent.grafana && yamlContent.grafana.ingress) {
const originalContent = yaml.dump(yamlContent.grafana.ingress, { lineWidth: -1, noRefs: true })
let ingressUpdated = false;
let ingress = yamlContent.grafana.ingress;
if (!ingress.annotations) {
ingress.annotations = {};
}

if (ingress.annotations['cert-manager.io/cluster-issuer'] !== issuer) {
ingress.annotations['cert-manager.io/cluster-issuer'] = issuer
ingressUpdated = true
}


// Update or add TLS configuration
if (ingress.hosts && ingress.hosts.length > 0) {
const firstHost = ingress.hosts[0];
if (typeof firstHost === 'string') {
const hostname = firstHost
const secretName = `${chart}-grafana-tls`;
//const secretName = ingressType === 'main' ? `${chart}-tls` : `${chart}-${ingressType}-tls`

if (!ingress.tls) {
ingress.tls = [{
secretName: secretName,
hosts: [hostname],
}]
ingressUpdated = true
} else if (ingress.tls.length === 0) {
ingress.tls.push({
secretName: secretName,
hosts: [hostname],
})
ingressUpdated = true
} else {
// Update existing TLS configuration
ingress.tls.forEach((tlsConfig: any) => {
if (!tlsConfig.secretName || tlsConfig.secretName !== secretName) {
tlsConfig.secretName = secretName
ingressUpdated = true
}
if (!tlsConfig.hosts || !tlsConfig.hosts.includes(hostname)) {
tlsConfig.hosts = [hostname]
ingressUpdated = true
}
})
}
}
}

if (ingressUpdated) {
updated = true
const updatedContent = yaml.dump(ingress, { lineWidth: -1, noRefs: true })

if (this.debugMode) {
this.log(chalk.yellow(`\nProposed changes for ${chart} :`))
this.log(chalk.red('- Original content:'))
this.log(originalContent)
this.log(chalk.green('+ Updated content:'))
this.log(updatedContent)

const confirmUpdate = await confirm({
message: chalk.cyan(`Do you want to apply these changes to ${chart}?`),
})

if (!confirmUpdate) {
this.log(chalk.yellow(`Skipped updating ${chart}`));
}
}

this.log(chalk.green(`Updated TLS configuration for ${chart} `))
} else {
this.log(chalk.green(`No changes needed for ${chart} ()`))
}

}

for (const ingressType of ingressTypes) {
if (yamlContent.ingress?.[ingressType]) {
const originalContent = yaml.dump(yamlContent.ingress[ingressType], { lineWidth: -1, noRefs: true })
Expand Down Expand Up @@ -259,6 +351,7 @@ spec:
'rollup-explorer-backend',
'l2-rpc',
'l1-devnet',
'scroll-monitor'
]

for (const chart of chartsToUpdate) {
Expand Down

0 comments on commit 923176a

Please sign in to comment.