MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / fetchEnvironmentHealth

Function fetchEnvironmentHealth

console/src/store/environments.ts:463–539  ·  view source on GitHub ↗
(
  environment: {
    httpAddress: EnabledEnvironment["httpAddress"];
    resolvable: EnabledEnvironment["resolvable"];
    enabledAt: EnabledEnvironment["enabledAt"];
  },
  timeoutMs: number = defaultTimeout,
  maxBoot: Duration = maxBootDuration,
)

Source from the content-addressed store, hash-verified

461]);
462
463export const fetchEnvironmentHealth = async (
464 environment: {
465 httpAddress: EnabledEnvironment["httpAddress"];
466 resolvable: EnabledEnvironment["resolvable"];
467 enabledAt: EnabledEnvironment["enabledAt"];
468 },
469 timeoutMs: number = defaultTimeout,
470 maxBoot: Duration = maxBootDuration,
471): Promise<EnvironmentStatus> => {
472 // Determine if the environment is healthy by issuing a basic SQL query.
473 const controller = new AbortController();
474 const timeout = setTimeout(() => controller.abort(), timeoutMs);
475 let version: DbVersion | undefined = undefined;
476 try {
477 if (!environment.resolvable) {
478 throw new Error(`Environment unresolvable`);
479 }
480 const result = await executeSql(
481 environment.httpAddress,
482 {
483 queries: [
484 {
485 query: selectVersionQuery.sql,
486 params: selectVersionQuery.parameters as string[],
487 },
488 ],
489 cluster: CATALOG_SERVER_CLUSTER,
490 },
491 { signal: controller.signal },
492 );
493 if ("errorMessage" in result) {
494 const errors: EnvironmentError[] = [];
495 if ("code" in result && BLOCKED_ERROR_CODES.has(result.code)) {
496 if (
497 result.code === MaterializeErrorCode.NETWORK_POLICY_SESSION_DENIED
498 ) {
499 errors.push({
500 message: "Environment blocked",
501 details: new NetworkPolicyError(result.code, result.detail),
502 });
503 }
504 return {
505 health: "blocked",
506 errors,
507 };
508 }
509 errors.push({
510 message: "Environmentd health check failed",
511 });
512 errors.push({
513 message: result.errorMessage,
514 });
515 return { health: "crashed", errors };
516 } else {
517 const versionString = result.results[0].rows[0][0] as string;
518 version = parseDbVersion(versionString);
519 return { health: "healthy", version, errors: [] };
520 }

Callers 2

Calls 4

executeSqlFunction · 0.90
parseDbVersionFunction · 0.90
formatDurationFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected