Skip to content

Commit

Permalink
feat(telemetry): adding qemu version (podman-desktop#8949)
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 authored Sep 18, 2024
1 parent 7f91b21 commit 0d5235a
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 48 deletions.
165 changes: 117 additions & 48 deletions extensions/podman/packages/extension/src/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const telemetryLogger: extensionApi.TelemetryLogger = {
const mocks = vi.hoisted(() => ({
getPodmanLocationMacMock: vi.fn(),
getKrunkitVersionMock: vi.fn(),
getQemuVersionMock: vi.fn(),
}));

// mock ps-list
Expand Down Expand Up @@ -223,6 +224,12 @@ vi.mock('node:os', async () => {
};
});

vi.mock('./qemu-helper', () => ({
QemuHelper: vi.fn().mockReturnValue({
getQemuVersion: mocks.getQemuVersionMock,
}),
}));

vi.mock('./krunkit-helper', async () => {
return {
KrunkitHelper: vi.fn().mockImplementation(() => {
Expand Down Expand Up @@ -283,6 +290,10 @@ vi.mock('./util', async () => {
beforeEach(() => {
vi.resetAllMocks();
console.error = consoleErrorMock;

(extensionApi.env.isMac as boolean) = true;
(extensionApi.env.isLinux as boolean) = false;
(extensionApi.env.isWindows as boolean) = false;
});

afterEach(() => {
Expand Down Expand Up @@ -2098,59 +2109,117 @@ test('isLibkrunSupported should return false with previous 5.1.2 version', async
expect(enabled).toBeFalsy();
});

test('sendTelemetryRecords with krunkit found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
describe('sendTelemetryRecords', () => {
test('krunkit found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
});
mocks.getPodmanLocationMacMock.mockResolvedValue({ foundPath: '/opt/podman/bin/podman', source: 'installer' });
mocks.getKrunkitVersionMock.mockResolvedValue('1.2.3');

extension.sendTelemetryRecords(
'evt',
{
provider: 'libkrun',
} as Record<string, unknown>,
false,
);
await new Promise(resolve => setTimeout(resolve, 100));
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
krunkitPath: '/opt/podman/bin',
krunkitVersion: '1.2.3',
podmanCliFoundPath: '/opt/podman/bin/podman',
podmanCliSource: 'installer',
podmanCliVersion: '5.1.2',
provider: 'libkrun',
}),
);
});
mocks.getPodmanLocationMacMock.mockResolvedValue({ foundPath: '/opt/podman/bin/podman', source: 'installer' });
mocks.getKrunkitVersionMock.mockResolvedValue('1.2.3');

extension.sendTelemetryRecords(
'evt',
{
provider: 'libkrun',
} as Record<string, unknown>,
false,
);
await new Promise(resolve => setTimeout(resolve, 100));
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
krunkitPath: '/opt/podman/bin',
krunkitVersion: '1.2.3',
podmanCliFoundPath: '/opt/podman/bin/podman',
podmanCliSource: 'installer',
podmanCliVersion: '5.1.2',
provider: 'libkrun',
}),
);
});
test('krunkit not found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
});
mocks.getPodmanLocationMacMock.mockResolvedValue({ foundPath: '/opt/podman/bin/podman', source: 'installer' });
mocks.getKrunkitVersionMock.mockRejectedValue('command not found');

extension.sendTelemetryRecords(
'evt',
{
provider: 'libkrun',
} as Record<string, unknown>,
false,
);
await new Promise(resolve => setTimeout(resolve, 100));
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
errorKrunkitVersion: 'command not found',
podmanCliFoundPath: '/opt/podman/bin/podman',
podmanCliSource: 'installer',
podmanCliVersion: '5.1.2',
provider: 'libkrun',
}),
);
});

test('sendTelemetryRecords with krunkit not found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
test('qemu found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
});
extension.sendTelemetryRecords(
'evt',
{
provider: 'qemu',
} as Record<string, unknown>,
false,
);
(extensionApi.env.isLinux as boolean) = true;
(extensionApi.env.isMac as boolean) = false;
(extensionApi.env.isWindows as boolean) = false;

mocks.getQemuVersionMock.mockResolvedValue('5.5.5');

await vi.waitFor(() => {
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
provider: 'qemu',
qemuVersion: '5.5.5',
}),
);
});
});
mocks.getPodmanLocationMacMock.mockResolvedValue({ foundPath: '/opt/podman/bin/podman', source: 'installer' });
mocks.getKrunkitVersionMock.mockRejectedValue('command not found');

extension.sendTelemetryRecords(
'evt',
{
provider: 'libkrun',
} as Record<string, unknown>,
false,
);
await new Promise(resolve => setTimeout(resolve, 100));
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
errorKrunkitVersion: 'command not found',
podmanCliFoundPath: '/opt/podman/bin/podman',
podmanCliSource: 'installer',
podmanCliVersion: '5.1.2',
provider: 'libkrun',
}),
);
test('qemu not found', async () => {
vi.spyOn(podmanCli, 'getPodmanInstallation').mockResolvedValue({
version: '5.1.2',
});
extension.sendTelemetryRecords(
'evt',
{
provider: 'qemu',
} as Record<string, unknown>,
false,
);
(extensionApi.env.isLinux as boolean) = true;
(extensionApi.env.isMac as boolean) = false;
(extensionApi.env.isWindows as boolean) = false;

mocks.getQemuVersionMock.mockRejectedValue('command not found');

await vi.waitFor(() => {
expect(telemetryLogger.logUsage).toHaveBeenCalledWith(
'evt',
expect.objectContaining({
provider: 'qemu',
errorQemuVersion: 'command not found',
}),
);
});
});
});

test('if a machine stopped is successfully reporting telemetry', async () => {
Expand Down
9 changes: 9 additions & 0 deletions extensions/podman/packages/extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PodmanConfiguration } from './podman-configuration';
import { PodmanInfoHelper } from './podman-info-helper';
import { PodmanInstall } from './podman-install';
import { PodmanRemoteConnections } from './podman-remote-connections';
import { QemuHelper } from './qemu-helper';
import { RegistrySetup } from './registry-setup';
import {
appConfigDir,
Expand Down Expand Up @@ -89,6 +90,7 @@ const configurationCompatibilityMode = 'setting.dockerCompatibility';
let telemetryLogger: extensionApi.TelemetryLogger | undefined;

const wslHelper = new WslHelper();
const qemuHelper = new QemuHelper();
const krunkitHelper = new KrunkitHelper();
const podmanBinaryHelper = new PodmanBinaryLocationHelper();
const podmanInfoHelper = new PodmanInfoHelper();
Expand Down Expand Up @@ -1851,6 +1853,13 @@ export function sendTelemetryRecords(
console.trace('unable to check wsl version', error);
telemetryRecords.errorWslVersion = error;
}
} else if (extensionApi.env.isLinux && telemetryRecords.provider === 'qemu') {
try {
telemetryRecords.qemuVersion = await qemuHelper.getQemuVersion();
} catch (err: unknown) {
console.trace('unable to check qemu version', err);
telemetryRecords.errorQemuVersion = err;
}
}

// add server side information about the machine
Expand Down

0 comments on commit 0d5235a

Please sign in to comment.