forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infra] hosts table metrics (elastic#173708)
## Summary Closes elastic#172475 - record performance event of the host table data loading - infra synthtrace now installs `system` package and can produce all datasets queried by host view - [lens viz](https://telemetry-v2-staging.elastic.dev/s/kibana-performance/app/visualize#/edit/f88d3180-9f10-11ee-b4ef-7533a045abfc?_g=h@97e8101&_a=h@a8f21d5) (internal) ### Testing - run journey with `PERFORMANCE_ENABLE_TELEMETRY=1 node scripts/run_performance.js -v --journey-path x-pack/performance/journeys/infra_hosts_view.ts` - check data is ingested in lens --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Dzmitry Lemechko <[email protected]>
- Loading branch information
1 parent
82718b7
commit 585838c
Showing
21 changed files
with
352 additions
and
32 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
packages/kbn-apm-synthtrace/src/lib/infra/infra_synthtrace_kibana_client.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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { join } from 'path'; | ||
import fetch from 'node-fetch'; | ||
import pRetry from 'p-retry'; | ||
import { Logger } from '../utils/create_logger'; | ||
import { kibanaHeaders } from '../shared/client_headers'; | ||
|
||
export class InfraSynthtraceKibanaClient { | ||
private readonly logger: Logger; | ||
private target: string; | ||
|
||
constructor(options: { logger: Logger; target: string; username: string; password: string }) { | ||
this.logger = options.logger; | ||
const url = new URL(options.target); | ||
url.username = options.username; | ||
url.password = options.password; | ||
this.target = url.toString(); | ||
} | ||
|
||
async fetchLatestSystemPackageVersion() { | ||
const fleetPackageApiUrl = join(this.target, '/api/fleet/epm/packages/system?prerelease=true'); | ||
this.logger.debug(`Fetching latest System package version from ${fleetPackageApiUrl}`); | ||
const response = await fetch(fleetPackageApiUrl, { | ||
method: 'GET', | ||
headers: kibanaHeaders(), | ||
}); | ||
|
||
const responseJson = await response.json(); | ||
|
||
if (response.status !== 200) { | ||
throw new Error( | ||
`Failed to fetch latest System package version, received HTTP ${response.status} and message: ${responseJson.message}` | ||
); | ||
} | ||
|
||
const { latestVersion } = responseJson.item; | ||
|
||
return latestVersion as string; | ||
} | ||
|
||
async installSystemPackage(packageVersion: string) { | ||
this.logger.debug(`Installing System package ${packageVersion}`); | ||
|
||
const url = join(this.target, `/api/fleet/epm/packages/system/${packageVersion}`); | ||
const response = await pRetry(() => { | ||
return fetch(url, { | ||
method: 'POST', | ||
headers: kibanaHeaders(), | ||
body: '{"force":true}', | ||
}); | ||
}); | ||
|
||
const responseJson = await response.json(); | ||
|
||
if (!responseJson.items) { | ||
throw new Error( | ||
`Failed to install System package version ${packageVersion}, received HTTP ${response.status} and message: ${responseJson.message} for url ${url}` | ||
); | ||
} | ||
|
||
this.logger.info(`Installed System package ${packageVersion}`); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/kbn-apm-synthtrace/src/lib/shared/client_headers.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,16 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export function kibanaHeaders() { | ||
return { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
'kbn-xsrf': 'kibana', | ||
'elastic-api-version': '2023-10-31', | ||
}; | ||
} |
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,86 @@ | ||
/* | ||
* 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 { Journey } from '@kbn/journeys'; | ||
import { | ||
createLogger, | ||
InfraSynthtraceEsClient, | ||
LogLevel, | ||
InfraSynthtraceKibanaClient, | ||
} from '@kbn/apm-synthtrace'; | ||
import { infra, timerange } from '@kbn/apm-synthtrace-client'; | ||
import { subj } from '@kbn/test-subj-selector'; | ||
|
||
export const journey = new Journey({ | ||
beforeSteps: async ({ kbnUrl, auth, es }) => { | ||
const logger = createLogger(LogLevel.debug); | ||
const synthKibanaClient = new InfraSynthtraceKibanaClient({ | ||
logger, | ||
target: kbnUrl.get(), | ||
username: auth.getUsername(), | ||
password: auth.getPassword(), | ||
}); | ||
|
||
const pkgVersion = await synthKibanaClient.fetchLatestSystemPackageVersion(); | ||
await synthKibanaClient.installSystemPackage(pkgVersion); | ||
|
||
const synthEsClient = new InfraSynthtraceEsClient({ | ||
logger, | ||
client: es, | ||
refreshAfterIndex: true, | ||
}); | ||
|
||
const start = Date.now() - 1000 * 60 * 10; | ||
await synthEsClient.index( | ||
generateHostsData({ | ||
from: new Date(start).toISOString(), | ||
to: new Date().toISOString(), | ||
count: 1000, | ||
}) | ||
); | ||
}, | ||
}).step('Navigate to Hosts view and load 500 hosts', async ({ page, kbnUrl, kibanaPage }) => { | ||
await page.goto( | ||
kbnUrl.get( | ||
`app/metrics/hosts?_a=(dateRange:(from:now-15m,to:now),filters:!(),limit:500,panelFilters:!(),query:(language:kuery,query:''))` | ||
) | ||
); | ||
// wait for table to be loaded | ||
await page.waitForSelector(subj('hostsView-table-loaded')); | ||
// wait for metric charts to be loaded | ||
await kibanaPage.waitForCharts({ count: 5, timeout: 60000 }); | ||
}); | ||
|
||
export function generateHostsData({ | ||
from, | ||
to, | ||
count = 1, | ||
}: { | ||
from: string; | ||
to: string; | ||
count: number; | ||
}) { | ||
const range = timerange(from, to); | ||
|
||
const hosts = Array(count) | ||
.fill(0) | ||
.map((_, idx) => infra.host(`my-host-${idx}`)); | ||
|
||
return range | ||
.interval('30s') | ||
.rate(1) | ||
.generator((timestamp, index) => | ||
hosts.flatMap((host) => [ | ||
host.cpu().timestamp(timestamp), | ||
host.memory().timestamp(timestamp), | ||
host.network().timestamp(timestamp), | ||
host.load().timestamp(timestamp), | ||
host.filesystem().timestamp(timestamp), | ||
host.diskio().timestamp(timestamp), | ||
]) | ||
); | ||
} |
Oops, something went wrong.