Skip to content

Commit 8a67062

Browse files
authored
Add metrics and move init params (#191)
1 parent 6cb3868 commit 8a67062

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

src/context/Context.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { SyntaxNode } from 'tree-sitter';
22
import { DocumentType } from '../document/Document';
3+
import { ScopedTelemetry } from '../telemetry/ScopedTelemetry';
4+
import { Telemetry } from '../telemetry/TelemetryDecorator';
35
import { removeQuotes } from '../utils/String';
46
import {
57
IntrinsicsSet,
@@ -23,6 +25,9 @@ import { TransformContext } from './TransformContext';
2325
type QuoteCharacter = '"' | "'";
2426

2527
export class Context {
28+
@Telemetry()
29+
protected readonly telemetry!: ScopedTelemetry;
30+
2631
public readonly section: SectionType;
2732
public readonly isTopLevel: boolean;
2833
public readonly logicalId?: string;
@@ -61,7 +66,9 @@ export class Context {
6166
}
6267

6368
public get entity(): Entity {
64-
this._entity ??= nodeToEntity(this.documentType, this.entityRootNode, this.section, this.logicalId);
69+
this._entity ??= this.telemetry.measure('create.entity', () =>
70+
nodeToEntity(this.documentType, this.entityRootNode, this.section, this.logicalId),
71+
);
6572
return this._entity;
6673
}
6774

@@ -70,17 +77,21 @@ export class Context {
7077
}
7178

7279
public get intrinsicContext(): IntrinsicContext {
73-
this._intrinsicContext ??= new IntrinsicContext(this.pathToRoot, this.documentType);
80+
this._intrinsicContext ??= this.telemetry.measure(
81+
'create.intrinsicContext',
82+
() => new IntrinsicContext(this.pathToRoot, this.documentType),
83+
);
7484
return this._intrinsicContext;
7585
}
7686

7787
public get transformContext(): TransformContext {
78-
// Find root node by traversing up from current node
79-
let rootNode = this.node;
80-
while (rootNode.parent) {
81-
rootNode = rootNode.parent;
82-
}
83-
this._transformContext ??= new TransformContext(rootNode, this.documentType);
88+
this._transformContext ??= this.telemetry.measure('create.transformContext', () => {
89+
let rootNode = this.node;
90+
while (rootNode.parent) {
91+
rootNode = rootNode.parent;
92+
}
93+
return new TransformContext(rootNode, this.documentType);
94+
});
8495
return this._transformContext;
8596
}
8697

src/context/ContextWithRelatedEntities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export class ContextWithRelatedEntities extends Context {
2525
}
2626

2727
public get relatedEntities(): Map<SectionType, Map<string, Context>> {
28-
this._relatedEntities ??= this.relatedEntitiesProvider();
28+
this._relatedEntities ??= this.telemetry.measure('create.relatedEntities', () =>
29+
this.relatedEntitiesProvider(),
30+
);
2931
return this._relatedEntities;
3032
}
3133

src/server/CfnInfraCore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class CfnInfraCore implements Configurables, Closeable {
5959
new AwsCredentials(
6060
lspComponents.authHandlers,
6161
this.settingsManager,
62-
initializeParams.initializationOptions?.encryption?.key,
62+
initializeParams.initializationOptions?.aws?.encryption?.key,
6363
);
6464

6565
this.diagnosticCoordinator =

src/server/InitParams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export type AwsMetadata = {
1717
cloudformation?: {
1818
endpoint?: string;
1919
};
20+
encryption?: {
21+
key: string;
22+
mode: string;
23+
};
2024
};
2125

2226
export interface ExtendedInitializeParams extends InitializeParams {
2327
initializationOptions?: {
2428
aws?: AwsMetadata;
25-
encryption?: {
26-
key: string;
27-
mode: string;
28-
};
2929
[key: string]: unknown;
3030
};
3131
}

tst/utils/TestExtension.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
CodeLensParams,
4545
CodeLensRequest,
4646
} from 'vscode-languageserver';
47-
import { InitializeParams, createConnection } from 'vscode-languageserver/node';
47+
import { createConnection } from 'vscode-languageserver/node';
4848
import { IamCredentialsUpdateRequest, IamCredentialsDeleteNotification } from '../../src/auth/AuthProtocol';
4949
import { UpdateCredentialsParams } from '../../src/auth/AwsLspAuthTypes';
5050
import { MultiDataStoreFactoryProvider } from '../../src/datastore/DataStore';
@@ -58,6 +58,7 @@ import { CfnExternal } from '../../src/server/CfnExternal';
5858
import { CfnInfraCore } from '../../src/server/CfnInfraCore';
5959
import { CfnLspProviders } from '../../src/server/CfnLspProviders';
6060
import { CfnServer } from '../../src/server/CfnServer';
61+
import { AwsMetadata, ExtendedInitializeParams } from '../../src/server/InitParams';
6162
import { RelationshipSchemaService } from '../../src/services/RelationshipSchemaService';
6263
import { LoggerFactory } from '../../src/telemetry/LoggerFactory';
6364
import { Closeable } from '../../src/utils/Closeable';
@@ -66,7 +67,19 @@ import { createMockCfnLintService, createMockGuardService, mockCfnAi } from './M
6667
import { getTestPrivateSchemas } from './SchemaUtils';
6768
import { wait } from './Utils';
6869

69-
const clientInfo = { name: `Test ${ExtensionName}`, version: '1.0.0-test' };
70+
const awsMetadata: AwsMetadata = {
71+
clientInfo: {
72+
extension: {
73+
name: `Test ${ExtensionName}`,
74+
version: '1.0.0-test',
75+
},
76+
clientId: '1111-1111-1111-1111',
77+
},
78+
encryption: {
79+
key: randomBytes(32).toString('base64'),
80+
mode: 'JWT',
81+
},
82+
};
7083

7184
export class TestExtension implements Closeable {
7285
private readonly readStream = new PassThrough();
@@ -85,32 +98,23 @@ export class TestExtension implements Closeable {
8598
private isReady = false;
8699

87100
constructor(
88-
private readonly initializeParams = {
101+
private readonly initializeParams: ExtendedInitializeParams = {
89102
processId: process.pid,
90103
rootUri: null,
91104
capabilities: {},
92-
clientInfo,
105+
clientInfo: awsMetadata.clientInfo?.extension,
93106
workspaceFolders: [],
94107
initializationOptions: {
95-
encryption: {
96-
key: randomBytes(32).toString('base64'),
97-
},
108+
aws: awsMetadata,
98109
},
99-
} as InitializeParams,
110+
},
100111
) {
101112
this.serverConnection = new LspConnection(
102113
createConnection(new StreamMessageReader(this.readStream), new StreamMessageWriter(this.writeStream)),
103114
{
104115
onInitialize: (params) => {
105116
const lsp = this.serverConnection.components;
106-
LoggerFactory.initialize({
107-
clientInfo: {
108-
extension: clientInfo,
109-
clientId: '1111-1111-1111-1111',
110-
},
111-
telemetryEnabled: true,
112-
logLevel: 'info',
113-
});
117+
LoggerFactory.initialize(awsMetadata);
114118

115119
const dataStoreFactory = new MultiDataStoreFactoryProvider();
116120
this.core = new CfnInfraCore(lsp, params, {

0 commit comments

Comments
 (0)