mirror of
https://github.com/podman-desktop/podman-desktop
synced 2026-04-21 09:37:22 +00:00
fix(telemetry): rename and rate limit handleContainerEventsFailure (#16789)
* fix(telemetry): rename handleContainerEventsFailure Signed-off-by: Dias Tursynbayev <original.justmello1337@gmail.com>
This commit is contained in:
parent
d870cf0b00
commit
e8174ba192
3 changed files with 54 additions and 1 deletions
|
|
@ -3697,6 +3697,55 @@ test('check handleEvents is not calling the console.log for health_status event'
|
|||
expect(consoleLogSpy).not.toBeCalled();
|
||||
});
|
||||
|
||||
test('check handleEvents tracks telemetry when stream emits error', async () => {
|
||||
telemetryTrackMock.mockClear();
|
||||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const getEventsMock = vi.fn();
|
||||
let eventsMockCallback: ((ignored: unknown, stream: PassThrough) => void) | undefined;
|
||||
// keep the function passed in parameter of getEventsMock
|
||||
getEventsMock.mockImplementation((options: (ignored: unknown, stream: PassThrough) => void) => {
|
||||
eventsMockCallback = options;
|
||||
});
|
||||
|
||||
const passThrough = new PassThrough();
|
||||
const fakeDockerode = {
|
||||
getEvents: getEventsMock,
|
||||
} as unknown as Dockerode;
|
||||
|
||||
const errorCallback = vi.fn();
|
||||
|
||||
containerRegistry.handleEvents(fakeDockerode, errorCallback);
|
||||
|
||||
if (eventsMockCallback) {
|
||||
eventsMockCallback?.(undefined, passThrough);
|
||||
}
|
||||
|
||||
// emit an error on the stream
|
||||
const testError = new Error('stream connection error');
|
||||
passThrough.emit('error', testError);
|
||||
|
||||
// wait for error handling
|
||||
await vi.waitFor(() => expect(errorCallback).toHaveBeenCalled());
|
||||
|
||||
// check that telemetry was tracked with correct event name and properties
|
||||
expect(telemetry.track).toHaveBeenCalledWith(
|
||||
'container-events-failure',
|
||||
expect.objectContaining({
|
||||
nbEvents: expect.any(Number),
|
||||
failureAfter: expect.any(Number),
|
||||
error: testError,
|
||||
}),
|
||||
);
|
||||
|
||||
// verify error was logged
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith('/event stream received an error.', testError);
|
||||
|
||||
// verify error callback was called with wrapped error
|
||||
expect(errorCallback).toHaveBeenCalledWith(expect.objectContaining({ message: 'Error in handling events' }));
|
||||
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('check volume mounted is replicated when executing replicatePodmanContainer with named volume', async () => {
|
||||
const dockerAPI = new Dockerode({ protocol: 'http', host: 'localhost' });
|
||||
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ export class ContainerProviderRegistry {
|
|||
stream?.on('error', error => {
|
||||
console.error('/event stream received an error.', error);
|
||||
// log why it failed and after how many ms connection dropped
|
||||
this.telemetryService.track('handleContainerEventsFailure', {
|
||||
this.telemetryService.track('container-events-failure', {
|
||||
nbEvents,
|
||||
failureAfter: performance.now() - startDate,
|
||||
error,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
{
|
||||
"event": "list.*",
|
||||
"frequency": "dailyPerInstance"
|
||||
},
|
||||
{
|
||||
"event": "container-events-failure",
|
||||
"frequency": "dailyPerInstance"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue