Skip to content

Commit

Permalink
Additional telemetry (#597)
Browse files Browse the repository at this point in the history
* Additional telemetry
  • Loading branch information
sudhirverma committed Jun 16, 2021
1 parent ca930ff commit 8df3581
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
29 changes: 29 additions & 0 deletions USAGE_DATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,32 @@
* command's error message (in case of exception)
* command's specific data like tkn, kubectl version and to check which command user has used.
* when extension is deactivated
* Watch on all tekton resources.
* Command which send data to telemetry.
* About command.
* Open Pipeline preview to the side command.
* Show output channel command.
* Refresh command.
* Start pipeline from k8s command.
* Start task from k8s command.
* Start pipeline command.
* Add trigger command.
* Start pipeline from command palette.
* OpenInEditor command.
* Start last pipeline run command.
* Delete command.
* Restart pipelineRun command.
* Show diagnostic data command.
* Restart taskRun command.
* Copy expose url command.
* start task command.
* start task command from palette.
* Report issue command.
* Refresh view command.
* Remove selected command.
* Open condition definition command.
* Open task definition command.
* Generate TaskRun template command.
* Tekton hub.
* Collect OpenShift and kubernetes cluster version.

8 changes: 8 additions & 0 deletions src/cli-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function newK8sCommand(...k8sArguments: string[]): CliCommand {
return createCliCommand('kubectl', ...k8sArguments);
}

export function newOcCommand(...OcArguments: string[]): CliCommand {
return createCliCommand('oc', ...OcArguments);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verbose(_target: unknown, key: string, descriptor: any): void {
let fnKey: string | undefined;
Expand Down Expand Up @@ -44,6 +48,10 @@ export class Command {
return newK8sCommand('get', 'taskrun', '-l', `tekton.dev/task=${task}`, '-o', 'json');
}

static printOcVersionJson(): CliCommand {
return newOcCommand('version -ojson');
}

static listTaskRunsForClusterTasks(clusterTask: string): CliCommand {
return newK8sCommand('get', 'taskrun', '-l', `tekton.dev/clusterTask=${clusterTask}`, '-o', 'json');
}
Expand Down
37 changes: 37 additions & 0 deletions src/cluster-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
/* eslint-disable @typescript-eslint/camelcase */


import { cli } from './cli';
import { Command } from './cli-command';

interface Versions {
openshift_Version: string;
kubernetes_Version: string;
}

export async function getClusterVersions(): Promise<Versions> {
const result = await cli.execute(Command.printOcVersionJson());
const versions: Versions = {
kubernetes_Version: undefined,
openshift_Version: undefined
};
if (!result.error) {
try {
const versionsJson = JSON.parse(result.stdout);
if (versionsJson?.serverVersion?.major && versionsJson?.serverVersion?.minor) {
versions.kubernetes_Version = `${versionsJson.serverVersion.major}.${versionsJson.serverVersion.minor}`;
}
if (versionsJson?.openshiftVersion) {
versions.openshift_Version = versionsJson.openshiftVersion;
}

} catch (err) {
// ignore and return undefined
}
}
return versions;
}
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { getVersion, tektonVersionType } from './util/tknversion';
import { TektonNode } from './tree-view/tekton-node';
import { checkClusterStatus } from './util/check-cluster-status';
import { getRedHatService } from '@redhat-developer/vscode-redhat-telemetry';
import { getClusterVersions } from './cluster-version';

export let contextGlobalState: vscode.ExtensionContext;
let k8sExplorer: k8s.ClusterExplorerV1 | undefined = undefined;
Expand Down Expand Up @@ -127,6 +128,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
triggerDetection();
});
checkClusterStatus(true); // watch Tekton resources when all required dependency are installed
getClusterVersions().then((version) => {
const telemetryProps: TelemetryProperties = {
identifier: 'cluster.version',
};
for (const [key, value] of Object.entries(version)) {
telemetryProps[key] = value;
}
sendTelemetry('tekton.cluster.version', telemetryProps)
})
setCommandContext(CommandContext.TreeZenMode, false);
setCommandContext(CommandContext.PipelinePreview, false);

Expand Down

0 comments on commit 8df3581

Please sign in to comment.