Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 102 additions & 91 deletions gen/proto/go/prehog/v1alpha/connect.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions gen/proto/js/prehog/v1alpha/connect_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion gen/proto/js/prehog/v1alpha/connect_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/prehog/v1alpha/connect.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ message ConnectProtocolUseEvent {
string user_name = 2;
// one of ssh/db/kube
string protocol = 3;
// one of resource_table/search_bar/connection_list/reopened_session (optional)
string origin = 4;
}

message ConnectAccessRequestCreateEvent {
Expand Down
3 changes: 2 additions & 1 deletion web/packages/teleterm/src/services/tshd/mapUsageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function mapPrehogBody(
const reqEvent = new prehogApi.ConnectProtocolUseEvent()
.setClusterName(event.clusterName)
.setUserName(event.userName)
.setProtocol(event.protocol);
.setProtocol(event.protocol)
.setOrigin(event.origin);

return req.setProtocolUse(reqEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ export function useDatabases() {
targetUri: db.uri,
targetName: db.name,
targetUser: getTargetUser(db.protocol as GatewayProtocol, dbUser),
origin: 'resource_table',
});

const connectionToReuse =
appContext.connectionTracker.findConnectionByDocument(doc);

if (connectionToReuse) {
appContext.connectionTracker.activateItem(connectionToReuse.id);
appContext.connectionTracker.activateItem(connectionToReuse.id, {
origin: 'resource_table',
});
} else {
documentsService.add(doc);
documentsService.open(doc.uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import { Kube, ServerSideParams } from 'teleterm/services/tshd/types';
import { useAppContext } from 'teleterm/ui/appContextProvider';
import { useClusterContext } from 'teleterm/ui/DocumentCluster/clusterContext';
import { KubeUri } from 'teleterm/ui/uri';

import { useServerSideResources } from '../useServerSideResources';

Expand All @@ -29,7 +30,8 @@ export function useKubes() {
);

return {
connect: ctx.connectKube,
connect: (kubeUri: KubeUri) =>
ctx.connectKube(kubeUri, { origin: 'resource_table' }),
fetchAttempt,
...serversideResources,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function useServers() {
);
const documentsService =
appContext.workspacesService.getWorkspaceDocumentService(rootCluster.uri);
const doc = documentsService.createTshNodeDocument(server.uri);
const doc = documentsService.createTshNodeDocument(server.uri, {
origin: 'resource_table',
});
doc.title = `${login}@${server.hostname}`;
doc.login = login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useStore, Store } from 'shared/libs/stores';

import { IAppContext } from 'teleterm/ui/types';
import { ClusterUri, DocumentUri, KubeUri, routing } from 'teleterm/ui/uri';
import { DocumentOrigin } from 'teleterm/ui/services/workspacesService';

import type * as tsh from 'teleterm/services/tshd/types';

Expand Down Expand Up @@ -71,8 +72,11 @@ class ClusterContext extends Store<State> {
});
};

connectKube = (kubeUri: KubeUri) => {
this.appCtx.commandLauncher.executeCommand('kube-connect', { kubeUri });
connectKube = (kubeUri: KubeUri, params: { origin: DocumentOrigin }) => {
this.appCtx.commandLauncher.executeCommand('kube-connect', {
kubeUri,
origin: params.origin,
});
};

refresh = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function useGateway(doc: types.DocumentGateway) {
// same port number.
port: gw.localPort,
});
ctx.usageService.captureProtocolUse(doc.targetUri, 'db', doc.origin);
});

const [disconnectAttempt, disconnect] = useAsync(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const getDocTshNodeWithServerId: () => DocumentTshNodeWithServerId = () => ({
rootClusterId: 'test',
leafClusterId: undefined,
login: 'user',
origin: 'resource_table',
});

const getDocTshNodeWithLoginHost: () => DocumentTshNodeWithLoginHost = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ async function setUpPtyProcess(
const cmd = createCmd(doc, rootCluster.proxyHost, getClusterName());
const ptyProcess = await createPtyProcess(ctx, cmd);

if (cmd.kind === 'pty.tsh-login') {
ctx.usageService.captureProtocolUse(clusterUri, 'ssh');
if (doc.kind === 'doc.terminal_tsh_node') {
ctx.usageService.captureProtocolUse(clusterUri, 'ssh', doc.origin);
}
if (cmd.kind === 'pty.tsh-kube-login') {
ctx.usageService.captureProtocolUse(clusterUri, 'kube');
if (doc.kind === 'doc.terminal_tsh_kube') {
ctx.usageService.captureProtocolUse(clusterUri, 'kube', doc.origin);
}

const openContextMenu = () => ctx.mainProcessClient.openTerminalContextMenu();
Expand Down
16 changes: 15 additions & 1 deletion web/packages/teleterm/src/ui/QuickInput/useQuickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ import { assertUnreachable, retryWithRelogin } from '../utils';

export default function useQuickInput() {
const appContext = useAppContext();
const { quickInputService, workspacesService, commandLauncher } = appContext;
const {
quickInputService,
workspacesService,
commandLauncher,
usageService,
} = appContext;
workspacesService.useState();
const documentsService =
workspacesService.getActiveWorkspaceDocumentService();
Expand Down Expand Up @@ -105,6 +110,14 @@ export default function useQuickInput() {
const params = routing.parseClusterUri(
workspacesService.getActiveWorkspace()?.localClusterUri
).params;
// ugly hack but QuickInput will be removed in v13
if (inputValue.startsWith('tsh proxy db')) {
usageService.captureProtocolUse(
workspacesService.getRootClusterUri(),
'db',
'search_bar'
);
}
documentsService.openNewTerminal({
initCommand: inputValue,
rootClusterId: routing.parseClusterUri(
Expand All @@ -120,6 +133,7 @@ export default function useQuickInput() {
commandLauncher.executeCommand('tsh-ssh', {
loginHost: command.loginHost,
localClusterUri,
origin: 'search_bar',
});
break;
}
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getMockDocuments(): Document[] {
targetUri: '/clusters/bar/dbs/foobar',
targetName: 'foobar',
targetUser: 'foo',
origin: 'resource_table',
},
{
kind: 'doc.gateway',
Expand All @@ -68,6 +69,7 @@ function getMockDocuments(): Document[] {
targetUri: '/clusters/bar/dbs/foobar',
targetName: 'foobar',
targetUser: 'bar',
origin: 'resource_table',
},
{
kind: 'doc.cluster',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function useConnections() {
return {
isAnyConnectionActive: items.some(c => c.connected),
removeItem: (id: string) => connectionTracker.removeItem(id),
activateItem: (id: string) => connectionTracker.activateItem(id),
activateItem: (id: string) =>
connectionTracker.activateItem(id, { origin: 'connection_list' }),
disconnectItem: (id: string) => connectionTracker.disconnectItem(id),
updateSorting,
items: getSortedItems(),
Expand Down
15 changes: 11 additions & 4 deletions web/packages/teleterm/src/ui/commandLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IAppContext } from 'teleterm/ui/types';
import { ClusterUri, KubeUri, RootClusterUri, routing } from 'teleterm/ui/uri';
import { TrackedKubeConnection } from 'teleterm/ui/services/connectionTracker';
import { Platform } from 'teleterm/mainProcess/types';
import { DocumentOrigin } from 'teleterm/ui/services/workspacesService';

const commands = {
// For handling "tsh ssh" executed from the command bar.
Expand All @@ -26,16 +27,21 @@ const commands = {
description: '',
run(
ctx: IAppContext,
args: { loginHost: string; localClusterUri: ClusterUri }
args: {
loginHost: string;
localClusterUri: ClusterUri;
origin: DocumentOrigin;
}
) {
const { loginHost, localClusterUri } = args;
const { loginHost, localClusterUri, origin } = args;
const rootClusterUri = routing.ensureRootClusterUri(localClusterUri);
const documentsService =
ctx.workspacesService.getWorkspaceDocumentService(rootClusterUri);

const doc = documentsService.createTshNodeDocumentFromLoginHost(
localClusterUri,
loginHost
loginHost,
{ origin }
);
documentsService.add(doc);
documentsService.setLocation(doc.uri);
Expand Down Expand Up @@ -89,11 +95,12 @@ const commands = {
'kube-connect': {
displayName: '',
description: '',
run(ctx: IAppContext, args: { kubeUri: KubeUri }) {
run(ctx: IAppContext, args: { kubeUri: KubeUri; origin: DocumentOrigin }) {
const documentsService =
ctx.workspacesService.getActiveWorkspaceDocumentService();
const kubeDoc = documentsService.createTshKubeDocument({
kubeUri: args.kubeUri,
origin: args.origin,
});
const connection = ctx.connectionTracker.findConnectionByDocument(
kubeDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ export class ClustersService extends ImmutableStore<types.ClustersServiceState>

async createGateway(params: tsh.CreateGatewayParams) {
const gateway = await this.client.createGateway(params);
this.usageService.captureProtocolUse(params.targetUri, 'db');
this.setState(draft => {
draft.gateways.set(gateway.uri, gateway);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ it('updates the port of a gateway connection when the underlying doc gets update
targetName: 'test',
targetSubresourceName: 'pg',
port: '12345',
origin: 'resource_table',
};

const { connectionTrackerService, workspacesService } =
Expand Down Expand Up @@ -142,6 +143,7 @@ it('creates a connection for doc.terminal_tsh_node docs with serverUri', () => {
rootClusterId: 'localhost',
leafClusterId: undefined,
login: 'user',
origin: 'resource_table',
};

const { connectionTrackerService } = getTestSetupWithMockedDocuments([
Expand Down Expand Up @@ -170,6 +172,7 @@ it('ignores doc.terminal_tsh_node docs with no serverUri', () => {
loginHost: 'user@foo',
rootClusterId: 'test',
leafClusterId: undefined,
origin: 'resource_table',
};

const { connectionTrackerService } = getTestSetupWithMockedDocuments([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useStore } from 'shared/libs/stores';
import { ClustersService } from 'teleterm/ui/services/clusters';
import {
Document,
DocumentOrigin,
isDocumentTshNodeWithLoginHost,
WorkspacesService,
} from 'teleterm/ui/services/workspacesService';
Expand Down Expand Up @@ -81,15 +82,18 @@ export class ConnectionTrackerService extends ImmutableStore<ConnectionTrackerSt
});
}

async activateItem(id: string): Promise<void> {
async activateItem(
id: string,
params: { origin: DocumentOrigin }
): Promise<void> {
const connection = this.state.connections.find(c => c.id === id);
const { rootClusterUri, activate } =
this._trackedConnectionOperationsFactory.create(connection);

if (rootClusterUri !== this._workspacesService.getRootClusterUri()) {
await this._workspacesService.setActiveWorkspace(rootClusterUri);
}
activate();
activate(params);
}

findConnectionByDocument(document: Document): TrackedConnection {
Expand Down
Loading