A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(admin): allow unanswered nodes in gateway stats
Hampus3f1562a403da
diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.jsonindex 7e224a8ae..58e2653f4 100644--- a/fluxer_admin/openapi-admin.json+++ b/fluxer_admin/openapi-admin.json@@ -16327,7 +16327,7 @@],"additionalProperties": false},- "code": {"type": "string", "minLength": 1, "maxLength": 256},+ "code": {"type": "string", "minLength": 1, "maxLength": 128},"url": {"type": "string"}},"required": ["registration_url", "code", "url"],@@ -17321,7 +17321,7 @@"properties": {"node_id": {"type": "string", "minLength": 1, "maxLength": 256},"status": {"type": "string", "minLength": 1, "maxLength": 256},- "sessions": {"$ref": "#/components/schemas/Int32Type"},+ "sessions": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},"session_resumes_total": {"nullable": true,"type": "integer",@@ -17340,22 +17340,22 @@"minimum": 0,"maximum": 9007199254740991},- "guilds": {"$ref": "#/components/schemas/Int32Type"},- "presences": {"$ref": "#/components/schemas/Int32Type"},- "calls": {"$ref": "#/components/schemas/Int32Type"},+ "guilds": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},+ "presences": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},+ "calls": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},"memory": {"type": "object","properties": {- "total": {"$ref": "#/components/schemas/Int64StringType"},- "processes": {"$ref": "#/components/schemas/Int64StringType"},- "system": {"$ref": "#/components/schemas/Int64StringType"}+ "total": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int64StringType"}]},+ "processes": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int64StringType"}]},+ "system": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int64StringType"}]}},"required": ["total", "processes", "system"],"additionalProperties": false},- "process_count": {"$ref": "#/components/schemas/Int32Type"},- "process_limit": {"$ref": "#/components/schemas/Int32Type"},- "uptime_seconds": {"$ref": "#/components/schemas/Int32Type"},+ "process_count": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},+ "process_limit": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},+ "uptime_seconds": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/Int32Type"}]},"cluster_metrics": {"type": "object","properties": {@@ -24469,7 +24469,7 @@"THREAD_ALREADY_CREATED_FOR_MESSAGE","THREAD_ARCHIVED","THREAD_LOCKED",- "TWO_FA_NOT_ENABLED",+ "TWO_FA_ALREADY_ENABLED","TWO_FACTOR_REQUIRED","UNAUTHORIZED","UNCLAIMED_ACCOUNT_CANNOT_ACCEPT_FRIEND_REQUESTS",@@ -24829,7 +24829,7 @@"A thread has already been created for this message.","This thread is archived.","This thread is locked.",- "Two-factor authentication isn't enabled.",+ "Two-factor authentication is already enabled.","Two-factor authentication is required.","Unauthorized.","Claim your account to accept friend requests.",diff --git a/fluxer_admin/src/templates/pages/gateway_nodes.rs b/fluxer_admin/src/templates/pages/gateway_nodes.rsindex 7e2cf405c..d00a71148 100644--- a/fluxer_admin/src/templates/pages/gateway_nodes.rs+++ b/fluxer_admin/src/templates/pages/gateway_nodes.rs@@ -100,12 +100,16 @@ pub(crate) fn node_stats_table(nodes: &[serde_json::Value]) -> Markup {@let node_id = node.get("node_id").and_then(|v| v.as_str()).unwrap_or("");@let label = format_node_id(node_id, i);@let status = node.get("status").and_then(|v| v.as_str()).unwrap_or("-");- @let ns = node.get("sessions").and_then(|v| v.as_u64()).unwrap_or(0);- @let nsr = node.get("session_resumes_total").and_then(|v| v.as_u64()).unwrap_or(0);- @let ng = node.get("guilds").and_then(|v| v.as_u64()).unwrap_or(0);- @let np = node.get("presences").and_then(|v| v.as_u64()).unwrap_or(0);- @let nc = node.get("calls").and_then(|v| v.as_u64()).unwrap_or(0);- @let nm = node.pointer("/memory/total").and_then(|v| v.as_str()).unwrap_or("0");+ @let ns = node_count_cell(node, "sessions");+ @let nsr = node_count_cell(node, "session_resumes_total");+ @let ng = node_count_cell(node, "guilds");+ @let np = node_count_cell(node, "presences");+ @let nc = node_count_cell(node, "calls");+ @let nm = node+ .pointer("/memory/total")+ .and_then(|v| v.as_str())+ .map(format_memory_from_bytes)+ .unwrap_or_else(|| "-".to_owned());tr class="transition-colors hover:bg-neutral-50" {td class="whitespace-nowrap px-6 py-4 text-sm" {div class="font-medium text-neutral-900 text-sm" { (label) }@@ -117,7 +121,7 @@ pub(crate) fn node_stats_table(nodes: &[serde_json::Value]) -> Markup {td class="whitespace-nowrap px-6 py-4 text-right text-sm" { (np) }td class="whitespace-nowrap px-6 py-4 text-right text-sm" { (nc) }td class="whitespace-nowrap px-6 py-4 text-right font-medium text-sm" {- (format_memory_from_bytes(nm))+ (nm)}}}@@ -127,6 +131,13 @@ pub(crate) fn node_stats_table(nodes: &[serde_json::Value]) -> Markup {}}+fn node_count_cell(node: &serde_json::Value, key: &str) -> String {+ node.get(key)+ .and_then(|v| v.as_u64())+ .map(|v| v.to_string())+ .unwrap_or_else(|| "-".to_owned())+}+pub(crate) fn format_node_id(node_id: &str, index: usize) -> String {let trimmed = node_id.trim();if trimmed.is_empty() {diff --git a/fluxer_api/src/api/infrastructure/IGatewayService.ts b/fluxer_api/src/api/infrastructure/IGatewayService.tsindex 20f4497ba..e8f3ac0d6 100644--- a/fluxer_api/src/api/infrastructure/IGatewayService.ts+++ b/fluxer_api/src/api/infrastructure/IGatewayService.ts@@ -60,17 +60,21 @@ interface GatewayNodeMemoryStats {interface GatewayNodeStatsEntry {node_id: string;status: string;- sessions: number;+ sessions: number | null;session_resumes_total: number | null;websocket_dispatches_total: number | null;websocket_dispatch_drops_total: number | null;- guilds: number;- presences: number;- calls: number;- memory: GatewayNodeMemoryStats;- process_count: number;- process_limit: number;- uptime_seconds: number;+ guilds: number | null;+ presences: number | null;+ calls: number | null;+ memory: {+ total: string | null;+ processes: string | null;+ system: string | null;+ };+ process_count: number | null;+ process_limit: number | null;+ uptime_seconds: number | null;}export interface GatewayNodeStats {diff --git a/fluxer_docs/src/content/docs/admin-api/gateway.mdx b/fluxer_docs/src/content/docs/admin-api/gateway.mdxindex 95e8b95c5..23b56b227 100644--- a/fluxer_docs/src/content/docs/admin-api/gateway.mdx+++ b/fluxer_docs/src/content/docs/admin-api/gateway.mdx@@ -86,20 +86,20 @@ One node's statistics. A node that does not answer within 10 seconds is listed w| --- | --- | --- || node_id | string | The name the node reports for itself || status<sup>1</sup> | string | The health this node reported |-| sessions | integer | The number of connected Gateway sessions |+| sessions | ?integer | The number of connected Gateway sessions || session_resumes_total | ?integer | The total number of session resumes || websocket_dispatches_total | ?integer | The total number of WebSocket dispatches || websocket_dispatch_drops_total | ?integer | The total number of WebSocket dispatches dropped |-| guilds | integer | The number of live guild processes |-| presences | integer | The number of tracked presences |-| calls | integer | The number of live calls |+| guilds | ?integer | The number of live guild processes |+| presences | ?integer | The number of tracked presences |+| calls | ?integer | The number of live calls || memory | [node memory](#node-memory-object) object | The memory accounting |-| process_count | integer | The number of Erlang processes running |-| process_limit | integer | The maximum number of Erlang processes |-| uptime_seconds | integer | The seconds since this node started |+| process_count | ?integer | The number of Erlang processes running |+| process_limit | ?integer | The maximum number of Erlang processes |+| uptime_seconds | ?integer | The seconds since this node started || cluster_metrics? | [gateway cluster metrics](#gateway-cluster-metrics-object) object | How this node sees the cluster, absent when the node did not answer |-<sup>1</sup> `healthy` or `unavailable`. An `unavailable` node has no `cluster_metrics` and null counters.+<sup>1</sup> `healthy` or `unavailable`. An `unavailable` node has no `cluster_metrics`, and its counts and `memory` values are null.## Gateway cluster metrics object@@ -134,15 +134,15 @@ The cluster as one node sees it. Each `_total` count starts at zero when the nod## Node memory object-Byte counts for one node, or summed over all polled nodes. Each count is a decimal string.+Byte counts for one node, or summed over all polled nodes. Each count is a decimal string, or null for a node that did not answer.### Structure| Field | Type | Description || --- | --- | --- |-| total | string | The total bytes allocated |-| processes | string | The bytes allocated to Erlang processes |-| system | string | The bytes allocated outside Erlang processes |+| total | ?string | The total bytes allocated |+| processes | ?string | The bytes allocated to Erlang processes |+| system | ?string | The bytes allocated outside Erlang processes |## Guild memory statistics objectdiff --git a/packages/schema/src/domains/admin/AdminSchemas.ts b/packages/schema/src/domains/admin/AdminSchemas.tsindex b8da01130..203e0abcd 100644--- a/packages/schema/src/domains/admin/AdminSchemas.ts+++ b/packages/schema/src/domains/admin/AdminSchemas.ts@@ -1067,7 +1067,7 @@ export type CreateRegistrationUrlRequest = z.infer<typeof CreateRegistrationUrlRexport const CreateRegistrationUrlResponse = z.object({registration_url: RegistrationUrlResponse,- code: createStringType(1, 256),+ code: createStringType(1, 128),url: z.string(),});@@ -1428,21 +1428,21 @@ export const NodeStatsResponse = z.object({z.object({node_id: createStringType(1, 256),status: createStringType(1, 256),- sessions: Int32Type,+ sessions: Int32Type.nullable(),session_resumes_total: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable(),websocket_dispatches_total: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable(),websocket_dispatch_drops_total: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable(),- guilds: Int32Type,- presences: Int32Type,- calls: Int32Type,+ guilds: Int32Type.nullable(),+ presences: Int32Type.nullable(),+ calls: Int32Type.nullable(),memory: z.object({- total: Int64StringType,- processes: Int64StringType,- system: Int64StringType,+ total: Int64StringType.nullable(),+ processes: Int64StringType.nullable(),+ system: Int64StringType.nullable(),}),- process_count: Int32Type,- process_limit: Int32Type,- uptime_seconds: Int32Type,+ process_count: Int32Type.nullable(),+ process_limit: Int32Type.nullable(),+ uptime_seconds: Int32Type.nullable(),cluster_metrics: z.object({gateway_cluster_member_count: Int32Type,diff --git a/packages/schema/src/domains/auth/AuthSchemas.ts b/packages/schema/src/domains/auth/AuthSchemas.tsindex 275e0d9a8..0bb1fc04f 100644--- a/packages/schema/src/domains/auth/AuthSchemas.ts+++ b/packages/schema/src/domains/auth/AuthSchemas.ts@@ -50,7 +50,7 @@ export const RegisterRequest = z.object({'Whether the person submitted the step that says creating the account accepts the terms of service. Must be true when the instance publishes terms or a privacy policy',),invite_code: createStringType(0, 256).nullish().describe('Guild invite code to join after registration'),- registration_url_code: createStringType(1, 256)+ registration_url_code: createStringType(1, 128).nullish().describe('Admin-issued registration URL code to use for this registration'),theme: RegisterThemeType.optional().describe('Initial UI theme preference for the new account'),@@ -630,7 +630,7 @@ export const IdentifyRequest = z.object({),login: UsernameType.optional().describe('Username to sign in or sign up with, on username instances'),device_proof: DeviceProofType.optional(),- registration_url_code: createStringType(1, 256)+ registration_url_code: createStringType(1, 128).nullish().describe('Admin-issued registration URL code, for sign-ups'),});@@ -663,7 +663,7 @@ export type IdentifyResponse = z.infer<typeof IdentifyResponse>;export const EmailCodeSendRequest = z.object({ticket: createStringType(1, 128).describe('Ticket from POST /auth/identify'),- registration_url_code: createStringType(1, 256)+ registration_url_code: createStringType(1, 128).nullish().describe('Admin-issued registration URL code, for sign-ups'),});@@ -687,7 +687,7 @@ export const EmailCodeVerifyRequest = z.object({.describe('For sign-ups, whether the person submitted the step that says creating the account accepts the terms of service. Must be true when the instance publishes terms or a privacy policy',),- registration_url_code: createStringType(1, 256)+ registration_url_code: createStringType(1, 128).nullish().describe('Admin-issued registration URL code, for sign-ups'),invite_code: createStringType(0, 256).nullish().describe('Invite to open after the date of birth step, for sign-ups'),@@ -712,7 +712,7 @@ export const AccountHandoffRequest = z.object({.regex(/^[0-9a-f]{64}$/u).describe('Hex SHA-256 of the nonce the browser keeps until redeeming'),locale: z.string().min(2).max(16).optional().describe('Locale of the page the account was created from'),- registration_url_code: createStringType(1, 256)+ registration_url_code: createStringType(1, 128).nullish().describe('Admin-issued registration URL code, for sign-ups'),});