-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Adding endpoint to upload android map files #161252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LikeTheSalad
merged 38 commits into
elastic:main
from
LikeTheSalad:uploading-android-map-files
Aug 1, 2023
Merged
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7e1ebf3
Adding android upload map validation
LikeTheSalad fb4002b
Adding same service name and version android map files
LikeTheSalad a995b4f
Setting android upload map endpoint body max size to 30 MB
LikeTheSalad f670716
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 6ea4d39
Fixing lint issues
LikeTheSalad 91e0b8b
Merge branch 'main' into uploading-android-map-files
LikeTheSalad 271b757
Fixing type issues
LikeTheSalad e05b441
Adding | undefined to test return type
LikeTheSalad 4366939
Update x-pack/plugins/apm/server/routes/source_maps/route.ts
LikeTheSalad 5dceb1c
Merge branch 'uploading-android-map-files' of github.com:LikeTheSalad…
LikeTheSalad 1eaef79
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine a593a12
Fixing maxBytes value for sourcemaps upload endpoint
LikeTheSalad 03bbf95
Merge branch 'uploading-android-map-files' of github.com:LikeTheSalad…
LikeTheSalad 588fa1a
Merge branch 'main' into uploading-android-map-files
kibanamachine 20a0e32
Merge branch 'main' into uploading-android-map-files
kibanamachine 740007b
Setting the sourcemaps and androidmaps endpoints max limit file size …
LikeTheSalad 13a1def
Adding documentation for the new android upload map endpoint
LikeTheSalad db098dd
Merge branch 'main' into uploading-android-map-files
kibanamachine 65052a0
Update docs/apm/api.asciidoc
LikeTheSalad 2d6bb59
Update docs/apm/api.asciidoc
LikeTheSalad 8ba1518
Update docs/apm/api.asciidoc
LikeTheSalad b285717
Update docs/apm/api.asciidoc
LikeTheSalad 356450f
Update docs/apm/api.asciidoc
LikeTheSalad 1b48fff
Update docs/apm/api.asciidoc
LikeTheSalad 74bf995
Update docs/apm/api.asciidoc
LikeTheSalad 82a1c13
Update docs/apm/api.asciidoc
LikeTheSalad 7dc2d44
Update docs/apm/api.asciidoc
LikeTheSalad 04ad479
Update docs/apm/api.asciidoc
LikeTheSalad 673eb18
Update docs/apm/api.asciidoc
LikeTheSalad 04dae25
Merge branch 'main' into uploading-android-map-files
kibanamachine 7c34a1a
Merge branch 'main' into uploading-android-map-files
kibanamachine c774db8
Update x-pack/plugins/apm/server/routes/source_maps/route.ts
LikeTheSalad 292b9ec
Removing unnecessary string conversion
LikeTheSalad 9bccc1d
Merge branch 'main' into uploading-android-map-files
kibanamachine 0676b19
Fixing typo
LikeTheSalad 083ed70
Merge branch 'uploading-android-map-files' of github.com:LikeTheSalad…
LikeTheSalad 37c7143
Renaming var to match type's name
LikeTheSalad 4d6160c
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,19 +9,24 @@ import { SavedObjectsClientContract } from '@kbn/core/server'; | |
| import { Artifact } from '@kbn/fleet-plugin/server'; | ||
| import { jsonRt, toNumberRt } from '@kbn/io-ts-utils'; | ||
| import * as t from 'io-ts'; | ||
| import { either } from 'fp-ts/lib/Either'; | ||
| import { ApmFeatureFlags } from '../../../common/apm_feature_flags'; | ||
| import { getInternalSavedObjectsClient } from '../../lib/helpers/get_internal_saved_objects_client'; | ||
| import { stringFromBufferRt } from '../../utils/string_from_buffer_rt'; | ||
| import { createApmServerRoute } from '../apm_routes/create_apm_server_route'; | ||
| import { | ||
| createFleetSourceMapArtifact, | ||
| createFleetAndroidMapArtifact, | ||
| deleteFleetSourcemapArtifact, | ||
| getCleanedBundleFilePath, | ||
| listSourceMapArtifacts, | ||
| ListSourceMapArtifactsResponse, | ||
| updateSourceMapsOnFleetPolicies, | ||
| } from '../fleet/source_maps'; | ||
| import { createApmSourceMap } from './create_apm_source_map'; | ||
| import { | ||
| createApmSourceMap, | ||
| createApmAndroidMap, | ||
| } from './create_apm_source_map'; | ||
| import { deleteApmSourceMap } from './delete_apm_sourcemap'; | ||
| import { runFleetSourcemapArtifactsMigration } from './schedule_source_map_migration'; | ||
|
|
||
|
|
@@ -41,6 +46,24 @@ export const sourceMapRt = t.intersection([ | |
|
|
||
| export type SourceMap = t.TypeOf<typeof sourceMapRt>; | ||
|
|
||
| const androidMapValidation = new t.Type<string, string, unknown>( | ||
| 'ANDROID_MAP_VALIDATION', | ||
| t.string.is, | ||
| (input, context): t.Validation<string> => | ||
| either.chain( | ||
| t.string.validate(input, context), | ||
| (str): t.Validation<string> => { | ||
| const firstLine = str.split('\n', 1)[0]; | ||
| if (firstLine.trim() === '# compiler: R8') { | ||
| return t.success(str); | ||
| } else { | ||
| return t.failure(input, context); | ||
| } | ||
| } | ||
| ), | ||
| (a): string => a | ||
| ); | ||
|
|
||
| function throwNotImplementedIfSourceMapNotAvailable( | ||
| featureFlags: ApmFeatureFlags | ||
| ): void { | ||
|
|
@@ -169,6 +192,85 @@ const uploadSourceMapRoute = createApmServerRoute({ | |
| }, | ||
| }); | ||
|
|
||
| const uploadAndroidMapRoute = createApmServerRoute({ | ||
| endpoint: 'POST /api/apm/androidmaps 2023-10-31', | ||
| options: { | ||
| tags: ['access:apm', 'access:apm_write'], | ||
| body: { accepts: ['multipart/form-data'], maxBytes: 30 * 1024 * 1024 }, | ||
| }, | ||
| params: t.type({ | ||
| body: t.type({ | ||
| service_name: t.string, | ||
| service_version: t.string, | ||
| map_file: t | ||
| .union([t.string, stringFromBufferRt]) | ||
| .pipe(androidMapValidation), | ||
| }), | ||
| }), | ||
| handler: async ({ | ||
| params, | ||
| plugins, | ||
| core, | ||
| logger, | ||
| featureFlags, | ||
| }): Promise<Artifact | undefined> => { | ||
| throwNotImplementedIfSourceMapNotAvailable(featureFlags); | ||
|
|
||
| const { | ||
| service_name: serviceName, | ||
| service_version: serviceVersion, | ||
| map_file: sourceMapContent, | ||
| } = params.body; | ||
| const bundleFilePath = 'android'; | ||
| const fleetPluginStart = await plugins.fleet?.start(); | ||
| const coreStart = await core.start(); | ||
| const internalESClient = coreStart.elasticsearch.client.asInternalUser; | ||
| const savedObjectsClient = await getInternalSavedObjectsClient(coreStart); | ||
| try { | ||
| if (fleetPluginStart) { | ||
| // create source map as fleet artifact | ||
| const artifact = await createFleetAndroidMapArtifact({ | ||
| fleetPluginStart, | ||
| apmArtifactBody: { | ||
| serviceName, | ||
| serviceVersion, | ||
| bundleFilepath: bundleFilePath, | ||
LikeTheSalad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sourceMap: sourceMapContent, | ||
| }, | ||
| }); | ||
|
|
||
| // sync source map to APM managed index | ||
| await createApmAndroidMap({ | ||
| internalESClient, | ||
| logger, | ||
| fleetId: artifact.id, | ||
| created: artifact.created, | ||
| mapContent: sourceMapContent, | ||
| bundleFilepath: bundleFilePath.toString(), | ||
|
||
| serviceName, | ||
| serviceVersion, | ||
| }); | ||
|
|
||
| // sync source map to fleet policy | ||
| await updateSourceMapsOnFleetPolicies({ | ||
| coreStart, | ||
| fleetPluginStart, | ||
| savedObjectsClient: | ||
| savedObjectsClient as unknown as SavedObjectsClientContract, | ||
| internalESClient, | ||
| }); | ||
|
|
||
| return artifact; | ||
| } | ||
| } catch (e) { | ||
| throw Boom.internal( | ||
| 'Something went wrong while creating a new android map', | ||
| e | ||
| ); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| const deleteSourceMapRoute = createApmServerRoute({ | ||
| endpoint: 'DELETE /api/apm/sourcemaps/{id} 2023-10-31', | ||
| options: { tags: ['access:apm', 'access:apm_write'] }, | ||
LikeTheSalad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -230,5 +332,6 @@ export const sourceMapsRouteRepository = { | |
| ...listSourceMapRoute, | ||
| ...uploadSourceMapRoute, | ||
| ...deleteSourceMapRoute, | ||
| ...uploadAndroidMapRoute, | ||
| ...migrateFleetArtifactsSourceMapRoute, | ||
| }; | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add docs for this one? (Example: https://www.elastic.co/guide/en/kibana/current/apm-api.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gbamparop - I've just added docs for the overall Android source map API. There are lots of similarities with the RUM one, which is why I took a lot of the parts involved in that part of the doc file. I'm not sure if my approach is the right one, so please have a look just in case there might be a better way to handle it. I'm also looping @bmorelli25 in, in case he's got some inputs as well.