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.
[kbn-journeys] add synthtrace support (elastic#178599)
## Summary Moving synthtrace clients init inside kbn-journeys: esArchiver does not always solve the issue with data generation. We already have afew journeys using Synthtrace instead and expect more to come. In order to simplify the process of creating new journeys, this PR moves Synthtrace client initialisation into kbn-journey package and exposes a way to define client type, generator function & its input arguments: ``` import { Journey, SynthtraceOptions } from '@kbn/journeys'; import { subj } from '@kbn/test-subj-selector'; import { generateApmData } from '../synthtrace_data/apm_data'; export const journey = new Journey({ synthtrace: { type: 'apm', generator: generateApmData, options: { from: new Date(Date.now() - 1000 * 60 * 15), to: new Date(Date.now() + 1000 * 60 * 15), }, }, }) ``` PR also needs review from teams who use Synthtrace to understand if the implementation is matching expectations. --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
45dbfae
commit aa45c2a
Showing
13 changed files
with
297 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* 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 { | ||
ApmSynthtraceEsClient, | ||
ApmSynthtraceKibanaClient, | ||
InfraSynthtraceEsClient, | ||
InfraSynthtraceKibanaClient, | ||
} from '@kbn/apm-synthtrace'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import Url from 'url'; | ||
import { Logger } from '@kbn/apm-synthtrace/src/lib/utils/create_logger'; | ||
import { Auth, Es } from '.'; | ||
import { KibanaUrl } from './kibana_url'; | ||
|
||
export interface SynthtraceClientOptions { | ||
kbnUrl: KibanaUrl; | ||
auth: Auth; | ||
es: Es; | ||
log: ToolingLog; | ||
} | ||
export type SynthtraceClient = InfraSynthtraceEsClient | ApmSynthtraceEsClient; | ||
export type SynthtraceClientType = 'infra' | 'apm'; | ||
|
||
export async function getSynthtraceClient( | ||
type: SynthtraceClientType, | ||
options: SynthtraceClientOptions | ||
): Promise<SynthtraceClient> { | ||
if (type === 'infra') { | ||
return initInfraSynthtraceClient(options); | ||
} else { | ||
return initApmSynthtraceClient(options); | ||
} | ||
} | ||
|
||
// Adapting ToolingLog instance to Logger interface | ||
class LoggerAdapter implements Logger { | ||
private log: ToolingLog; | ||
private joiner = ', '; | ||
|
||
constructor(log: ToolingLog) { | ||
this.log = log; | ||
} | ||
|
||
debug(...args: any[]): void { | ||
this.log.debug(args.join(this.joiner)); | ||
} | ||
|
||
info(...args: any[]): void { | ||
this.log.info(args.join(this.joiner)); | ||
} | ||
|
||
error(arg: string | Error): void { | ||
this.log.error(arg); | ||
} | ||
|
||
perf<T>(name: string, cb: () => T): T { | ||
const startTime = Date.now(); | ||
const result = cb(); | ||
const duration = Date.now() - startTime; | ||
const durationInSeconds = duration / 1000; | ||
const formattedTime = durationInSeconds.toFixed(3) + 's'; | ||
this.log.info(`${name} took ${formattedTime}.`); | ||
return result; | ||
} | ||
} | ||
|
||
async function initInfraSynthtraceClient(options: SynthtraceClientOptions) { | ||
const { log, es, auth, kbnUrl } = options; | ||
const logger: Logger = new LoggerAdapter(log); | ||
|
||
const synthKbnClient = new InfraSynthtraceKibanaClient({ | ||
logger, | ||
target: kbnUrl.get(), | ||
username: auth.getUsername(), | ||
password: auth.getPassword(), | ||
}); | ||
const pkgVersion = await synthKbnClient.fetchLatestSystemPackageVersion(); | ||
await synthKbnClient.installSystemPackage(pkgVersion); | ||
|
||
const synthEsClient = new InfraSynthtraceEsClient({ | ||
logger, | ||
client: es, | ||
refreshAfterIndex: true, | ||
}); | ||
|
||
return synthEsClient; | ||
} | ||
|
||
async function initApmSynthtraceClient(options: SynthtraceClientOptions) { | ||
const { log, es, auth, kbnUrl } = options; | ||
const logger: Logger = new LoggerAdapter(log); | ||
const kibanaUrl = new URL(kbnUrl.get()); | ||
const kibanaUrlWithAuth = Url.format({ | ||
protocol: kibanaUrl.protocol, | ||
hostname: kibanaUrl.hostname, | ||
port: kibanaUrl.port, | ||
auth: `${auth.getUsername()}:${auth.getPassword()}`, | ||
}); | ||
|
||
const synthKbnClient = new ApmSynthtraceKibanaClient({ | ||
logger, | ||
target: kibanaUrlWithAuth, | ||
}); | ||
const packageVersion = await synthKbnClient.fetchLatestApmPackageVersion(); | ||
await synthKbnClient.installApmPackage(packageVersion); | ||
|
||
const synthEsClient = new ApmSynthtraceEsClient({ | ||
client: es, | ||
logger, | ||
refreshAfterIndex: true, | ||
version: packageVersion, | ||
}); | ||
|
||
synthEsClient.pipeline(synthEsClient.getDefaultPipeline(false)); | ||
|
||
return synthEsClient; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/kbn-performance-testing-dataset-extractor/kibana.jsonc
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
Oops, something went wrong.