-
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.
Migrate agent_explorer test Update latest_agent_versions test
- Loading branch information
1 parent
e945fc9
commit eee7cd3
Showing
12 changed files
with
347 additions
and
7 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
55 changes: 55 additions & 0 deletions
55
x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.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,55 @@ | ||
/* | ||
* 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 globby from 'globby'; | ||
import path from 'path'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
const cwd = path.join(__dirname); | ||
const envGrepFiles = process.env.APM_TEST_GREP_FILES as string; | ||
|
||
function getGlobPattern() { | ||
try { | ||
const envGrepFilesParsed = JSON.parse(envGrepFiles as string) as string[]; | ||
return envGrepFilesParsed.map((pattern) => { | ||
return pattern.includes('spec') ? `**/${pattern}**` : `**/${pattern}**.spec.ts`; | ||
}); | ||
} catch (e) { | ||
// ignore | ||
} | ||
return '**/*.spec.ts'; | ||
} | ||
|
||
export default function apmApiIntegrationTests({ | ||
getService, | ||
loadTestFile, | ||
}: DeploymentAgnosticFtrProviderContext) { | ||
// DO NOT SKIP | ||
// Skipping here will skip the entire apm api test suite | ||
// Instead skip (flaky) tests individually | ||
// Failing: See https://github.com/elastic/kibana/issues/176948 | ||
describe('APM API tests', function () { | ||
const registry = getService('registry'); | ||
const filePattern = getGlobPattern(); | ||
const tests = globby.sync(filePattern, { cwd }); | ||
|
||
if (envGrepFiles) { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`\nCommand "--grep-files=${filePattern}" matched ${tests.length} file(s):\n${tests | ||
.map((name) => ` - ${name}`) | ||
.join('\n')}\n` | ||
); | ||
} | ||
|
||
tests.forEach((testName) => { | ||
describe(testName, () => { | ||
loadTestFile(require.resolve(`./${testName}`)); | ||
registry.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
121 changes: 121 additions & 0 deletions
121
x-pack/test/api_integration/deployment_agnostic/services/apm_api.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,121 @@ | ||
/* | ||
* 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 { format } from 'url'; | ||
import request from 'superagent'; | ||
import type { | ||
APIReturnType, | ||
APIClientRequestParamsOf, | ||
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; | ||
import { APIEndpoint } from '@kbn/apm-plugin/server'; | ||
import { formatRequest } from '@kbn/server-route-repository'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../ftr_provider_context'; | ||
|
||
function createApmApiClient({ getService }: DeploymentAgnosticFtrProviderContext, role: string) { | ||
const supertestWithoutAuth = getService('supertestWithoutAuth'); | ||
const samlAuth = getService('samlAuth'); | ||
|
||
return async <TEndpoint extends APIEndpoint>( | ||
options: { | ||
type?: 'form-data'; | ||
endpoint: TEndpoint; | ||
spaceId?: string; | ||
} & APIClientRequestParamsOf<TEndpoint> & { | ||
params?: { query?: { _inspect?: boolean } }; | ||
} | ||
): Promise<SupertestReturnType<TEndpoint>> => { | ||
const { endpoint, type } = options; | ||
|
||
const params = 'params' in options ? (options.params as Record<string, any>) : {}; | ||
|
||
const roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope(role); | ||
|
||
const headers: Record<string, string> = { | ||
...samlAuth.getInternalRequestHeader(), | ||
...roleAuthc.apiKeyHeader, | ||
}; | ||
|
||
const { method, pathname, version } = formatRequest(endpoint, params.path); | ||
const pathnameWithSpaceId = options.spaceId ? `/s/${options.spaceId}${pathname}` : pathname; | ||
const url = format({ pathname: pathnameWithSpaceId, query: params?.query }); | ||
|
||
// eslint-disable-next-line no-console | ||
console.debug(`Calling APM API: ${method.toUpperCase()} ${url}`); | ||
|
||
if (version) { | ||
headers['Elastic-Api-Version'] = version; | ||
} | ||
|
||
let res: request.Response; | ||
if (type === 'form-data') { | ||
const fields: Array<[string, any]> = Object.entries(params.body); | ||
const formDataRequest = supertestWithoutAuth[method](url) | ||
.set(headers) | ||
.set('Content-type', 'multipart/form-data'); | ||
|
||
for (const field of fields) { | ||
void formDataRequest.field(field[0], field[1]); | ||
} | ||
|
||
res = await formDataRequest; | ||
} else if (params.body) { | ||
res = await supertestWithoutAuth[method](url).send(params.body).set(headers); | ||
} else { | ||
res = await supertestWithoutAuth[method](url).set(headers); | ||
} | ||
|
||
// supertest doesn't throw on http errors | ||
if (res?.status !== 200) { | ||
throw new ApmApiError(res, endpoint); | ||
} | ||
|
||
return res; | ||
}; | ||
} | ||
|
||
type ApiErrorResponse = Omit<request.Response, 'body'> & { | ||
body: { | ||
statusCode: number; | ||
error: string; | ||
message: string; | ||
attributes: object; | ||
}; | ||
}; | ||
|
||
export type ApmApiSupertest = ReturnType<typeof createApmApiClient>; | ||
|
||
export class ApmApiError extends Error { | ||
res: ApiErrorResponse; | ||
|
||
constructor(res: request.Response, endpoint: string) { | ||
super( | ||
`Unhandled ApmApiError. | ||
Status: "${res.status}" | ||
Endpoint: "${endpoint}" | ||
Body: ${JSON.stringify(res.body)}` | ||
); | ||
|
||
this.res = res; | ||
} | ||
} | ||
|
||
export interface SupertestReturnType<TEndpoint extends APIEndpoint> { | ||
status: number; | ||
body: APIReturnType<TEndpoint>; | ||
} | ||
|
||
export function ApmApiProvider(context: DeploymentAgnosticFtrProviderContext) { | ||
return { | ||
async createApmApiClient() { | ||
return { | ||
readUser: createApmApiClient(context, 'viewer'), | ||
adminUser: createApmApiClient(context, 'admin'), | ||
writeUser: createApmApiClient(context, 'editor'), | ||
}; | ||
}, | ||
}; | ||
} |
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.