Skip to content
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

Send telemetry events to telemetry plugin #115

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions code/build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const extensionsPath = path.join(path.dirname(__dirname), 'extensions');
// });
const compilations = [
'authentication-proxy/tsconfig.json',
'che-activity-tracker/tsconfig.json',
'che-api/tsconfig.json',
'che-commands/tsconfig.json',
'che-port/tsconfig.json',
'che-on-start/tsconfig.json',
'che-remote/tsconfig.json',
'che-resource-monitor/tsconfig.json',
'che-terminal/tsconfig.json',
'che-telemetry/tsconfig.json',
'che-github-authentication/tsconfig.json',
'configuration-editing/build/tsconfig.json',
'configuration-editing/tsconfig.json',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions code/extensions/che-activity-tracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
},
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
"compile": "gulp compile-extension:che-activity-tracker",
"watch": "gulp watch-extension:che-activity-tracker",
"vscode:prepublish": "npm run compile",
"test": "jest",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/**/*.{ts,tsx}\""
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

export type WorkspaceService = { updateWorkspaceActivity: () => any };

/**
* Receives activity updates and sends reset inactivity requests to the che-machine-exec /activity/tick endpoint.
* To avoid duplicate requests may send requests periodically. This means
Expand All @@ -27,9 +29,9 @@ export class ActivityTrackerService {
// Flag which is used to check if new requests were received during timer awaiting.
private isNewRequest: boolean;

private workspaceService: any;
private workspaceService: WorkspaceService;

constructor(workspaceService: any) {
constructor(workspaceService: WorkspaceService) {
this.isTimerRunning = false;
this.isNewRequest = false;
this.workspaceService = workspaceService;
Expand Down
4 changes: 2 additions & 2 deletions code/extensions/che-activity-tracker/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
***********************************************************************/

import * as vscode from "vscode";
import { ActivityTrackerService } from "./activity-tracker-service";
import { ActivityTrackerService, WorkspaceService } from "./activity-tracker-service";

export async function activate(context: vscode.ExtensionContext) {

Expand Down Expand Up @@ -38,7 +38,7 @@ async function track(events: vscode.Event<any>[], context: vscode.ExtensionConte
});
}

async function getWorkspaceService(): Promise<any> {
async function getWorkspaceService(): Promise<WorkspaceService> {
const CHE_API = 'eclipse-che.api';
const extensionApi = vscode.extensions.getExtension(CHE_API);
if (!extensionApi) {
Expand Down
3 changes: 2 additions & 1 deletion code/extensions/che-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"inversify": "^6.0.1",
"js-yaml": "^4.1.0",
"reflect-metadata": "^0.1.13",
"vscode-nls": "^5.0.0"
"vscode-nls": "^5.0.0",
"@eclipse-che/workspace-telemetry-client": "latest"
azatsarynnyy marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down
2 changes: 2 additions & 0 deletions code/extensions/che-api/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import { DevfileService } from './devfile-service';
import { WorkspaceService } from './workspace-service';
import { GithubService } from './github-service';
import { TelemetryService } from './telemetry-service';

export interface Api {
getDevfileService(): DevfileService;
getWorkspaceService(): WorkspaceService;
getGithubService(): GithubService;
getTelemetryService(): TelemetryService;
}
23 changes: 23 additions & 0 deletions code/extensions/che-api/src/api/telemetry-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**********************************************************************
* Copyright (c) 2022 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

export const TelemetryService = Symbol("TelemetryService");

export interface TelemetryService {
submitTelemetryEvent(
id: string,
ownerId: string,
ip: string,
agent: string,
resolution: string,
properties: [string, string][]
): Promise<void>;
submitTelemetryActivity(): Promise<void>;
}
9 changes: 8 additions & 1 deletion code/extensions/che-api/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { WorkspaceService } from './api/workspace-service';
import { K8sWorkspaceServiceImpl } from './impl/k8s-workspace-service-impl';
import { GithubService } from './api/github-service';
import { GithubServiceImpl } from './impl/github-service-impl';
import { TelemetryService } from './api/telemetry-service';
import { K8sTelemetryServiceImpl } from './impl/k8s-telemetry-service-impl';
import * as axios from 'axios';


Expand All @@ -39,10 +41,12 @@ export async function activate(_extensionContext: vscode.ExtensionContext): Prom
container.bind(Symbol.for('AxiosInstance')).toConstantValue(axios);
container.bind(GithubServiceImpl).toSelf().inSingletonScope();
container.bind(GithubService).to(GithubServiceImpl).inSingletonScope();
container.bind(TelemetryService).to(K8sTelemetryServiceImpl).inSingletonScope();

const devfileService = container.get(DevfileService) as DevfileService;
const workspaceService = container.get(WorkspaceService) as WorkspaceService;
const githubService = container.get(GithubService) as GithubService;
const telemetryService = container.get(TelemetryService) as TelemetryService;
const api: Api = {
getDevfileService(): DevfileService {
return devfileService;
Expand All @@ -52,7 +56,10 @@ export async function activate(_extensionContext: vscode.ExtensionContext): Prom
},
getGithubService(): GithubService {
return githubService;
}
},
getTelemetryService(): TelemetryService {
return telemetryService;
},
};

return api;
Expand Down
70 changes: 70 additions & 0 deletions code/extensions/che-api/src/impl/k8s-telemetry-service-impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import {
EventProperty,
TelemetryClient,
} from "@eclipse-che/workspace-telemetry-client";

import { TelemetryService } from "../api/telemetry-service";
import { injectable } from "inversify";

@injectable()
export class K8sTelemetryServiceImpl implements TelemetryService {
private readonly telemetryClient: TelemetryClient | undefined;

constructor() {
if (process.env.DEVWORKSPACE_TELEMETRY_BACKEND_PORT === undefined) {
console.error(
'Unable to create telemetry client: "DEVWORKSPACE_TELEMETRY_BACKEND_PORT" is not set.'
);
} else {
this.telemetryClient = new TelemetryClient(
undefined,
"http://localhost:" + process.env.DEVWORKSPACE_TELEMETRY_BACKEND_PORT
);
}
}

async submitTelemetryEvent(
id: string,
ownerId: string,
ip: string,
agent: string,
resolution: string,
properties: [string, string][]
): Promise<void> {
if (!this.telemetryClient) {
return;
}

await this.telemetryClient.event({
id: id,
ip: ip,
ownerId: ownerId,
agent: agent,
resolution: resolution,
properties: properties.map((prop: [string, string]) => {
const eventProp: EventProperty = {
id: prop[0],
value: prop[1],
};
return eventProp;
}),
});
}

async submitTelemetryActivity(): Promise<void> {
if (!this.telemetryClient) {
return;
}
await this.telemetryClient.activity();
}
}
25 changes: 25 additions & 0 deletions code/extensions/che-api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@
request "^2.81.0"
rewire "^3.0.2"

"@eclipse-che/api@^7.38.1":
version "7.54.0"
resolved "https://registry.yarnpkg.com/@eclipse-che/api/-/api-7.54.0.tgz#10305df3fca96e4149a6e9d99b107f89f916d1ec"
integrity sha512-/7zO0IVmtMsaoEY6jybejDT3fq68t+Y4pSkDGG3+nJIK1qcT89yUyKMQGUIP4xjIZBZQvCddijscPlhJWXwndg==

"@eclipse-che/workspace-telemetry-client@latest":
version "0.0.1-1654006444"
resolved "https://registry.yarnpkg.com/@eclipse-che/workspace-telemetry-client/-/workspace-telemetry-client-0.0.1-1654006444.tgz#62a4a03573061a3452266392510729843e89d0b9"
integrity sha512-WQ+zh54t/Kt83Ex9eH05w/4hmhkXAgXC6wauXt92JHhrPbox9E1CWgDVdP/T9FHdCST42qcbPEnXK3zpdgkSBg==
dependencies:
"@eclipse-che/api" "^7.38.1"
axios "^0.24.0"

"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
Expand Down Expand Up @@ -898,6 +911,13 @@ [email protected]:
dependencies:
follow-redirects "^1.14.0"

axios@^0.24.0:
version "0.24.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.24.0.tgz#804e6fa1e4b9c5288501dd9dff56a7a0940d20d6"
integrity sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==
dependencies:
follow-redirects "^1.14.4"

babel-code-frame@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
Expand Down Expand Up @@ -1633,6 +1653,11 @@ follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==

follow-redirects@^1.14.4:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
Expand Down
7 changes: 7 additions & 0 deletions code/extensions/che-telemetry/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build/**
tests/**
coverage/**
out/**
tsconfig.json
extension.webpack.config.js
yarn.lock
13 changes: 13 additions & 0 deletions code/extensions/che-telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Eclipse Che Telemetry Extension for Visual Studio Code

**Notice:** This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.

## Features
This extension detects and sends the following events to a backend telemetry plugin listening on `http://localhost:${DEVWORKSPACE_TELEMETRY_BACKEND_PORT}`.

This extension will activate on Che Code startup.

| Event ID | Description |
|------------------|------------------------------------------------------------|
| WORKSPACE_OPENED | Sent when the telemetry extension activates |
| EDITOR_USED | Sent on the vscode.workspace.onDidChangeTextDocument event |
11 changes: 11 additions & 0 deletions code/extensions/che-telemetry/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**********************************************************************
dkwon17 marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2022 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

export type EventId = "WORKSPACE_OPENED" | "EDITOR_USED";
60 changes: 60 additions & 0 deletions code/extensions/che-telemetry/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**********************************************************************
dkwon17 marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2022 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/
import * as vscode from 'vscode';
import { TelemetryEventService } from "./telemetry-event-service";

let telemetryEventService: TelemetryEventService;

export async function activate(context: vscode.ExtensionContext) {
const telemetryService = await getTelemetryService();
telemetryEventService = new TelemetryEventService(telemetryService);

telemetryEventService.sendEvent(
"WORKSPACE_OPENED",
context.extensionPath,
[]
);

context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(
(e: vscode.TextDocumentChangeEvent) => {
if (e.document.uri.scheme !== "output") {
telemetryEventService.sendEvent(
"EDITOR_USED",
context.extensionPath,
[["programming language", e.document.languageId]]
);
}
}
)
);
}

async function getTelemetryService(): Promise<any> {
const CHE_API = "eclipse-che.api";
const extensionApi = vscode.extensions.getExtension(CHE_API);
if (!extensionApi) {
throw Error(
`Failed to get workspace service. Extension ${CHE_API} is not installed.`
);
}

try {
await extensionApi.activate();
const cheApi: any = extensionApi?.exports;
return cheApi.getTelemetryService();
} catch {
throw Error(
`Failed to get telemetry service. Could not activate and retrieve exports from extension ${CHE_API}.`
);
}
}

export function deactivate() {}
Loading