Skip to content

Fixes and edits to telemetry code to support JdkFeatureEvent #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
45 changes: 27 additions & 18 deletions patches/nb-telemetry.diff
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ index d82646afb1..3d507b5fe3 100644
import org.openide.util.Lookup;

/**
@@ -55,130 +58,164 @@ import org.openide.util.Lookup;
@@ -55,130 +58,171 @@ import org.openide.util.Lookup;
*/
public class LspServerTelemetryManager {

Expand All @@ -63,7 +63,7 @@ index d82646afb1..3d507b5fe3 100644
- public synchronized void connect(LanguageClient client, Future<Void> future) {
- clients.put(client, future);
- lspServerIntiailizationTime = System.currentTimeMillis();
+ private static enum ProjectType {
+ public static enum ProjectType {
+ standalone,
+ maven,
+ gradle;
Expand Down Expand Up @@ -188,12 +188,12 @@ index d82646afb1..3d507b5fe3 100644
-
- // In future if different JDK is used for different project then this can be updated
- obj.addProperty("javaVersion", System.getProperty("java.version"));
-
- if (mp.containsKey(prjPath)) {
- Project prj = mp.get(prjPath);
+ String javaVersion = getProjectJavaVersion();
+ obj.addProperty("javaVersion", javaVersion);


- if (mp.containsKey(prjPath)) {
- Project prj = mp.get(prjPath);
-
- ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
- String projectType = r.getProjectType();
- obj.addProperty("buildTool", (projectType.contains("maven") ? "MavenProject" : "GradleProject"));
Expand All @@ -220,7 +220,7 @@ index d82646afb1..3d507b5fe3 100644
+ obj.addProperty("isOpenedWithProblems", ProjectProblems.isBroken(prj));
}
+ obj.addProperty("buildTool", projectType.name());
+ boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType);
+ boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client);
+ obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);

prjProps.add(obj);
Expand All @@ -236,26 +236,35 @@ index d82646afb1..3d507b5fe3 100644

- properties.add("prjsInfo", prjProps);
+ properties.add("projectInfo", prjProps);

- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
+
+ properties.addProperty("projInitTimeTaken", timeToOpenProjects);
+ properties.addProperty("numProjects", workspaceClientFolders.size());
+ properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);

- this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
+ this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
+ }

- this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
+ public boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
+ return isPreviewEnabled(source, prjType, null);
}
-
- private boolean isEnablePreivew(FileObject source, String prjType) {
- if (prjType.equals(this.STANDALONE_PRJ)) {
- NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+
+ private boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
+ public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
+ if (prjType == ProjectType.standalone) {
NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null ;
if (client == null) {
return false;
- return false;
+ client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client == null) {
+ return false;
+ }
}
- AtomicBoolean isEnablePreviewSet = new AtomicBoolean(false);
+ boolean[] isEnablePreviewSet = {false};
Expand Down Expand Up @@ -283,7 +292,7 @@ index d82646afb1..3d507b5fe3 100644
}

private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
@@ -187,15 +224,50 @@ public class LspServerTelemetryManager {
@@ -187,15 +231,50 @@ public class LspServerTelemetryManager {

BigInteger number = new BigInteger(1, hash);

Expand Down Expand Up @@ -331,7 +340,7 @@ index d82646afb1..3d507b5fe3 100644
+ return propertyLookup.apply("java.vm.name");
+ }
+
+ private ProjectType getProjectType(Project prj) {
+ public ProjectType getProjectType(Project prj) {
+ ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
+ String projectType = r == null ? null : r.getProjectType();
+ return projectType != null && projectType.contains(ProjectType.maven.name()) ? ProjectType.maven : ProjectType.gradle;
Expand All @@ -358,7 +367,7 @@ index 9134992f5f..f070fec320 100644
}

+ public boolean wantsTelemetryEnabled() {
+ return wantsTelemetryEnabled;
+ return wantsTelemetryEnabled == Boolean.TRUE;
+ }
+
private NbCodeClientCapabilities withCapabilities(ClientCapabilities caps) {
Expand Down
31 changes: 22 additions & 9 deletions vscode/src/lsp/listeners/notifications/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { LOGGER } from '../../../logger';
import { globalState } from "../../../globalState";
import { WorkspaceChangeData, WorkspaceChangeEvent } from "../../../telemetry/events/workspaceChange";
import { Telemetry } from "../../../telemetry/telemetry";
import { JdkFeatureEvent, JdkFeatureEventData } from "../../../telemetry/events/jdkFeature";

const checkInstallNbJavac = (msg: string) => {
const NO_JAVA_SUPPORT = "Cannot initialize Java support";
Expand All @@ -44,8 +45,8 @@ const checkInstallNbJavac = (msg: string) => {
}
}

const showStatusBarMessageHandler = (params : ShowStatusMessageParams) => {
let decorated : string = params.message;
const showStatusBarMessageHandler = (params: ShowStatusMessageParams) => {
let decorated: string = params.message;
let defTimeout;

switch (params.type) {
Expand Down Expand Up @@ -100,7 +101,7 @@ const textEditorDecorationDisposeHandler = (param: any) => {
if (decorationType) {
globalState.removeDecoration(param);
decorationType.dispose();

globalState.getDecorationParamsByUri().forEach((value, key) => {
if (value.key == param) {
globalState.removeDecorationParams(key);
Expand All @@ -111,8 +112,8 @@ const textEditorDecorationDisposeHandler = (param: any) => {


const telemetryEventHandler = (param: any) => {
if(WorkspaceChangeEvent.NAME === param?.name){
const {projectInfo, numProjects, lspInitTimeTaken, projInitTimeTaken} = param?.properties;
if (WorkspaceChangeEvent.NAME === param?.name) {
const { projectInfo, numProjects, lspInitTimeTaken, projInitTimeTaken } = param?.properties;
const eventData: WorkspaceChangeData = {
projectInfo,
numProjects,
Expand All @@ -123,6 +124,18 @@ const telemetryEventHandler = (param: any) => {
Telemetry.sendTelemetry(workspaceChangeEvent);
return;
}
if (JdkFeatureEvent.NAME === param?.name) {
const { javaVersion, names, jeps, isPreviewEnabled } = param?.properties;
const eventData: JdkFeatureEventData = {
jeps,
names,
javaVersion,
isPreviewEnabled
};
const jdkFeatureEvent: JdkFeatureEvent = new JdkFeatureEvent(eventData);
Telemetry.sendTelemetry(jdkFeatureEvent);
return;
}
const ls = globalState.getListener(param);
if (ls) {
for (const listener of ls) {
Expand All @@ -131,7 +144,7 @@ const telemetryEventHandler = (param: any) => {
}
}

export const notificationListeners : notificationOrRequestListenerType[] = [{
export const notificationListeners: notificationOrRequestListenerType[] = [{
type: StatusMessageRequest.type,
handler: showStatusBarMessageHandler
}, {
Expand All @@ -140,13 +153,13 @@ export const notificationListeners : notificationOrRequestListenerType[] = [{
}, {
type: TestProgressNotification.type,
handler: testProgressHandler
},{
}, {
type: TextEditorDecorationSetNotification.type,
handler: textEditorSetDecorationHandler
},{
}, {
type: TextEditorDecorationDisposeNotification.type,
handler: textEditorDecorationDisposeHandler
},{
}, {
type: TelemetryEventNotification.type,
handler: telemetryEventHandler
}];
4 changes: 2 additions & 2 deletions vscode/src/telemetry/events/jdkFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class JdkFeatureEvent extends BaseEvent<JdkFeatureEventData> {
const names: string[] = [];

events.forEach(event => {
jeps.push(...event.getPayload.jeps);
names.push(...event.getPayload.names);
if (event.getPayload.jeps) jeps.push(...event.getPayload.jeps);
if (event.getPayload.names) names.push(...event.getPayload.names);
});

return new JdkFeatureEvent({
Expand Down
Loading