-
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.
- Loading branch information
Showing
5 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
x-pack/test/api_integration/apis/asset_manager/bootstrap_apm_synthtrace.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,50 @@ | ||
/* | ||
* 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 { APM_TEST_PASSWORD } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication'; | ||
import { | ||
ApmSynthtraceEsClient, | ||
ApmSynthtraceKibanaClient, | ||
createLogger, | ||
LogLevel, | ||
} from '@kbn/apm-synthtrace'; | ||
import url from 'url'; | ||
import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export async function bootstrapApmSynthtrace( | ||
context: InheritedFtrProviderContext, | ||
kibanaClient: ApmSynthtraceKibanaClient | ||
) { | ||
const es = context.getService('es'); | ||
|
||
const kibanaVersion = await kibanaClient.fetchLatestApmPackageVersion(); | ||
await kibanaClient.installApmPackage(kibanaVersion); | ||
|
||
const esClient = new ApmSynthtraceEsClient({ | ||
client: es, | ||
logger: createLogger(LogLevel.info), | ||
version: kibanaVersion, | ||
refreshAfterIndex: true, | ||
}); | ||
|
||
return esClient; | ||
} | ||
|
||
export function getApmSynthtraceKibanaClient(kibanaServerUrl: string) { | ||
const kibanaServerUrlWithAuth = url | ||
.format({ | ||
...url.parse(kibanaServerUrl), | ||
auth: `elastic:${APM_TEST_PASSWORD}`, | ||
}) | ||
.slice(0, -1); | ||
|
||
const kibanaClient = new ApmSynthtraceKibanaClient({ | ||
target: kibanaServerUrlWithAuth, | ||
logger: createLogger(LogLevel.debug), | ||
}); | ||
|
||
return kibanaClient; | ||
} |
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
107 changes: 107 additions & 0 deletions
107
x-pack/test/api_integration/apis/asset_manager/tests/services.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,107 @@ | ||
/* | ||
* 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 { omit } from 'lodash'; | ||
import { apm, timerange } from '@kbn/apm-synthtrace-client'; | ||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../types'; | ||
import { ASSETS_ENDPOINT } from '../constants'; | ||
|
||
const SERVICES_ASSETS_ENDPOINT = `${ASSETS_ENDPOINT}/services`; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const synthtrace = getService('synthtraceEsClient'); | ||
|
||
describe('asset management', () => { | ||
beforeEach(async () => { | ||
await synthtrace.clean(); | ||
}); | ||
|
||
describe('GET /assets/services', () => { | ||
it('should return services', async () => { | ||
const from = new Date(Date.now() - 1000 * 60 * 2).toISOString(); | ||
const to = new Date().toISOString(); | ||
await synthtrace.index(generateServicesData({ from, to, count: 2 })); | ||
|
||
const response = await supertest | ||
.get(SERVICES_ASSETS_ENDPOINT) | ||
.query({ | ||
from, | ||
to, | ||
}) | ||
.expect(200); | ||
|
||
expect(response.body).to.have.property('services'); | ||
expect(response.body.services.length).to.equal(2); | ||
}); | ||
|
||
it('should return services running on specified host', async () => { | ||
const from = new Date(Date.now() - 1000 * 60 * 2).toISOString(); | ||
const to = new Date().toISOString(); | ||
await synthtrace.index(generateServicesData({ from, to, count: 5 })); | ||
|
||
const response = await supertest | ||
.get(SERVICES_ASSETS_ENDPOINT) | ||
.query({ | ||
from, | ||
to, | ||
parent: 'my-host-1', | ||
}) | ||
.expect(200); | ||
|
||
expect(response.body).to.have.property('services'); | ||
expect(response.body.services.length).to.equal(1); | ||
expect(omit(response.body.services[0], ['@timestamp'])).to.eql({ | ||
'asset.kind': 'service', | ||
'asset.id': 'service-1', | ||
'asset.ean': 'service:service-1', | ||
'asset.references': [], | ||
'asset.parents': [], | ||
'service.environment': 'production', | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function generateServicesData({ | ||
from, | ||
to, | ||
count = 1, | ||
}: { | ||
from: string; | ||
to: string; | ||
count: number; | ||
}) { | ||
const range = timerange(from, to); | ||
|
||
const services = Array(count) | ||
.fill(0) | ||
.map((_, idx) => | ||
apm | ||
.service({ | ||
name: `service-${idx}`, | ||
environment: 'production', | ||
agentName: 'nodejs', | ||
}) | ||
.instance(`my-host-${idx}`) | ||
); | ||
|
||
return range | ||
.interval('1m') | ||
.rate(1) | ||
.generator((timestamp, index) => | ||
services.map((service) => | ||
service | ||
.transaction({ transactionName: 'GET /foo' }) | ||
.timestamp(timestamp) | ||
.duration(500) | ||
.success() | ||
) | ||
); | ||
} |
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,19 @@ | ||
/* | ||
* 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 { GenericFtrProviderContext } from '@kbn/test'; | ||
import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context'; | ||
import { AssetManagerServices } from './config'; | ||
|
||
export type InheritedServices = InheritedFtrProviderContext extends GenericFtrProviderContext< | ||
infer TServices, | ||
{} | ||
> | ||
? TServices | ||
: {}; | ||
|
||
export type FtrProviderContext = GenericFtrProviderContext<AssetManagerServices, {}>; |