-
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.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.5`: - [[APM] Limit the number of source map artifacts (#144963)](#144963) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Søren Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-12T14:25:55Z","message":"[APM] Limit the number of source map artifacts (#144963)","sha":"654d531efda087b5c297d4fef4a8b9aed0a318ca","branchLabelMapping":{"^v8.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:APM","apm:test-plan-regression","backport:prev-minor","v8.6.0"],"number":144963,"url":"https://github.com/elastic/kibana/pull/144963","mergeCommit":{"message":"[APM] Limit the number of source map artifacts (#144963)","sha":"654d531efda087b5c297d4fef4a8b9aed0a318ca"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.6.0","labelRegex":"^v8.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/144963","number":144963,"mergeCommit":{"message":"[APM] Limit the number of source map artifacts (#144963)","sha":"654d531efda087b5c297d4fef4a8b9aed0a318ca"}}]}] BACKPORT--> Co-authored-by: Søren Louv-Jansen <[email protected]>
- Loading branch information
1 parent
c23f85a
commit 3b7df37
Showing
3 changed files
with
168 additions
and
29 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
144 changes: 144 additions & 0 deletions
144
x-pack/test/apm_api_integration/tests/sourcemaps/sourcemaps.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,144 @@ | ||
/* | ||
* 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 { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; | ||
import type { SourceMap } from '@kbn/apm-plugin/server/routes/source_maps/route'; | ||
import expect from '@kbn/expect'; | ||
import { times } from 'lodash'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
|
||
export default function ApiTest({ getService }: FtrProviderContext) { | ||
const registry = getService('registry'); | ||
const apmApiClient = getService('apmApiClient'); | ||
|
||
async function uploadSourcemap({ | ||
bundleFilePath, | ||
serviceName, | ||
serviceVersion, | ||
sourcemap, | ||
}: { | ||
bundleFilePath: string; | ||
serviceName: string; | ||
serviceVersion: string; | ||
sourcemap: SourceMap; | ||
}) { | ||
const response = await apmApiClient.writeUser({ | ||
endpoint: 'POST /api/apm/sourcemaps', | ||
type: 'form-data', | ||
params: { | ||
body: { | ||
bundle_filepath: bundleFilePath, | ||
service_name: serviceName, | ||
service_version: serviceVersion, | ||
sourcemap: JSON.stringify(sourcemap), | ||
}, | ||
}, | ||
}); | ||
return response.body; | ||
} | ||
|
||
async function deleteSourcemap(id: string) { | ||
await apmApiClient.writeUser({ | ||
endpoint: 'DELETE /api/apm/sourcemaps/{id}', | ||
params: { path: { id } }, | ||
}); | ||
} | ||
|
||
async function listSourcemaps() { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: 'GET /api/apm/sourcemaps', | ||
}); | ||
return response.body.artifacts; | ||
} | ||
|
||
registry.when('source maps', { config: 'basic', archives: [] }, () => { | ||
let resp: APIReturnType<'POST /api/apm/sourcemaps'>; | ||
describe('upload source map', () => { | ||
after(async () => { | ||
await apmApiClient.writeUser({ | ||
endpoint: 'DELETE /api/apm/sourcemaps/{id}', | ||
params: { path: { id: resp.id } }, | ||
}); | ||
}); | ||
|
||
it('can upload a source map', async () => { | ||
resp = await uploadSourcemap({ | ||
serviceName: 'foo', | ||
serviceVersion: '1.0.0', | ||
bundleFilePath: 'bar', | ||
sourcemap: { | ||
version: 123, | ||
sources: [''], | ||
mappings: '', | ||
}, | ||
}); | ||
expect(resp).to.not.empty(); | ||
}); | ||
}); | ||
|
||
describe('list source maps', () => { | ||
const uploadedSourcemapIds: string[] = []; | ||
before(async () => { | ||
const sourcemapCount = times(2); | ||
for (const i of sourcemapCount) { | ||
const sourcemap = await uploadSourcemap({ | ||
serviceName: 'foo', | ||
serviceVersion: `1.0.${i}`, | ||
bundleFilePath: 'bar', | ||
sourcemap: { | ||
version: 123, | ||
sources: [''], | ||
mappings: '', | ||
}, | ||
}); | ||
uploadedSourcemapIds.push(sourcemap.id); | ||
await sleep(100); | ||
} | ||
}); | ||
|
||
after(async () => { | ||
await Promise.all(uploadedSourcemapIds.map((id) => deleteSourcemap(id))); | ||
}); | ||
|
||
it('can list source maps', async () => { | ||
const sourcemaps = await listSourcemaps(); | ||
expect(sourcemaps).to.not.empty(); | ||
}); | ||
|
||
it('returns newest source maps first', async () => { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: 'GET /api/apm/sourcemaps', | ||
}); | ||
|
||
const timestamps = response.body.artifacts.map((a) => new Date(a.created).getTime()); | ||
expect(timestamps[0]).to.be.greaterThan(timestamps[1]); | ||
}); | ||
}); | ||
|
||
describe('delete source maps', () => { | ||
it('can delete a source map', async () => { | ||
const sourcemap = await uploadSourcemap({ | ||
serviceName: 'foo', | ||
serviceVersion: '1.0.0', | ||
bundleFilePath: 'bar', | ||
sourcemap: { | ||
version: 123, | ||
sources: [''], | ||
mappings: '', | ||
}, | ||
}); | ||
|
||
await deleteSourcemap(sourcemap.id); | ||
const sourcemaps = await listSourcemaps(); | ||
expect(sourcemaps).to.be.empty(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |