Skip to content

Commit c9362ae

Browse files
committed
refactor: make monitoring functioning again
1 parent a3c0e12 commit c9362ae

File tree

4 files changed

+202
-134
lines changed

4 files changed

+202
-134
lines changed
Lines changed: 149 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,160 @@
1-
import { env } from '$env/dynamic/public';
1+
import { env } from "$env/dynamic/public";
22

33
export interface Platform {
4-
name: string;
5-
url: string;
6-
status: 'Active' | 'Inactive';
7-
uptime: string;
4+
name: string;
5+
url: string;
6+
status: "Active" | "Inactive";
7+
uptime: string;
88
}
99

1010
export interface RegistryVault {
11-
ename: string;
12-
uri: string;
13-
evault: string;
14-
originalUri?: string;
15-
resolved?: boolean;
11+
ename: string;
12+
uri: string;
13+
evault: string;
14+
originalUri?: string;
15+
resolved?: boolean;
1616
}
1717

1818
export class RegistryService {
19-
private baseUrl: string;
20-
21-
constructor() {
22-
this.baseUrl = env.PUBLIC_REGISTRY_URL || 'https://registry.staging.metastate.foundation';
23-
}
24-
25-
async getEVaults(): Promise<RegistryVault[]> {
26-
try {
27-
const response = await fetch(`${this.baseUrl}/list`);
28-
29-
if (!response.ok) {
30-
throw new Error(`HTTP error! status: ${response.status}`);
31-
}
32-
33-
const vaults: RegistryVault[] = await response.json();
34-
return vaults;
35-
} catch (error) {
36-
console.error('Error fetching evaults from registry:', error);
37-
return [];
38-
}
39-
}
40-
41-
async getPlatforms(): Promise<Platform[]> {
42-
try {
43-
const response = await fetch(`${this.baseUrl}/platforms`);
44-
45-
if (!response.ok) {
46-
throw new Error(`HTTP error! status: ${response.status}`);
47-
}
48-
49-
const platformUrls: string[] = await response.json();
50-
51-
// Convert URLs to platform objects with friendly names
52-
const platforms = platformUrls.map((url) => {
53-
// Ensure URL has protocol
54-
const urlWithProtocol =
55-
url.startsWith('http://') || url.startsWith('https://') ? url : `http://${url}`;
56-
const urlObj = new URL(urlWithProtocol);
57-
const hostname = urlObj.hostname;
58-
const port = urlObj.port;
59-
const protocol = urlObj.protocol;
60-
61-
// Extract platform name from hostname
62-
let name = hostname.split('.')[0];
63-
64-
// Capitalize and format the name
65-
if (name === 'pictique') name = 'Pictique';
66-
else if (name === 'blabsy') name = 'Blabsy';
67-
else if (name === 'charter') name = 'Group Charter';
68-
else if (name === 'cerberus') name = 'Cerberus';
69-
else if (name === 'evoting') name = 'eVoting';
70-
else name = name.charAt(0).toUpperCase() + name.slice(1);
71-
72-
// Build the full URL with protocol and port
73-
const fullUrl = port ? `${hostname}:${port}` : hostname;
74-
const displayUrl = `${protocol}//${fullUrl}`;
75-
76-
return {
77-
name,
78-
url: displayUrl,
79-
status: 'Active' as const,
80-
uptime: '24h'
81-
};
82-
});
83-
84-
return platforms;
85-
} catch (error) {
86-
console.error('Error fetching platforms from registry:', error);
87-
88-
// Return fallback platforms if registry is unavailable
89-
return [
90-
{
91-
name: 'Blabsy',
92-
url: 'http://192.168.0.235:4444',
93-
status: 'Active',
94-
uptime: '24h'
95-
},
96-
{
97-
name: 'Pictique',
98-
url: 'http://192.168.0.235:1111',
99-
status: 'Active',
100-
uptime: '24h'
101-
},
102-
{
103-
name: 'Group Charter',
104-
url: 'http://192.168.0.235:5555',
105-
status: 'Active',
106-
uptime: '24h'
107-
},
108-
{
109-
name: 'Cerberus',
110-
url: 'http://192.168.0.235:6666',
111-
status: 'Active',
112-
uptime: '24h'
113-
}
114-
];
115-
}
116-
}
19+
private baseUrl: string;
20+
21+
constructor() {
22+
this.baseUrl =
23+
env.PUBLIC_REGISTRY_URL ||
24+
"https://registry.staging.metastate.foundation";
25+
}
26+
27+
async getEVaults(): Promise<RegistryVault[]> {
28+
try {
29+
const response = await fetch(`${this.baseUrl}/list`);
30+
31+
if (!response.ok) {
32+
throw new Error(`HTTP error! status: ${response.status}`);
33+
}
34+
35+
const vaults: RegistryVault[] = await response.json();
36+
return vaults;
37+
} catch (error) {
38+
console.error("Error fetching evaults from registry:", error);
39+
return [];
40+
}
41+
}
42+
43+
async getPlatforms(): Promise<Platform[]> {
44+
try {
45+
const response = await fetch(`${this.baseUrl}/platforms`);
46+
47+
if (!response.ok) {
48+
throw new Error(`HTTP error! status: ${response.status}`);
49+
}
50+
51+
const platformUrls: (string | null | undefined)[] =
52+
await response.json();
53+
54+
// Filter out null/undefined values and convert URLs to platform objects
55+
const platforms = platformUrls
56+
.filter(
57+
(url): url is string => url != null && url.trim() !== "",
58+
)
59+
.map((url) => {
60+
// Use the original URL from the registry (it already has the correct format)
61+
let displayUrl = url.trim();
62+
63+
// Ensure URL has protocol if it doesn't
64+
if (
65+
!displayUrl.startsWith("http://") &&
66+
!displayUrl.startsWith("https://")
67+
) {
68+
displayUrl = `http://${displayUrl}`;
69+
}
70+
71+
// Parse URL to extract platform name
72+
let name = "Unknown";
73+
try {
74+
const urlObj = new URL(displayUrl);
75+
const hostname = urlObj.hostname;
76+
// Extract platform name from hostname (remove port if present)
77+
const hostnameWithoutPort = hostname.split(":")[0];
78+
const namePart = hostnameWithoutPort.split(".")[0];
79+
80+
// Capitalize and format the name
81+
if (namePart === "pictique") name = "Pictique";
82+
else if (namePart === "blabsy") name = "Blabsy";
83+
else if (namePart === "charter") name = "Group Charter";
84+
else if (namePart === "cerberus") name = "Cerberus";
85+
else if (namePart === "evoting") name = "eVoting";
86+
else if (namePart === "dreamsync") name = "DreamSync";
87+
else if (namePart === "ereputation")
88+
name = "eReputation";
89+
else
90+
name =
91+
namePart.charAt(0).toUpperCase() +
92+
namePart.slice(1);
93+
} catch {
94+
// If URL parsing fails, try to extract name from the URL string
95+
const match = displayUrl.match(
96+
/(?:https?:\/\/)?([^:./]+)/,
97+
);
98+
if (match) {
99+
const namePart = match[1].toLowerCase();
100+
if (namePart === "pictique") name = "Pictique";
101+
else if (namePart === "blabsy") name = "Blabsy";
102+
else if (namePart === "charter")
103+
name = "Group Charter";
104+
else if (namePart === "cerberus") name = "Cerberus";
105+
else if (namePart === "evoting") name = "eVoting";
106+
else if (namePart === "dreamsync")
107+
name = "DreamSync";
108+
else if (namePart === "ereputation")
109+
name = "eReputation";
110+
else
111+
name =
112+
namePart.charAt(0).toUpperCase() +
113+
namePart.slice(1);
114+
}
115+
}
116+
117+
return {
118+
name,
119+
url: displayUrl,
120+
status: "Active" as const,
121+
uptime: "24h",
122+
};
123+
});
124+
125+
return platforms;
126+
} catch (error) {
127+
console.error("Error fetching platforms from registry:", error);
128+
129+
// Return fallback platforms if registry is unavailable
130+
return [
131+
{
132+
name: "Blabsy",
133+
url: "http://192.168.0.235:4444",
134+
status: "Active",
135+
uptime: "24h",
136+
},
137+
{
138+
name: "Pictique",
139+
url: "http://192.168.0.235:1111",
140+
status: "Active",
141+
uptime: "24h",
142+
},
143+
{
144+
name: "Group Charter",
145+
url: "http://192.168.0.235:5555",
146+
status: "Active",
147+
uptime: "24h",
148+
},
149+
{
150+
name: "Cerberus",
151+
url: "http://192.168.0.235:6666",
152+
status: "Active",
153+
uptime: "24h",
154+
},
155+
];
156+
}
157+
}
117158
}
118159

119160
export const registryService = new RegistryService();

infrastructure/control-panel/src/routes/monitoring/+page.svelte

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@
100100
id: `evault-${index + 1}`,
101101
position: { x: 200, y: 500 + index * 180 },
102102
data: {
103-
label: evault.evaultId || evault.name || 'eVault',
104-
subLabel: evault.serviceUrl || evault.ip || 'Unknown',
103+
label: evault.name || evault.ename || evault.evault || evault.id || 'eVault',
104+
subLabel: evault.uri || evault.serviceUrl || 'Unknown',
105105
type: 'evault',
106106
selected: false
107107
},
@@ -506,12 +506,19 @@
506506
const cleanW3id = w3id.replace('@', '');
507507
console.log('Cleaned w3id:', cleanW3id);
508508
509-
// Since evaultId is the same as w3id (without @), prioritize that match
509+
// Match against ename (w3id), evault, or id fields
510510
const index = selectedEVaults.findIndex((e) => {
511-
const matches = e.evaultId === cleanW3id;
511+
// Check if ename (w3id) matches (with or without @)
512+
const enameMatch = e.ename && (e.ename === cleanW3id || e.ename === w3id || e.ename.replace('@', '') === cleanW3id);
513+
// Check if evault field matches
514+
const evaultMatch = e.evault && e.evault === cleanW3id;
515+
// Check if id field matches
516+
const idMatch = e.id && e.id === cleanW3id;
517+
518+
const matches = enameMatch || evaultMatch || idMatch;
512519
513520
if (matches) {
514-
console.log('Found matching eVault by evaultId:', e);
521+
console.log('Found matching eVault:', e);
515522
}
516523
517524
return matches;
@@ -523,12 +530,17 @@
523530
selectedEVaultsLength: selectedEVaults.length
524531
});
525532
526-
// If no match found, log all available evaultIds for debugging
533+
// If no match found, log all available evault identifiers for debugging
527534
if (index === -1) {
528535
console.log('No match found for cleaned w3id:', cleanW3id);
529-
console.log('Available evaultIds:');
536+
console.log('Available evault identifiers:');
530537
selectedEVaults.forEach((evault, i) => {
531-
console.log(`eVault ${i}: evaultId = "${evault.evaultId}"`);
538+
console.log(`eVault ${i}:`, {
539+
ename: evault.ename,
540+
evault: evault.evault,
541+
id: evault.id,
542+
name: evault.name
543+
});
532544
});
533545
534546
// Return -1 to indicate no match found
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import adapter from '@sveltejs/adapter-node';
2-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
1+
import adapter from "@sveltejs/adapter-node";
2+
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {
6-
// Consult https://svelte.dev/docs/kit/integrations
7-
// for more information about preprocessors
8-
preprocess: vitePreprocess(),
9-
kit: { adapter: adapter() }
6+
// Consult https://svelte.dev/docs/kit/integrations
7+
// for more information about preprocessors
8+
preprocess: vitePreprocess(),
9+
kit: {
10+
adapter: adapter(),
11+
// Load .env from the root of the monorepo (parent directory)
12+
env: {
13+
dir: "../../",
14+
},
15+
},
1016
};
1117

1218
export default config;
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
import { sveltekit } from '@sveltejs/kit/vite';
2-
import tailwindcss from '@tailwindcss/vite';
3-
import { defineConfig } from 'vite';
1+
import { dirname, resolve } from "path";
2+
import { fileURLToPath } from "url";
3+
import { sveltekit } from "@sveltejs/kit/vite";
4+
import tailwindcss from "@tailwindcss/vite";
5+
import { defineConfig } from "vite";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
49

510
export default defineConfig({
6-
plugins: [tailwindcss(), sveltekit()],
7-
optimizeDeps: {
8-
exclude: ['lowdb', 'steno']
9-
},
10-
build: {
11-
rollupOptions: {
12-
external: ['lowdb', 'lowdb/node', 'steno']
13-
}
14-
}
11+
plugins: [tailwindcss(), sveltekit()],
12+
// Load .env from the root of the monorepo (parent directory)
13+
envDir: resolve(__dirname, "../.."),
14+
// PUBLIC_ prefix is for client-side env vars, server-side vars (like LOKI_*) are loaded automatically
15+
envPrefix: "PUBLIC_",
16+
optimizeDeps: {
17+
exclude: ["lowdb", "steno"],
18+
},
19+
build: {
20+
rollupOptions: {
21+
external: ["lowdb", "lowdb/node", "steno"],
22+
},
23+
},
1524
});

0 commit comments

Comments
 (0)