-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Package policy upgrade telemetry with sender (#115180)
* draft of upgrade usage collector * telemetry sender service * fixed tests and types * cleanup * type fix * removed collector * made required field message generic, added test * cleanup * cleanup * cleanup * removed v3-dev as outdated * removed conditional from telemetry url creation * supporting multiple channels in sender * fix types * refactor * using json content type * fix test * simplified telemetry url * fixed type * added back ndjson * moved telemetry to update, added dryrun * fix types * fix prettier * updated after review * fix imports * added error_message field * review fixes Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
38a51c8
commit 654e75a
Showing
15 changed files
with
661 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/fleet/server/services/upgrade_usage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { Logger } from 'src/core/server'; | ||
import { loggingSystemMock } from 'src/core/server/mocks'; | ||
|
||
import type { TelemetryEventsSender } from '../telemetry/sender'; | ||
import { createMockTelemetryEventsSender } from '../telemetry/__mocks__'; | ||
|
||
import { sendTelemetryEvents, capErrorSize } from './upgrade_usage'; | ||
import type { PackagePolicyUpgradeUsage } from './upgrade_usage'; | ||
|
||
describe('sendTelemetryEvents', () => { | ||
let eventsTelemetryMock: jest.Mocked<TelemetryEventsSender>; | ||
let loggerMock: jest.Mocked<Logger>; | ||
|
||
beforeEach(() => { | ||
eventsTelemetryMock = createMockTelemetryEventsSender(); | ||
loggerMock = loggingSystemMock.createLogger(); | ||
}); | ||
|
||
it('should queue telemetry events with generic error', () => { | ||
const upgardeMessage: PackagePolicyUpgradeUsage = { | ||
package_name: 'aws', | ||
current_version: '0.6.1', | ||
new_version: '1.3.0', | ||
status: 'failure', | ||
error: [ | ||
{ key: 'queueUrl', message: ['Queue URL is required'] }, | ||
{ message: 'Invalid format' }, | ||
], | ||
dryRun: true, | ||
}; | ||
|
||
sendTelemetryEvents(loggerMock, eventsTelemetryMock, upgardeMessage); | ||
|
||
expect(eventsTelemetryMock.queueTelemetryEvents).toHaveBeenCalledWith('fleet-upgrades', [ | ||
{ | ||
current_version: '0.6.1', | ||
error: [ | ||
{ | ||
key: 'queueUrl', | ||
message: ['Queue URL is required'], | ||
}, | ||
{ | ||
message: 'Invalid format', | ||
}, | ||
], | ||
error_message: ['Field is required', 'Invalid format'], | ||
new_version: '1.3.0', | ||
package_name: 'aws', | ||
status: 'failure', | ||
dryRun: true, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should cap error size', () => { | ||
const maxSize = 2; | ||
const errors = [{ message: '1' }, { message: '2' }, { message: '3' }]; | ||
|
||
const result = capErrorSize(errors, maxSize); | ||
|
||
expect(result.length).toEqual(maxSize); | ||
}); | ||
}); |
Oops, something went wrong.