Skip to content

Commit

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

Saved Object before: 

```
 "attributes": {
    "apmIndices": {
      "onboarding": "caue",
      "sourcemap": "foo-*"
    },
    "isSpaceAware": true
  },
```
<img width="1826" alt="Screenshot 2024-02-28 at 17 47 12"
src="https://github.com/elastic/kibana/assets/55978943/e44d90ec-982c-4330-88dc-14f0f59bfce7">

Saved Object after:
```
"attributes": {
    "apmIndices": {
      "onboarding": "caue"
    },
    "isSpaceAware": true
  },
```

The API now accepts the `sourcemap` param.
  • Loading branch information
cauemarcondes authored Mar 4, 2024
1 parent bf5634f commit 505b928
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/observability_solution/apm/scripts/test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ if (server) {
const cmd = [
'node',
...(inspect ? ['--inspect-brk'] : []),
`../../../../../scripts/${ftrScript}`,
`../../../../../../scripts/${ftrScript}`,
...(grep ? [`--grep "${grep}"`] : []),
...(updateSnapshots ? [`--updateSnapshots`] : []),
...(bail ? [`--bail`] : []),
`--config ../../../../test/apm_api_integration/${license}/config.ts`,
`--config ../../../../../test/apm_api_integration/${license}/config.ts`,
].join(' ');

console.log(`Running: "${cmd}"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if (cypressCliArgs.grep) {
}

const spawnArgs = [
`../../../../scripts/${ftrScript}`,
`../../../../../scripts/${ftrScript}`,
`--config=./ftr_config.ts`,
`--kibana-install-dir=${argv.kibanaInstallDir}`,
...(argv.bail ? [`--bail`] : []),
Expand Down
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 505b928

Please sign in to comment.