From 8df35813c5f70b3f0b2839a9b22ea61d0563fad4 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Wed, 16 Jun 2021 15:08:03 +0530 Subject: [PATCH] Additional telemetry (#597) * Additional telemetry --- USAGE_DATA.md | 29 +++++++++++++++++++++++++++++ src/cli-command.ts | 8 ++++++++ src/cluster-version.ts | 37 +++++++++++++++++++++++++++++++++++++ src/extension.ts | 10 ++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/cluster-version.ts diff --git a/USAGE_DATA.md b/USAGE_DATA.md index b05f5964..42b8c72e 100644 --- a/USAGE_DATA.md +++ b/USAGE_DATA.md @@ -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. + diff --git a/src/cli-command.ts b/src/cli-command.ts index a87eb0f3..91c14aba 100644 --- a/src/cli-command.ts +++ b/src/cli-command.ts @@ -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; @@ -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'); } diff --git a/src/cluster-version.ts b/src/cluster-version.ts new file mode 100644 index 00000000..0ad2b6f2 --- /dev/null +++ b/src/cluster-version.ts @@ -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 { + 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; +} diff --git a/src/extension.ts b/src/extension.ts index ad07c636..8acfc7c7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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; @@ -127,6 +128,15 @@ export async function activate(context: vscode.ExtensionContext): Promise 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);