refactor(site): use generated Healthcheck API entities (#10650)

This commit is contained in:
Marcin Tojek 2023-11-13 15:58:57 +01:00 committed by GitHub
parent b69c237b8a
commit fbd34139b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 110 deletions

View File

@ -28,13 +28,13 @@ import (
var ( var (
// baseDirs are the directories to introspect for types to generate. // baseDirs are the directories to introspect for types to generate.
baseDirs = [...]string{"./codersdk", "./coderd/healthcheck", "./coderd/healthcheck/derphealth"} baseDirs = [...]string{"./codersdk", "./coderd/healthcheck"}
// externalTypes are types that are not in the baseDirs, but we want to // externalTypes are types that are not in the baseDirs, but we want to
// support. These are usually types that are used in the baseDirs. // support. These are usually types that are used in the baseDirs.
// Do not include things like "Database", as that would break the idea // Do not include things like "Database", as that would break the idea
// of splitting db and api types. // of splitting db and api types.
// Only include dirs that are client facing packages. // Only include dirs that are client facing packages.
externalTypeDirs = [...]string{"./cli/clibase"} externalTypeDirs = [...]string{"./cli/clibase", "./coderd/healthcheck/derphealth"}
indent = " " indent = " "
) )

View File

@ -1555,17 +1555,9 @@ export const getInsightsTemplate = async (
return response.data; return response.data;
}; };
export interface Health {
healthy: boolean;
time: string;
coder_version: string;
access_url: { healthy: boolean };
database: { healthy: boolean };
derp: { healthy: boolean };
websocket: { healthy: boolean };
}
export const getHealth = async () => { export const getHealth = async () => {
const response = await axios.get<Health>("/api/v2/debug/health"); const response = await axios.get<TypesGen.HealthcheckReport>(
"/api/v2/debug/health",
);
return response.data; return response.data;
}; };

View File

@ -2104,9 +2104,7 @@ export interface HealthcheckReport {
readonly time: string; readonly time: string;
readonly healthy: boolean; readonly healthy: boolean;
readonly failing_sections: string[]; readonly failing_sections: string[];
// Named type "github.com/coder/coder/v2/coderd/healthcheck/derphealth.Report" unknown, using "any" readonly derp: DerphealthReport;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type
readonly derp: any;
readonly access_url: HealthcheckAccessURLReport; readonly access_url: HealthcheckAccessURLReport;
readonly websocket: HealthcheckWebsocketReport; readonly websocket: HealthcheckWebsocketReport;
readonly database: HealthcheckDatabaseReport; readonly database: HealthcheckDatabaseReport;
@ -2121,6 +2119,51 @@ export interface HealthcheckWebsocketReport {
readonly error?: string; readonly error?: string;
} }
// The code below is generated from cli/clibase.
// From clibase/clibase.go
export type ClibaseAnnotations = Record<string, string>;
// From clibase/clibase.go
export interface ClibaseGroup {
readonly parent?: ClibaseGroup;
readonly name?: string;
readonly yaml?: string;
readonly description?: string;
}
// From clibase/option.go
export interface ClibaseOption {
readonly name?: string;
readonly description?: string;
readonly required?: boolean;
readonly flag?: string;
readonly flag_shorthand?: string;
readonly env?: string;
readonly yaml?: string;
readonly default?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type.
readonly value?: any;
readonly annotations?: ClibaseAnnotations;
readonly group?: ClibaseGroup;
readonly use_instead?: ClibaseOption[];
readonly hidden?: boolean;
readonly value_source?: ClibaseValueSource;
}
// From clibase/option.go
export type ClibaseOptionSet = ClibaseOption[];
// From clibase/option.go
export type ClibaseValueSource = "" | "default" | "env" | "flag" | "yaml";
export const ClibaseValueSources: ClibaseValueSource[] = [
"",
"default",
"env",
"flag",
"yaml",
];
// The code below is generated from coderd/healthcheck/derphealth. // The code below is generated from coderd/healthcheck/derphealth.
// From derphealth/derp.go // From derphealth/derp.go
@ -2170,48 +2213,3 @@ export interface DerphealthStunReport {
readonly CanSTUN: boolean; readonly CanSTUN: boolean;
readonly Error?: string; readonly Error?: string;
} }
// The code below is generated from cli/clibase.
// From clibase/clibase.go
export type ClibaseAnnotations = Record<string, string>;
// From clibase/clibase.go
export interface ClibaseGroup {
readonly parent?: ClibaseGroup;
readonly name?: string;
readonly yaml?: string;
readonly description?: string;
}
// From clibase/option.go
export interface ClibaseOption {
readonly name?: string;
readonly description?: string;
readonly required?: boolean;
readonly flag?: string;
readonly flag_shorthand?: string;
readonly env?: string;
readonly yaml?: string;
readonly default?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type.
readonly value?: any;
readonly annotations?: ClibaseAnnotations;
readonly group?: ClibaseGroup;
readonly use_instead?: ClibaseOption[];
readonly hidden?: boolean;
readonly value_source?: ClibaseValueSource;
}
// From clibase/option.go
export type ClibaseOptionSet = ClibaseOption[];
// From clibase/option.go
export type ClibaseValueSource = "" | "default" | "env" | "flag" | "yaml";
export const ClibaseValueSources: ClibaseValueSource[] = [
"",
"default",
"env",
"flag",
"yaml",
];

View File

@ -1,5 +1,8 @@
import type { Health } from "api/api"; import type {
import type { DeploymentStats, WorkspaceStatus } from "api/typesGenerated"; DeploymentStats,
HealthcheckReport,
WorkspaceStatus,
} from "api/typesGenerated";
import { import {
type FC, type FC,
useMemo, useMemo,
@ -67,7 +70,7 @@ const styles = {
} satisfies Record<string, Interpolation<Theme>>; } satisfies Record<string, Interpolation<Theme>>;
export interface DeploymentBannerViewProps { export interface DeploymentBannerViewProps {
health?: Health; health?: HealthcheckReport;
stats?: DeploymentStats; stats?: DeploymentStats;
fetchStats?: () => void; fetchStats?: () => void;
} }

View File

@ -2,7 +2,6 @@ import {
withDefaultFeatures, withDefaultFeatures,
type GetLicensesResponse, type GetLicensesResponse,
type DeploymentConfig, type DeploymentConfig,
type Health,
} from "api/api"; } from "api/api";
import { FieldError } from "api/errors"; import { FieldError } from "api/errors";
import * as TypesGen from "api/typesGenerated"; import * as TypesGen from "api/typesGenerated";
@ -2385,10 +2384,10 @@ export const MockLicenseResponse: GetLicensesResponse[] = [
}, },
]; ];
export const MockHealth = { export const MockHealth: TypesGen.HealthcheckReport = {
time: "2023-08-01T16:51:03.29792825Z", time: "2023-08-01T16:51:03.29792825Z",
healthy: true, healthy: true,
failing_sections: null, failing_sections: [],
derp: { derp: {
healthy: true, healthy: true,
regions: { regions: {
@ -2431,15 +2430,14 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: false, can_exchange_messages: false,
round_trip_ping: 0, round_trip_ping: "0",
round_trip_ping_ms: 0,
uses_websocket: false, uses_websocket: false,
client_logs: [], client_logs: [],
client_errs: [], client_errs: [],
error: null,
stun: { stun: {
Enabled: true, Enabled: true,
CanSTUN: true, CanSTUN: true,
Error: null,
}, },
}, },
{ {
@ -2456,7 +2454,8 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: true, can_exchange_messages: true,
round_trip_ping: 7674330, round_trip_ping: "7674330",
round_trip_ping_ms: 7674330,
uses_websocket: false, uses_websocket: false,
client_logs: [ client_logs: [
[ [
@ -2467,15 +2466,12 @@ export const MockHealth = {
], ],
], ],
client_errs: [[], []], client_errs: [[], []],
error: null,
stun: { stun: {
Enabled: false, Enabled: false,
CanSTUN: false, CanSTUN: false,
Error: null,
}, },
}, },
], ],
error: null,
}, },
"10007": { "10007": {
healthy: true, healthy: true,
@ -2516,15 +2512,14 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: false, can_exchange_messages: false,
round_trip_ping: 0, round_trip_ping: "0",
round_trip_ping_ms: 0,
uses_websocket: false, uses_websocket: false,
client_logs: [], client_logs: [],
client_errs: [], client_errs: [],
error: null,
stun: { stun: {
Enabled: true, Enabled: true,
CanSTUN: true, CanSTUN: true,
Error: null,
}, },
}, },
{ {
@ -2541,7 +2536,8 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: true, can_exchange_messages: true,
round_trip_ping: 170527034, round_trip_ping: "170527034",
round_trip_ping_ms: 170527034,
uses_websocket: false, uses_websocket: false,
client_logs: [ client_logs: [
[ [
@ -2552,15 +2548,12 @@ export const MockHealth = {
], ],
], ],
client_errs: [[], []], client_errs: [[], []],
error: null,
stun: { stun: {
Enabled: false, Enabled: false,
CanSTUN: false, CanSTUN: false,
Error: null,
}, },
}, },
], ],
error: null,
}, },
"10008": { "10008": {
healthy: true, healthy: true,
@ -2601,15 +2594,14 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: false, can_exchange_messages: false,
round_trip_ping: 0, round_trip_ping: "0",
round_trip_ping_ms: 0,
uses_websocket: false, uses_websocket: false,
client_logs: [], client_logs: [],
client_errs: [], client_errs: [],
error: null,
stun: { stun: {
Enabled: true, Enabled: true,
CanSTUN: true, CanSTUN: true,
Error: null,
}, },
}, },
{ {
@ -2626,7 +2618,8 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: true, can_exchange_messages: true,
round_trip_ping: 111329690, round_trip_ping: "111329690",
round_trip_ping_ms: 111329690,
uses_websocket: false, uses_websocket: false,
client_logs: [ client_logs: [
[ [
@ -2637,15 +2630,12 @@ export const MockHealth = {
], ],
], ],
client_errs: [[], []], client_errs: [[], []],
error: null,
stun: { stun: {
Enabled: false, Enabled: false,
CanSTUN: false, CanSTUN: false,
Error: null,
}, },
}, },
], ],
error: null,
}, },
"10009": { "10009": {
healthy: true, healthy: true,
@ -2686,15 +2676,14 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: false, can_exchange_messages: false,
round_trip_ping: 0, round_trip_ping: "0",
round_trip_ping_ms: 0,
uses_websocket: false, uses_websocket: false,
client_logs: [], client_logs: [],
client_errs: [], client_errs: [],
error: null,
stun: { stun: {
Enabled: true, Enabled: true,
CanSTUN: true, CanSTUN: true,
Error: null,
}, },
}, },
{ {
@ -2711,7 +2700,8 @@ export const MockHealth = {
TokenBucketBytesBurst: 0, TokenBucketBytesBurst: 0,
}, },
can_exchange_messages: true, can_exchange_messages: true,
round_trip_ping: 138185506, round_trip_ping: "138185506",
round_trip_ping_ms: 138185506,
uses_websocket: false, uses_websocket: false,
client_logs: [ client_logs: [
[ [
@ -2722,15 +2712,12 @@ export const MockHealth = {
], ],
], ],
client_errs: [[], []], client_errs: [[], []],
error: null,
stun: { stun: {
Enabled: false, Enabled: false,
CanSTUN: false, CanSTUN: false,
Error: null,
}, },
}, },
], ],
error: null,
}, },
}, },
netcheck: { netcheck: {
@ -2764,7 +2751,6 @@ export const MockHealth = {
GlobalV6: "", GlobalV6: "",
CaptivePortal: null, CaptivePortal: null,
}, },
netcheck_err: null,
netcheck_logs: [ netcheck_logs: [
"netcheck: netcheck.runProbe: got STUN response for 10007stun0 from 34.71.26.24:55368 (9b07930007da49dd7df79bc7) in 1.791799ms", "netcheck: netcheck.runProbe: got STUN response for 10007stun0 from 34.71.26.24:55368 (9b07930007da49dd7df79bc7) in 1.791799ms",
"netcheck: netcheck.runProbe: got STUN response for 999stun0 from 34.71.26.24:55368 (7397fec097f1d5b01364566b) in 1.791529ms", "netcheck: netcheck.runProbe: got STUN response for 999stun0 from 34.71.26.24:55368 (7397fec097f1d5b01364566b) in 1.791529ms",
@ -2777,7 +2763,6 @@ export const MockHealth = {
"netcheck: [v1] measureAllICMPLatency: listen ip4:icmp 0.0.0.0: socket: operation not permitted", "netcheck: [v1] measureAllICMPLatency: listen ip4:icmp 0.0.0.0: socket: operation not permitted",
"netcheck: [v1] report: udp=true v6=false v6os=true mapvarydest=false hair= portmap= v4a=34.71.26.24:55368 derp=999 derpdist=999v4:2ms,10007v4:175ms,10008v4:112ms,10009v4:139ms", "netcheck: [v1] report: udp=true v6=false v6os=true mapvarydest=false hair= portmap= v4a=34.71.26.24:55368 derp=999 derpdist=999v4:2ms,10007v4:175ms,10008v4:112ms,10009v4:139ms",
], ],
error: null,
}, },
access_url: { access_url: {
access_url: "https://dev.coder.com", access_url: "https://dev.coder.com",
@ -2785,21 +2770,17 @@ export const MockHealth = {
reachable: true, reachable: true,
status_code: 200, status_code: 200,
healthz_response: "OK", healthz_response: "OK",
error: null,
}, },
websocket: { websocket: {
healthy: true, healthy: true,
response: { body: "",
body: "", code: 101,
code: 101,
},
error: null,
}, },
database: { database: {
healthy: true, healthy: true,
reachable: true, reachable: true,
latency: 92570, latency: "92570",
error: null, latency_ms: 92570,
}, },
coder_version: "v0.27.1-devel+c575292", coder_version: "v0.27.1-devel+c575292",
}; };
@ -2813,12 +2794,32 @@ export const MockListeningPortsResponse: TypesGen.WorkspaceAgentListeningPortsRe
], ],
}; };
export const DeploymentHealthUnhealthy: Health = { export const DeploymentHealthUnhealthy: TypesGen.HealthcheckReport = {
healthy: false, healthy: false,
failing_sections: [], // apparently this property is not used at all?
time: "2023-10-12T23:15:00.000000000Z", time: "2023-10-12T23:15:00.000000000Z",
coder_version: "v2.3.0-devel+8cca4915a", coder_version: "v2.3.0-devel+8cca4915a",
access_url: { healthy: true }, access_url: {
database: { healthy: false }, healthy: true,
derp: { healthy: false }, access_url: "",
websocket: { healthy: false }, healthz_response: "",
reachable: true,
status_code: 0,
},
database: {
healthy: false,
latency: "",
latency_ms: 0,
reachable: true,
},
derp: {
healthy: false,
regions: [],
netcheck_logs: [],
},
websocket: {
healthy: false,
body: "",
code: 0,
},
}; };