-
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] Add
?full
option to get package info endpoint to return all…
… package fields (#144343) * add source mode to archive parsing * add ?full patram to get pkg info * revert archive change * do not cache EPR fetch info * add test package for source_mode * add int test * add new param to frontent * use released package for test * tidy for PR * Add API docs * add get all packages script * get archive from cache even if not installed * fix types
- Loading branch information
Showing
26 changed files
with
373 additions
and
20 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
128 changes: 128 additions & 0 deletions
128
x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.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,128 @@ | ||
/* | ||
* 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 fetch from 'node-fetch'; | ||
import { kibanaPackageJson } from '@kbn/utils'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { chunk } from 'lodash'; | ||
|
||
import yargs from 'yargs/yargs'; | ||
|
||
import type { PackageInfo } from '../../common'; | ||
|
||
const REGISTRY_URL = 'https://epr-snapshot.elastic.co'; | ||
const KIBANA_URL = 'http://localhost:5601'; | ||
const KIBANA_USERNAME = 'elastic'; | ||
const KIBANA_PASSWORD = 'changeme'; | ||
const KIBANA_VERSION = kibanaPackageJson.version; | ||
|
||
const { base = '', prerelease = false, batchSize = 1 } = yargs(process.argv).argv; | ||
|
||
const logger = new ToolingLog({ | ||
level: 'info', | ||
writeTo: process.stdout, | ||
}); | ||
|
||
interface Result { | ||
pkg: string; | ||
epr: number; | ||
archive: number; | ||
archiveCached: number; | ||
} | ||
async function getPackage(name: string, version: string, full: boolean = false) { | ||
const start = Date.now(); | ||
const res = await fetch( | ||
`${KIBANA_URL}${base}/api/fleet/epm/packages/${name}/${version}?prerelease=true${ | ||
full ? '&full=true' : '' | ||
}`, | ||
{ | ||
headers: { | ||
accept: '*/*', | ||
'content-type': 'application/json', | ||
'kbn-xsrf': 'xyz', | ||
Authorization: | ||
'Basic ' + Buffer.from(`${KIBANA_USERNAME}:${KIBANA_PASSWORD}`).toString('base64'), | ||
}, | ||
method: 'GET', | ||
} | ||
); | ||
const end = Date.now(); | ||
|
||
let body; | ||
try { | ||
body = await res.json(); | ||
} catch (e) { | ||
logger.error(`Error parsing response: ${e}`); | ||
throw e; | ||
} | ||
|
||
if (body.item && body.item.name) { | ||
return { pkg: body.item, status: body.status, took: (end - start) / 1000 }; | ||
} | ||
|
||
throw new Error(`Invalid package returned for ${name}-${version} : ${JSON.stringify(res)}`); | ||
} | ||
|
||
async function getAllPackages() { | ||
const res = await fetch( | ||
`${REGISTRY_URL}/search?kibana.version=${KIBANA_VERSION}${ | ||
prerelease ? '&prerelease=true' : '' | ||
}`, | ||
{ | ||
headers: { | ||
accept: '*/*', | ||
}, | ||
method: 'GET', | ||
} | ||
); | ||
const body = await res.json(); | ||
return body as PackageInfo[]; | ||
} | ||
|
||
async function performTest({ name, version }: { name: string; version: string }): Promise<Result> { | ||
const eprResult = await getPackage(name, version); | ||
const archiveResult = await getPackage(name, version, true); | ||
const cachedArchiveResult = await getPackage(name, version, true); | ||
logger.info(`✅ ${name}-${version}`); | ||
|
||
return { | ||
pkg: `${name}-${version}`, | ||
epr: eprResult.took, | ||
archive: archiveResult.took, | ||
archiveCached: cachedArchiveResult.took, | ||
}; | ||
} | ||
|
||
export async function run() { | ||
const allPackages = await getAllPackages(); | ||
|
||
const batches = chunk(allPackages, batchSize as number); | ||
let allResults: Result[] = []; | ||
|
||
const start = Date.now(); | ||
for (const batch of batches) { | ||
const results = await Promise.all(batch.map(performTest)); | ||
allResults = [...allResults, ...(results.filter((v) => v) as Result[])]; | ||
} | ||
const end = Date.now(); | ||
const took = (end - start) / 1000; | ||
allResults.sort((a, b) => b.archive - a.archive); | ||
logger.info(`Took ${took} seconds to get ${allResults.length} packages`); | ||
logger.info( | ||
'Average EPM time: ' + allResults.reduce((acc, { epr }) => acc + epr, 0) / allResults.length | ||
); | ||
logger.info( | ||
'Average Archive time: ' + | ||
allResults.reduce((acc, { archive }) => acc + archive, 0) / allResults.length | ||
); | ||
logger.info( | ||
'Average Cache time: ' + | ||
allResults.reduce((acc, { archiveCached }) => acc + archiveCached, 0) / allResults.length | ||
); | ||
// eslint-disable-next-line no-console | ||
console.table(allResults); | ||
} |
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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
require('../../../../../src/setup_node_env'); | ||
require('./get_all_packages').run(); |
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
6 changes: 6 additions & 0 deletions
6
...ion/apis/fixtures/test_packages/non_epr_fields/1.0.0/data_stream/test_logs/fields/ecs.yml
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,6 @@ | ||
- name: logs_test_name | ||
title: logs_test_title | ||
type: text | ||
- name: new_field_name | ||
title: new_field_title | ||
type: keyword |
16 changes: 16 additions & 0 deletions
16
.../apis/fixtures/test_packages/non_epr_fields/1.0.0/data_stream/test_logs/fields/fields.yml
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,16 @@ | ||
- name: data_stream.type | ||
type: constant_keyword | ||
description: > | ||
Data stream type. | ||
- name: data_stream.dataset | ||
type: constant_keyword | ||
description: > | ||
Data stream dataset. | ||
- name: data_stream.namespace | ||
type: constant_keyword | ||
description: > | ||
Data stream namespace. | ||
- name: '@timestamp' | ||
type: date | ||
description: > | ||
Event timestamp. |
Oops, something went wrong.