-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Kwon <[email protected]>
- Loading branch information
Showing
21 changed files
with
3,157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
code/extensions/che-api/src/impl/k8s-telemetry-service-impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/********************************************************************** | ||
* 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/********************************************************************** | ||
* 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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/********************************************************************** | ||
* 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 | ||
***********************************************************************/ | ||
|
||
/* eslint-disable header/header */ | ||
|
||
//@ts-check | ||
|
||
"use strict"; | ||
|
||
const withDefaults = require("../shared.webpack.config"); | ||
const webpack = require("webpack"); | ||
|
||
module.exports = withDefaults({ | ||
context: __dirname, | ||
resolve: { | ||
mainFields: ["module", "main"], | ||
}, | ||
entry: { | ||
extension: "./src/extension.ts", | ||
}, | ||
plugins: [ | ||
new webpack.ContextReplacementPlugin(/keyv/), // needs to exclude the package to ignore warnings https://github.com/jaredwray/keyv/issues/45 | ||
], | ||
externals: { | ||
bufferutil: "commonjs bufferutil", // ignored | ||
"utf-8-validate": "commonjs utf-8-validate", // ignored | ||
}, | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "telemetry", | ||
"displayName": "%displayName%", | ||
"description": "%description%", | ||
"publisher": "eclipse-che", | ||
"license": "EPL-2.0", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.63.0" | ||
}, | ||
"icon": "images/icon.png", | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"capabilities": { | ||
"virtualWorkspaces": true, | ||
"untrustedWorkspaces": { | ||
"supported": true | ||
} | ||
}, | ||
"main": "./out/extension.js", | ||
"scripts": { | ||
"compile": "gulp compile-extension:che-telemetry", | ||
"watch": "gulp watch-extension:che-telemetry", | ||
"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", | ||
"@types/jest": "^27.4.1", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/node": "14.x", | ||
"add": "^2.0.6", | ||
"jest": "27.3.1", | ||
"ts-jest": "^27.1.4", | ||
"yarn": "^1.22.18" | ||
}, | ||
"dependencies": { | ||
"axios": "0.21.2", | ||
"inversify": "^6.0.1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/che-incubator/che-code.git" | ||
}, | ||
"extensionDependencies": [ | ||
"eclipse-che.api" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"displayName": "Eclipse Che Telemetry Extension", | ||
"description": "Eclipse Che Telemetry Extension" | ||
} |
Oops, something went wrong.