mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: switch ssh session stats based on experiment (#13637)
This commit is contained in:
@@ -24,6 +24,7 @@ import type dayjs from "dayjs";
|
||||
import userAgentParser from "ua-parser-js";
|
||||
import { delay } from "../utils/delay";
|
||||
import * as TypesGen from "./typesGenerated";
|
||||
import type { PostWorkspaceUsageRequest } from "./typesGenerated";
|
||||
|
||||
const getMissingParameters = (
|
||||
oldBuildParameters: TypesGen.WorkspaceBuildParameter[],
|
||||
@@ -1879,6 +1880,18 @@ class ApiMethods {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
postWorkspaceUsage = async (
|
||||
workspaceID: string,
|
||||
options: PostWorkspaceUsageRequest,
|
||||
) => {
|
||||
const response = await this.axios.post(
|
||||
`/api/v2/workspaces/${workspaceID}/usage`,
|
||||
options,
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
}
|
||||
|
||||
// This is a hard coded CSRF token/cookie pair for local development. In prod,
|
||||
|
||||
@@ -8,12 +8,14 @@ import { type DeleteWorkspaceOptions, API } from "api/api";
|
||||
import type {
|
||||
CreateWorkspaceRequest,
|
||||
ProvisionerLogLevel,
|
||||
UsageAppName,
|
||||
Workspace,
|
||||
WorkspaceBuild,
|
||||
WorkspaceBuildParameter,
|
||||
WorkspacesRequest,
|
||||
WorkspacesResponse,
|
||||
} from "api/typesGenerated";
|
||||
import type { ConnectionStatus } from "pages/TerminalPage/types";
|
||||
import { disabledRefetchOptions } from "./util";
|
||||
import { workspaceBuildsKey } from "./workspaceBuilds";
|
||||
|
||||
@@ -313,3 +315,41 @@ export const agentLogs = (workspaceId: string, agentId: string) => {
|
||||
...disabledRefetchOptions,
|
||||
};
|
||||
};
|
||||
|
||||
// workspace usage options
|
||||
export interface WorkspaceUsageOptions {
|
||||
usageApp: UsageAppName;
|
||||
connectionStatus: ConnectionStatus;
|
||||
workspaceId: string | undefined;
|
||||
agentId: string | undefined;
|
||||
}
|
||||
|
||||
export const workspaceUsage = (options: WorkspaceUsageOptions) => {
|
||||
return {
|
||||
queryKey: [
|
||||
"workspaces",
|
||||
options.workspaceId,
|
||||
"agents",
|
||||
options.agentId,
|
||||
"usage",
|
||||
options.usageApp,
|
||||
],
|
||||
enabled:
|
||||
options.workspaceId !== undefined &&
|
||||
options.agentId !== undefined &&
|
||||
options.connectionStatus === "connected",
|
||||
queryFn: () => {
|
||||
if (options.workspaceId === undefined || options.agentId === undefined) {
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return API.postWorkspaceUsage(options.workspaceId, {
|
||||
agent_id: options.agentId,
|
||||
app_name: options.usageApp,
|
||||
});
|
||||
},
|
||||
// ...disabledRefetchOptions,
|
||||
refetchInterval: 60000,
|
||||
refetchIntervalInBackground: true,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,7 +12,10 @@ import { Unicode11Addon } from "xterm-addon-unicode11";
|
||||
import { WebLinksAddon } from "xterm-addon-web-links";
|
||||
import { WebglAddon } from "xterm-addon-webgl";
|
||||
import { deploymentConfig } from "api/queries/deployment";
|
||||
import { workspaceByOwnerAndName } from "api/queries/workspaces";
|
||||
import {
|
||||
workspaceByOwnerAndName,
|
||||
workspaceUsage,
|
||||
} from "api/queries/workspaces";
|
||||
import { useProxy } from "contexts/ProxyContext";
|
||||
import { ThemeOverride } from "contexts/ThemeProvider";
|
||||
import themes from "theme";
|
||||
@@ -67,6 +70,16 @@ const TerminalPage: FC = () => {
|
||||
const config = useQuery(deploymentConfig());
|
||||
const renderer = config.data?.config.web_terminal_renderer;
|
||||
|
||||
// Periodically report workspace usage.
|
||||
useQuery(
|
||||
workspaceUsage({
|
||||
usageApp: "reconnecting-pty",
|
||||
connectionStatus,
|
||||
workspaceId: workspace.data?.id,
|
||||
agentId: workspaceAgent?.id,
|
||||
}),
|
||||
);
|
||||
|
||||
// handleWebLink handles opening of URLs in the terminal!
|
||||
const handleWebLink = useCallback(
|
||||
(uri: string) => {
|
||||
|
||||
Reference in New Issue
Block a user