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

Collect cluster information for telemetry. #543

Merged
merged 3 commits into from
Apr 5, 2021
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
6 changes: 3 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { commands } from 'vscode';
import { customTektonExplorer } from './pipeline/customTektonExplorer';
import { telemetryLogCommand } from './telemetry';
import { telemetryLog } from './telemetry';

export enum VSCodeCommands {
SetContext = 'setContext',
Expand Down Expand Up @@ -36,11 +36,11 @@ export function exitZenMode(): void {
}

export function refreshCustomTree(commandId?: string): void {
telemetryLogCommand(commandId, 'Custom refresh command call');
telemetryLog(commandId, 'Custom refresh command call');
customTektonExplorer.refresh();
}

export function removeItemFromCustomTree(commandId?: string): void {
telemetryLogCommand(commandId, 'Custom remove command call');
telemetryLog(commandId, 'Custom remove command call');
customTektonExplorer.removeItem();
}
6 changes: 3 additions & 3 deletions src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TaskRun } from '../tekton/taskrun';
import { window } from 'vscode';
import { Progress } from '../util/progress';
import { ClusterTriggerBinding } from '../tekton/clustertriggerbunding';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { ContextType } from '../context-type';
import { TektonNode } from '../tree-view/tekton-node';
import { checkRefResource, referenceOfTaskAndClusterTaskInCluster } from '../util/check-ref-resource';
Expand Down Expand Up @@ -97,7 +97,7 @@ async function doDelete(items: TektonNode[], toRefresh: Refreshable, commandId?:
.then(() => toRefresh.refresh())
.then(() => {
const message = 'All items successfully deleted.';
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
return window.showInformationMessage(message);
})
.catch((err) => {
Expand All @@ -119,7 +119,7 @@ async function doDelete(items: TektonNode[], toRefresh: Refreshable, commandId?:
cli.execute(toDelete.values().next().value))
.then(() => toRefresh.refresh())
.then(() => {
telemetryLogCommand(commandId, 'Successfully deleted.');
telemetryLog(commandId, 'Successfully deleted.');
return window.showInformationMessage(`The '${name}' successfully deleted.`)
})
.catch((err) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/pipeline-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { previewManager, PreviewSettings } from './preview-manager';
import { CommandContext, setCommandContext } from '../commands';
import { calculatePipelineGraph, calculatePipelineRunGraph, askToSelectPipeline } from './pipeline-graph';
import { tektonFSUri, tektonVfsProvider } from '../util/tekton-vfs';
import { telemetryLogCommand } from '../telemetry';
import { telemetryLog } from '../telemetry';
import { ContextType } from '../context-type';

export async function showPipelinePreview(commandId?: string): Promise<void> {
const document = vscode.window.activeTextEditor?.document;
if (!document) {
return;
}
telemetryLogCommand(commandId, 'Pipeline preview command click')
telemetryLog(commandId, 'Pipeline preview command click')
const resourceColumn = (vscode.window.activeTextEditor && vscode.window.activeTextEditor.viewColumn) || vscode.ViewColumn.One;
const pipelines = tektonYaml.getTektonDocuments(document, TektonYamlType.Pipeline)
if (pipelines?.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/pipelineExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { TreeDataProvider, TreeView, Event, EventEmitter, TreeItem, ProviderResult, Disposable, window, extensions, commands, Uri, version } from 'vscode';
import { TektonNode } from '../tree-view/tekton-node';
import { telemetryLogCommand } from '../telemetry';
import { telemetryLog } from '../telemetry';
import { tkn } from '../tkn';
import { MoreNode } from '../tree-view/expand-node';
import { Platform } from '../util/platform';
Expand Down Expand Up @@ -79,7 +79,7 @@ export class PipelineExplorer implements TreeDataProvider<TektonNode>, Disposabl
for (const [key, value] of Object.entries(template)) {
body = `${body}${key} ${value}\n`;
}
telemetryLogCommand(commandId, 'Report issue command click');
telemetryLog(commandId, 'Report issue command click');
return commands.executeCommand(
'vscode.open',
Uri.parse(`${repoURL}/issues/new?labels=kind/bug&title=Issue&body=**Environment**\n${body}\n**Description**`));
Expand Down
6 changes: 3 additions & 3 deletions src/tekton/addtrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { cli } from '../cli';
import { TknVersion, version } from '../util/tknversion';
import { NewPvc } from './createpvc';
import { getExposeURl } from '../util/exposeurl';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { getStderrString } from '../util/stderrstring';
import { VCT } from './pipelinecontent';
import { Command } from '../cli-command';
Expand Down Expand Up @@ -107,12 +107,12 @@ export async function k8sCreate(trigger: TriggerTemplateKind | EventListenerKind
}
if (trigger.kind === RouteModel.kind && !result.error) {
const url = await getExposeURl(trigger.metadata.name);
telemetryLogCommand(commandId, 'Trigger successfully created');
telemetryLog(commandId, 'Trigger successfully created');
vscode.window.showInformationMessage(`Trigger successfully created. Expose URL: ${url}`);
}
if (kind === PipelineRunModel.kind && !result.error) {
const message = 'Pipeline successfully started';
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
vscode.window.showInformationMessage(message);
}
await fs.unlink(fsPath);
Expand Down
10 changes: 5 additions & 5 deletions src/tekton/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PipelineWizard } from '../pipeline/wizard';
import { pipelineData } from './webviewstartpipeline';
import { startPipeline } from './startpipeline';
import { triggerDetection } from '../util/detection';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { TektonNode } from '../tree-view/tekton-node';
import { Command } from '../cli-command';

Expand Down Expand Up @@ -65,7 +65,7 @@ export class Pipeline extends TektonItem {
Pipeline.tkn.restartPipeline(pipeline)
.then(() => Pipeline.explorer.refresh())
.then(() => {
telemetryLogCommand(commandId, 'successfully restarted');
telemetryLog(commandId, 'successfully restarted');
window.showInformationMessage(`Pipeline '${pipeline.getName()}' successfully created`);
})
.catch((error) => {
Expand All @@ -78,17 +78,17 @@ export class Pipeline extends TektonItem {
static refresh(commandId?: string): void {
triggerDetection();
Pipeline.explorer.refresh();
telemetryLogCommand(commandId, 'Refresh command click');
telemetryLog(commandId, 'Refresh command click');
}


static about(commandId?: string): void {
telemetryLogCommand(commandId, 'About command click');
telemetryLog(commandId, 'About command click');
Pipeline.tkn.executeInTerminal(Command.printTknVersion());
}

static async showTektonOutput(commandId?: string): Promise<void> {
telemetryLogCommand(commandId, 'Output channel click');
telemetryLog(commandId, 'Output channel click');
cli.showOutputChannel();
}

Expand Down
4 changes: 2 additions & 2 deletions src/tekton/startpipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Progress } from '../util/progress';
import { TektonItem } from './tektonitem';
import { showPipelineRunPreview } from '../pipeline/pipeline-preview';
import { window } from 'vscode';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';



Expand All @@ -17,7 +17,7 @@ export function startPipeline(inputStartPipeline: StartObject): Promise<string>
TektonItem.tkn.startPipeline(inputStartPipeline)
.then((pipelineRunName) => TektonItem.ShowPipelineRun() ? showPipelineRunPreview(pipelineRunName) : undefined)
.then(() => {
telemetryLogCommand(inputStartPipeline.commandId, 'Pipeline successfully started')
telemetryLog(inputStartPipeline.commandId, 'Pipeline successfully started')
window.showInformationMessage(`Pipeline '${inputStartPipeline.name}' successfully started`)
})
.catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tekton/starttask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as cliInstance from '../cli';
import { TektonItem } from './tektonitem';
import { TknPipelineTrigger } from '../tekton';
import { Trigger, PipelineContent } from './pipelinecontent';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { window } from 'vscode';
import { Command } from '../cli-command';

Expand Down Expand Up @@ -54,7 +54,7 @@ export async function startTask(taskName: string, commandId?: string): Promise<s
TektonItem.tkn.startTask(inputStartTask)
.then(() => TektonItem.explorer.refresh())
.then(() => {
telemetryLogCommand(commandId, 'Task successfully started');
telemetryLog(commandId, 'Task successfully started');
window.showInformationMessage(`Task '${inputStartTask.name}' successfully started`);
})
.catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tekton/taskrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { PipelineTaskRunData, TknTaskRun } from '../tekton';
import * as fs from 'fs-extra';
import * as yaml from 'js-yaml';
import { Platform } from '../util/platform';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { getStderrString } from '../util/stderrstring';
import { ContextType } from '../context-type';
import { TektonNode } from '../tree-view/tekton-node';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class TaskRun extends TektonItem {
return false;
} else {
const message = 'TaskRun successfully restarted';
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
window.showInformationMessage(message);
}
await fs.unlink(fsPath);
Expand Down
4 changes: 2 additions & 2 deletions src/tekton/taskruntemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as yaml from 'js-yaml';
import * as vscode from 'vscode';
import { Task, TaskRunTemplate } from '../tekton';
import { cli } from '../cli';
import { telemetryLogCommand } from '../telemetry';
import { telemetryLog } from '../telemetry';
import { newK8sCommand } from '../cli-command';
import { TektonNode } from '../tree-view/tekton-node';

Expand Down Expand Up @@ -85,7 +85,7 @@ export async function openTaskRunTemplate(context: TektonNode, commandId?: strin
serviceAccountName(taskRunTemplate);
taskRef(context.getName(), taskRunTemplate);
const taskRunYaml = yaml.dump(taskRunTemplate);
telemetryLogCommand(commandId, 'Open taskRun template');
telemetryLog(commandId, 'Open taskRun template');
vscode.workspace.openTextDocument({content: taskRunYaml, language: 'yaml'}).then(doc => {
vscode.window.showTextDocument(doc, {preview: false})
})
Expand Down
4 changes: 2 additions & 2 deletions src/tekton/tektonitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PipelineExplorer, pipelineExplorer } from '../pipeline/pipelineExplorer
import { workspace, window } from 'vscode';
import { tektonFSUri } from '../util/tekton-vfs';
import { TknResourceItem } from './webviewstartpipeline';
import { telemetryLogCommand, telemetryLogError } from '../telemetry';
import { telemetryLog, telemetryLogError } from '../telemetry';
import { ContextType } from '../context-type';
import { TektonNode } from '../tree-view/tekton-node';
import { Command } from '../cli-command';
Expand Down Expand Up @@ -118,7 +118,7 @@ export abstract class TektonItem {
const uri = tektonFSUri(type, name, outputFormat, uid);
workspace.openTextDocument(uri).then((doc) => {
if (doc) {
telemetryLogCommand(commandId, 'successfully open in editor');
telemetryLog(commandId, 'successfully open in editor');
window.showTextDocument(doc, { preserveFocus: true, preview: true });
}
}, (err) => {
Expand Down
10 changes: 5 additions & 5 deletions src/tekton/triggertemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TektonItem } from './tektonitem';
import { tkn } from '../tkn';
import { CliCommand } from '../cli';
import { getExposeURl } from '../util/exposeurl';
import { telemetryLogCommand } from '../telemetry';
import { telemetryLog } from '../telemetry';
import { TektonNode } from '../tree-view/tekton-node';
import { Command } from '../cli-command';

Expand All @@ -25,7 +25,7 @@ export class TriggerTemplate extends TektonItem {
const message = 'Expose URL not available';
const listEventListener = JSON.parse(result.stdout).items;
if (listEventListener.length === 0) {
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
vscode.window.showInformationMessage(message);
return null;
}
Expand All @@ -35,7 +35,7 @@ export class TriggerTemplate extends TektonItem {
if (triggers?.template?.name === trigger.getName()) {
const url = await getExposeURl(eventListener.status.configuration.generatedName);
vscode.env.clipboard.writeText(url);
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
vscode.window.showInformationMessage(message);
return;
} else if (triggers?.triggerRef) {
Expand All @@ -44,14 +44,14 @@ export class TriggerTemplate extends TektonItem {
if (triggerName === trigger.getName()) {
const url = await getExposeURl(eventListener.status.configuration.generatedName);
vscode.env.clipboard.writeText(url);
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
vscode.window.showInformationMessage(message);
return;
}
}
}
}
telemetryLogCommand(commandId, message);
telemetryLog(commandId, message);
vscode.window.showInformationMessage('Expose URl not available');
}
}
16 changes: 8 additions & 8 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export function telemetryProperties(commandId: string): TelemetryProperties {
}
}

export async function telemetryLogError(commandId: string, result: string | Error): Promise<void> {
if (commandId) {
const telemetryProps: TelemetryProperties = telemetryProperties(`${commandId}_error`);
export async function telemetryLogError(identifier: string, result: string | Error): Promise<void> {
if (identifier) {
const telemetryProps: TelemetryProperties = telemetryProperties(`${identifier}_error`);
const message = getStderrString(result);
telemetryProps.error = hideClusterInfo(message);
sendTelemetry(`${commandId}_error`, telemetryProps);
sendTelemetry(`${identifier}_error`, telemetryProps);
}
}

Expand All @@ -46,11 +46,11 @@ export function createTrackingEvent(name: string, properties = {}): TelemetryEve
}
}

export function telemetryLogCommand(commandId: string, message?: string): void {
if (commandId) {
const telemetryProps: TelemetryProperties = telemetryProperties(commandId);
export function telemetryLog(identifier: string, message?: string): void {
if (identifier) {
const telemetryProps: TelemetryProperties = telemetryProperties(identifier);
if (message) telemetryProps['message'] = message;
sendTelemetry(commandId, telemetryProps);
sendTelemetry(identifier, telemetryProps);
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PipelineRun } from './tree-view/pipelinerun-node';
import { MoreNode } from './tree-view/expand-node';
import { Command } from './cli-command';
import { getPipelineList } from './util/list-tekton-resource';
import { telemetryLog, telemetryLogError } from './telemetry';

export const humanizer = humanize.humanizer(createConfig());

Expand Down Expand Up @@ -139,27 +140,32 @@ export class TknImpl implements Tkn {
const kubectlCheck = RegExp('kubectl:\\s*command not found');
if (kubectlCheck.test(getStderrString(result.error))) {
const tknMessage = 'Please install kubectl.';
telemetryLog('kubeclt_not_found', tknMessage);
watchResources.disableWatch();
return [new TektonNodeImpl(null, tknMessage, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)]
}
if (result.stdout.trim() === 'no') {
const tknDownMsg = 'The current user doesn\'t have the privileges to interact with tekton resources.';
const tknPrivilegeMsg = 'The current user doesn\'t have the privileges to interact with tekton resources.';
telemetryLog('tekton_resource_privileges', tknPrivilegeMsg);
watchResources.disableWatch();
return [new TektonNodeImpl(null, tknDownMsg, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)];
return [new TektonNodeImpl(null, tknPrivilegeMsg, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)];
}
if (result.error && getStderrString(result.error).indexOf('You must be logged in to the server (Unauthorized)') > -1) {
const tknMessage = 'Please login to the server.';
telemetryLog('login', tknMessage);
watchResources.disableWatch();
return [new TektonNodeImpl(null, tknMessage, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)]
}
if (result.error && getStderrString(result.error).indexOf('the server doesn\'t have a resource type \'pipeline\'') > -1) {
const tknDownMsg = 'Please install the OpenShift Pipelines Operator.';
const message = 'Please install the Pipelines Operator.';
telemetryLog('install_pipeline_operator', message);
watchResources.disableWatch();
return [new TektonNodeImpl(null, tknDownMsg, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)];
return [new TektonNodeImpl(null, message, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)];
}
const serverCheck = RegExp('Unable to connect to the server');
if (serverCheck.test(getStderrString(result.error))) {
const loginError = 'Unable to connect to OpenShift cluster, is it down?';
telemetryLogError('problem_connect_cluster', loginError);
watchResources.disableWatch();
return [new TektonNodeImpl(null, loginError, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)];
}
Expand Down
7 changes: 5 additions & 2 deletions test/tkn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { TektonNode, TektonNodeImpl } from '../src/tree-view/tekton-node';
import { PipelineRun } from '../src/tree-view/pipelinerun-node';
import { MoreNode } from '../src/tree-view/expand-node';
import { Command } from '../src/cli-command';
import * as telemetry from '../src/telemetry';

const expect = chai.expect;
chai.use(sinonChai);
Expand All @@ -37,6 +38,8 @@ suite('tkn', () => {
let execStubCli: sinon.SinonStub;

setup(() => {
sandbox.stub(telemetry, 'telemetryLog');
sandbox.stub(telemetry, 'telemetryLogError');
sandbox.stub(ToolsConfig, 'getVersion').resolves('0.2.0');
execStubCli = sandbox.stub(CliImpl.prototype, 'execute').resolves();
});
Expand Down Expand Up @@ -1184,10 +1187,10 @@ suite('tkn', () => {
assert.equal(result[0].getName(), 'The current user doesn\'t have the privileges to interact with tekton resources.');
});

test('show warning message if OpenShift pipelines operator is not installed', async () => {
test('show warning message if pipelines operator is not installed', async () => {
execStub.onFirstCall().resolves({ error: 'error: the server doesn\'t have a resource type \'pipeline\'', stdout: '' });
const result = await tknCli.getPipelineNodes();
assert.equal(result[0].getName(), 'Please install the OpenShift Pipelines Operator.');
assert.equal(result[0].getName(), 'Please install the Pipelines Operator.');
});
});

Expand Down