@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
106 lines • 3.33 kB
TypeScript
import { Client } from "../abstract/Client";
import type { Cluster } from "../abstract/Cluster";
import { DefaultMap } from "../internal/DefaultMap";
import type { PickPartial } from "../internal/misc";
/**
* Scoreboard tool constructor options.
*/
export interface ToolScoreboardOptions {
cluster: Cluster<Client>;
refreshMs?: number;
pingExecTimeMs?: number;
pingParallelism?: number;
pingPollMs?: number;
tickMs?: number;
maxQueries?: number;
maxErrors?: number;
}
type ClientIdent = number | "master" | "replica";
interface ToolScoreboardQuery {
timestamp: number;
elapsed: number | null;
op: "tick" | "discovery" | "query";
error: string | null;
}
interface ToolScoreboardSwallowedError {
timestamp: number;
elapsed: number | null;
message: string;
}
interface ToolScoreboardQueryError {
timestamp: number;
elapsed: number | null;
message: string;
clientIdent: ClientIdent;
}
/**
* A tool which plays the role of Linux `top` command, but for the Cluster.
* Tracks the state of the Cluster and Clients health.
*/
export declare class ToolScoreboard {
/** Default values for the constructor options. */
static readonly DEFAULT_OPTIONS: Required<PickPartial<ToolScoreboardOptions>>;
private launchedPollers;
private renderCallCount;
private renderCallFirstAt?;
private queryPollDefers;
/** Options of this tool. */
readonly options: Required<ToolScoreboardOptions>;
/** Registry of all Islands with Clients. */
islands: Map<number, {
shards: number;
clients: Map<ClientIdent, Client>;
}>;
/** Log of queries sent (ping, discovery, tick). */
queries: DefaultMap<number, DefaultMap<ClientIdent, ToolScoreboardQuery[]>>;
/** Pool stats of Clients. */
poolStats: DefaultMap<number, Map<ClientIdent, {
totalConns: number;
idleConns: number;
queuedReqs: number;
}>>;
/** Registry of the recent swallowed errors (pings-independent). */
swallowedErrors: ToolScoreboardSwallowedError[];
/** Errors extracted from the queries log. */
queryErrors: ToolScoreboardQueryError[];
/**
* Initializes the instance.
*/
constructor(options: ToolScoreboardOptions);
/**
* Runs an endless loop that updates the Scoreboard with the current state of
* the Cluster and yields back on every refreshMs tick.
*/
[Symbol.asyncIterator](): AsyncGenerator<this>;
/**
* Renders the current state of the Scoreboard as a string.
*/
render(): string;
/**
* Renders a colorful cell corresponding to one query.
*/
private renderQuery;
/**
* Renders the text value of a cell corresponding to a query.
*/
private renderElapsed;
/**
* Runs an endless polling loop for the provided Client. The loop terminates
* if the Client disappears from the cluster.
*/
private pollerLoop;
/**
* Adds a query (probably running right now) to the Scoreboard.
*/
private addQuery;
/**
* Adds an error to the Scoreboard.
*/
private addSwallowedError;
/**
* Finds all existing Client by matching their addresses to the passed one.
*/
private findClients;
}
export {};
//# sourceMappingURL=ToolScoreboard.d.ts.map