Skip to content

Commit d0d18fb

Browse files
Add logs to detect the cause of the problem
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent b0f2695 commit d0d18fb

1 file changed

Lines changed: 103 additions & 15 deletions

File tree

code/extensions/che-api/src/extension.ts

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,111 @@ if (Reflect.metadata === undefined) {
1818

1919
import { Container } from 'inversify';
2020
import * as vscode from 'vscode';
21-
import { Api } from './api/api';
22-
import { DevfileService } from './api/devfile-service';
23-
import { K8SService } from './api/k8s-service';
24-
import { K8sDevfileServiceImpl } from './impl/k8s-devfile-service-impl';
25-
import { K8SServiceImpl } from './impl/k8s-service-impl';
26-
import { K8sDevWorkspaceEnvVariables } from './impl/k8s-devworkspace-env-variables';
27-
import { WorkspaceService } from './api/workspace-service';
28-
import { K8sWorkspaceServiceImpl } from './impl/k8s-workspace-service-impl';
29-
import { GithubService } from './api/github-service';
30-
import { GithubServiceImpl } from './impl/github-service-impl';
31-
import { TelemetryService } from './api/telemetry-service';
32-
import { K8sTelemetryServiceImpl } from './impl/k8s-telemetry-service-impl';
33-
import * as axios from 'axios';
34-
import { Logger } from './logger';
21+
import type { Api } from './api/api';
22+
import type { DevfileService } from './api/devfile-service';
23+
import type { WorkspaceService } from './api/workspace-service';
24+
import type { GithubService } from './api/github-service';
25+
import type { TelemetryService } from './api/telemetry-service';
26+
27+
const NAVIGATOR_DIAG_PREFIX = '[che-api][navigator-diag]';
28+
const ENABLE_NAVIGATOR_DIAGNOSTICS = process.env.CHE_API_NAVIGATOR_DIAGNOSTICS !== 'false';
29+
30+
type DependencyProbe = {
31+
moduleName: string;
32+
resolverName: string;
33+
loader: () => Promise<unknown>;
34+
};
35+
36+
function safeResolveModule(moduleName: string): string {
37+
try {
38+
// eslint-disable-next-line no-restricted-globals
39+
return require.resolve(moduleName);
40+
} catch (error) {
41+
return `unresolved (${String(error)})`;
42+
}
43+
}
44+
45+
async function probeDependencyLoad(probe: DependencyProbe): Promise<void> {
46+
const resolvedPath = safeResolveModule(probe.resolverName);
47+
const start = Date.now();
48+
console.info(`${NAVIGATOR_DIAG_PREFIX} START loading '${probe.moduleName}' (resolved: ${resolvedPath})`);
49+
try {
50+
await probe.loader();
51+
console.info(`${NAVIGATOR_DIAG_PREFIX} DONE loading '${probe.moduleName}' in ${Date.now() - start}ms`);
52+
} catch (error) {
53+
console.error(`${NAVIGATOR_DIAG_PREFIX} FAILED loading '${probe.moduleName}' in ${Date.now() - start}ms`, error);
54+
}
55+
}
56+
57+
async function runNavigatorDependencyDiagnostics(): Promise<void> {
58+
if (!ENABLE_NAVIGATOR_DIAGNOSTICS) {
59+
return;
60+
}
61+
62+
console.info(`${NAVIGATOR_DIAG_PREFIX} diagnostics started`);
63+
const probes: DependencyProbe[] = [
64+
{
65+
moduleName: 'axios',
66+
resolverName: 'axios',
67+
loader: () => import('axios')
68+
},
69+
{
70+
moduleName: 'oauth4webapi',
71+
resolverName: 'oauth4webapi',
72+
loader: () => import('oauth4webapi')
73+
},
74+
{
75+
moduleName: 'openid-client',
76+
resolverName: 'openid-client',
77+
loader: () => import('openid-client')
78+
},
79+
{
80+
moduleName: '@kubernetes/client-node',
81+
resolverName: '@kubernetes/client-node',
82+
loader: () => import('@kubernetes/client-node')
83+
}
84+
];
85+
86+
for (const probe of probes) {
87+
// Sequential loading makes it easy to map PendingMigrationError to the module currently being loaded.
88+
await probeDependencyLoad(probe);
89+
}
90+
console.info(`${NAVIGATOR_DIAG_PREFIX} diagnostics completed`);
91+
}
3592

3693

3794
export async function activate(_extensionContext: vscode.ExtensionContext): Promise<Api> {
95+
await runNavigatorDependencyDiagnostics();
96+
97+
const [
98+
axiosModule,
99+
{ DevfileService },
100+
{ K8SService },
101+
{ K8sDevfileServiceImpl },
102+
{ K8SServiceImpl },
103+
{ K8sDevWorkspaceEnvVariables },
104+
{ WorkspaceService },
105+
{ K8sWorkspaceServiceImpl },
106+
{ GithubService },
107+
{ GithubServiceImpl },
108+
{ TelemetryService },
109+
{ K8sTelemetryServiceImpl },
110+
{ Logger }
111+
] = await Promise.all([
112+
import('axios'),
113+
import('./api/devfile-service'),
114+
import('./api/k8s-service'),
115+
import('./impl/k8s-devfile-service-impl'),
116+
import('./impl/k8s-service-impl'),
117+
import('./impl/k8s-devworkspace-env-variables'),
118+
import('./api/workspace-service'),
119+
import('./impl/k8s-workspace-service-impl'),
120+
import('./api/github-service'),
121+
import('./impl/github-service-impl'),
122+
import('./api/telemetry-service'),
123+
import('./impl/k8s-telemetry-service-impl'),
124+
import('./logger')
125+
]);
38126

39127
const container = new Container();
40128
container.bind(K8sDevfileServiceImpl).toSelf().inSingletonScope();
@@ -43,7 +131,7 @@ export async function activate(_extensionContext: vscode.ExtensionContext): Prom
43131
container.bind(K8SServiceImpl).toSelf().inSingletonScope();
44132
container.bind(K8SService).to(K8SServiceImpl).inSingletonScope();
45133
container.bind(K8sDevWorkspaceEnvVariables).toSelf().inSingletonScope();
46-
container.bind(Symbol.for('AxiosInstance')).toConstantValue(axios);
134+
container.bind(Symbol.for('AxiosInstance')).toConstantValue(axiosModule);
47135
container.bind(GithubServiceImpl).toSelf().inSingletonScope();
48136
container.bind(GithubService).to(GithubServiceImpl).inSingletonScope();
49137
container.bind(TelemetryService).to(K8sTelemetryServiceImpl).inSingletonScope();

0 commit comments

Comments
 (0)