Skip to content

Commit

Permalink
[8.13] [APM] Update Indices API to support sourcemap param (#177847) (#…
Browse files Browse the repository at this point in the history
…177933)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[APM] Update Indices API to support sourcemap param
(#177847)](#177847)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cauê
Marcondes","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-03-04T13:26:30Z","message":"[APM]
Update Indices API to support sourcemap param (#177847)\n\ncloses
https://github.com/elastic/kibana/issues/177820\r\n\r\nSaved Object
before: \r\n\r\n```\r\n \"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\",\r\n \"sourcemap\": \"foo-*\"\r\n },\r\n
\"isSpaceAware\": true\r\n },\r\n```\r\n<img width=\"1826\"
alt=\"Screenshot 2024-02-28 at 17 47
12\"\r\nsrc=\"https://github.com/elastic/kibana/assets/55978943/e44d90ec-982c-4330-88dc-14f0f59bfce7\">\r\n\r\nSaved
Object after:\r\n```\r\n\"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\"\r\n },\r\n \"isSpaceAware\": true\r\n
},\r\n```\r\n\r\nThe API now accepts the `sourcemap`
param.","sha":"505b928dc1e30a70a2e4fe9d966e03174b2fbc2c","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:obs-ux-infra_services","v8.13.0","v8.14.0"],"title":"[APM]
Update Indices API to support sourcemap
param","number":177847,"url":"https://github.com/elastic/kibana/pull/177847","mergeCommit":{"message":"[APM]
Update Indices API to support sourcemap param (#177847)\n\ncloses
https://github.com/elastic/kibana/issues/177820\r\n\r\nSaved Object
before: \r\n\r\n```\r\n \"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\",\r\n \"sourcemap\": \"foo-*\"\r\n },\r\n
\"isSpaceAware\": true\r\n },\r\n```\r\n<img width=\"1826\"
alt=\"Screenshot 2024-02-28 at 17 47
12\"\r\nsrc=\"https://github.com/elastic/kibana/assets/55978943/e44d90ec-982c-4330-88dc-14f0f59bfce7\">\r\n\r\nSaved
Object after:\r\n```\r\n\"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\"\r\n },\r\n \"isSpaceAware\": true\r\n
},\r\n```\r\n\r\nThe API now accepts the `sourcemap`
param.","sha":"505b928dc1e30a70a2e4fe9d966e03174b2fbc2c"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177847","number":177847,"mergeCommit":{"message":"[APM]
Update Indices API to support sourcemap param (#177847)\n\ncloses
https://github.com/elastic/kibana/issues/177820\r\n\r\nSaved Object
before: \r\n\r\n```\r\n \"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\",\r\n \"sourcemap\": \"foo-*\"\r\n },\r\n
\"isSpaceAware\": true\r\n },\r\n```\r\n<img width=\"1826\"
alt=\"Screenshot 2024-02-28 at 17 47
12\"\r\nsrc=\"https://github.com/elastic/kibana/assets/55978943/e44d90ec-982c-4330-88dc-14f0f59bfce7\">\r\n\r\nSaved
Object after:\r\n```\r\n\"attributes\": {\r\n \"apmIndices\": {\r\n
\"onboarding\": \"caue\"\r\n },\r\n \"isSpaceAware\": true\r\n
},\r\n```\r\n\r\nThe API now accepts the `sourcemap`
param.","sha":"505b928dc1e30a70a2e4fe9d966e03174b2fbc2c"}}]}]
BACKPORT-->

---------

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Mar 4, 2024
1 parent a5f3d6a commit afa98a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x-pack/plugins/apm/server/routes/settings/apm_indices/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ const saveApmIndicesRoute = createApmServerRoute({
span: t.string,
transaction: t.string,
metric: t.string,
// Keeping this one here for backward compatibility
sourcemap: t.string,
} as SaveApmIndicesBodySchema),
}),
handler: async (resources): Promise<SavedObject<{}>> => {
const { params, context } = resources;
const { body } = params;
const savedObjectsClient = (await context.core).savedObjects.client;
return await saveApmIndices(savedObjectsClient, body);
const indices = { ...body };
if (indices.sourcemap) {
// Delete this as we stopped supporting it from 8.7.
delete indices.sourcemap;
}

return await saveApmIndices(savedObjectsClient, indices);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {
APMIndicesSavedObjectBody,
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
} from '@kbn/apm-data-access-plugin/server/saved_objects/apm_indices';
Expand Down Expand Up @@ -71,5 +72,27 @@ export default function apmIndicesTests({ getService }: FtrProviderContext) {
expect(readResponse.status).to.be(200);
expect(readResponse.body.transaction).to.eql(INDEX_VALUE);
});

it('updates apm indices removing legacy sourcemap', async () => {
const INDEX_VALUE = 'foo-*';

const writeResponse = await apmApiClient.writeUser({
endpoint: 'POST /internal/apm/settings/apm-indices/save',
params: {
body: { sourcemap: 'bar-*', transaction: INDEX_VALUE },
},
});
expect(writeResponse.status).to.be(200);
const savedAPMSavedObject = writeResponse.body
.attributes as Partial<APMIndicesSavedObjectBody>;
expect(savedAPMSavedObject.apmIndices?.transaction).to.eql(INDEX_VALUE);
expect(savedAPMSavedObject.apmIndices?.sourcemap).to.eql(undefined);

const readResponse = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/settings/apm-indices',
});
expect(readResponse.body.transaction).to.eql(INDEX_VALUE);
expect(readResponse.body.sourcemap).to.eql('apm-*');
});
});
}

0 comments on commit afa98a3

Please sign in to comment.