-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] NP Migration - Moves plugin server files out of legacy #57532
[APM] NP Migration - Moves plugin server files out of legacy #57532
Conversation
0b888d4
to
6698349
Compare
const apmIndices = await framework.plugins.apm.getApmIndices( | ||
requestContext.core.savedObjects.client | ||
); | ||
const apmIndices = await framework.plugins.apm.getApmIndices(); |
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.
getApmIndices()
no longer requires a saved objects client to be passed in.
@@ -6,5 +6,5 @@ | |||
"configPath": ["xpack", "apm"], | |||
"ui": false, | |||
"requiredPlugins": ["apm_oss", "data", "home"], | |||
"optionalPlugins": ["cloud"] | |||
"optionalPlugins": ["cloud", "usageCollection"] |
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.
added usageCollection
plugin as an optional dependency for service telemetry
@@ -26,34 +25,28 @@ export function createApmTelementry( | |||
} | |||
|
|||
export async function storeApmServicesTelemetry( | |||
server: APMLegacyServer, | |||
savedObjectsClient: InternalSavedObjectsClient, |
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.
uses the savedObjectsClient directly rather than obtaining a new instance from the legacy kibana server
@@ -0,0 +1,16 @@ | |||
/* |
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.
smaller helper function to get the internal saved objects client from the core setup object since we do this in a few places.
context.__LEGACY.server | ||
); | ||
await internalSavedObjectsClient.create( | ||
const savedObjectsClient = context.core.savedObjects.client; |
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.
I changed this to a scoped saved object client, which used to be internal before. i tested it with the apm read user and it was able to persist the index pattern for discover/kuery bar/etc.
@@ -27,9 +27,8 @@ export async function saveApmIndices( | |||
|
|||
// remove empty/undefined values | |||
function removeEmpty(apmIndices: Partial<ApmIndicesConfig>) { | |||
return Object.fromEntries( |
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.
the reference to Object.fromEntries
produced a typescript error (maybe it's not fully supported?) so i just converted it to a reduce.
}) | ||
); | ||
|
||
const usageCollection = plugins.usageCollection; |
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.
the usage collector is now registered from the plugin setup, but it can't block setup since it depends on core start services, so it uses regular old Promise API.
const savedObjectsClient = await getInternalSavedObjectsClient(core); | ||
storeApmServicesTelemetry(savedObjectsClient, apmTelemetry).catch(error => { | ||
context.logger.error(error.message); | ||
}); |
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.
it was necessary to add a catch
here since the CI test saw an unresolved promise when there was a failure to persist telemetry attributes and failed CI.
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.
@watson I recall that you added this check (throw on unresolved promise) to the test runner. Did you also enable it at runtime in dev mode?
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.
when i ran the api integration tests locally, the same unresolved promise error shows in the server log, but the test runner did not mark it as a failure
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.
I was just thinking whether this also would throw during normal development and not just when running tests
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.
Yes, the check was added in #51431.
For CI the magic is here:
kibana/src/dev/ci_setup/setup_env.sh
Line 17 in 5bb2481
export NODE_OPTIONS="$NODE_OPTIONS --throw-deprecation" |
In dev-mode (when running yarn start
), the magic is here:
Line 56 in 5bb2481
"start": "node --trace-warnings --throw-deprecation scripts/kibana --dev", |
I intended it to run during dev-mode, so that developers would not be surprised by weird errors in CI that they might as well catch early on in development.
Note that if you manually run node scripts/kibana
it will not throw on deprecations.
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.
Btw, normally I would think that you should pass the error on to the UI so that the user could be notified that something went wrong instead of just logging it to STDERR. But I'm not sure what this code does and if it makes sense to do one or the other in this case. Just be sure you thought it through 🙂
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.
normally I would think that you should pass the error on to the UI so that the user could be notified that something went wrong instead of just logging it to STDERR.
Agree! However, the operation in this case is a background job which is implicitly initiated by the user but the response of the API doesn't rely on it.
@ogupte I think we talked about adding a comment to make this more obvious
@@ -7,7 +7,7 @@ | |||
import '../../infra/types/rison_node'; | |||
import '../../infra/types/eui'; | |||
// EUIBasicTable | |||
import {} from '../../reporting/public/components/report_listing'; | |||
import '../../reporting/public/components/report_listing'; |
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.
not sure how this was valid before
6698349
to
3ec54f2
Compare
x-pack/legacy/plugins/apm/public/components/app/ServiceMap/Popover/ServiceMetricList.tsx
Show resolved
Hide resolved
} from '../../server/lib/helpers/setup_request'; | ||
import { | ||
PROCESSOR_EVENT, | ||
SERVICE_NAME, | ||
ERROR_GROUP_ID | ||
} from '../elasticsearch_fieldnames'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { rangeFilter } from '../../server/lib/helpers/range_filter'; |
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.
Why is it forbidden to import from the server folder?
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.
Actually, I think the linter has a point: range_filter
should be moved to common
if it's consumed by something from common
.
context.__LEGACY.server | ||
); | ||
await internalSavedObjectsClient.create( | ||
await savedObjectsClient.create( |
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.
Looks much better 👍
@@ -12,7 +12,7 @@ import { | |||
SetupTimeRange, | |||
SetupUIFilters | |||
} from '../../../../helpers/setup_request'; | |||
import { fetchAndTransformGcMetrics } from './fetchAndTransformGcMetrics'; | |||
import { fetchAndTransformGcMetrics } from './fetch_and_transform_gc_metrics'; |
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 for fixing the casing everywhere 👍
export async function getInternalSavedObjectsClient(core: CoreSetup) { | ||
return core.getStartServices().then(async ([coreStart]) => { | ||
return coreStart.savedObjects.createInternalRepository(); | ||
}); |
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.
No biggie but any reason not to async/await
like everywhere else?
const [coreStart] = await core.getStartServices()
return coreStart.savedObjects.createInternalRepository();
fdcdb8d
to
d6b6314
Compare
Removed myself from the reviewers list since it looks like this doesn't touch the Maps app. Feel free to re-add me if I'm mistaken! |
d6b6314
to
7074e7b
Compare
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.
Infra changes LGTM 👍
and context scoped clients exposed in the new platform core setup
…ndices, and uses the internal saved objects client when creating apm index pattern, so that any user who navigates to apm can trigger it
7074e7b
to
b150999
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
cla/trigger |
…#57532) * Closes @56832 Migrates uses of the saved objects client to the internal and context scoped clients exposed in the new platform core setup * moves apm server, common, and typings dirs to the new plugin directory * fixes path imports and type errors * fixes some lint errors * fixes CI failure. Use internal saved objects client like before. * uses the context-scoped saved objects client for saving runtime APM indices, and uses the internal saved objects client when creating apm index pattern, so that any user who navigates to apm can trigger it * fixes the type check error by updating import paths * renamed files and directories to snake_case to pass scripts/check_file_casing * rebase fixes and commit filename case changes * moves get_indices_privileges.ts out of legacy path
…#58074) * Closes @56832 Migrates uses of the saved objects client to the internal and context scoped clients exposed in the new platform core setup * moves apm server, common, and typings dirs to the new plugin directory * fixes path imports and type errors * fixes some lint errors * fixes CI failure. Use internal saved objects client like before. * uses the context-scoped saved objects client for saving runtime APM indices, and uses the internal saved objects client when creating apm index pattern, so that any user who navigates to apm can trigger it * fixes the type check error by updating import paths * renamed files and directories to snake_case to pass scripts/check_file_casing * rebase fixes and commit filename case changes * moves get_indices_privileges.ts out of legacy path
* master: (136 commits) [Visualize] Remove legacy appState in visualize (elastic#57330) Use static time for tsvb rollup test (elastic#57701) [SIEM] Fix ResizeObserver polyfill (elastic#58046) [SIEM][Detection Engine] Fixes return codes where some were rule_id instead of id skip flaky suite (elastic#56816) skip flaky suite (elastic#58059) skip flaky suite (elastic#45348) migrates notification server routes to NP (elastic#57906) Moved all of the show/hide toggles outside of ordered lists. (elastic#57163) [APM] NP Migration - Moves plugin server files out of legacy (elastic#57532) [Maps][Telemetry] Migrate Maps telemetry to NP (elastic#55055) Embeddable add panel examples (elastic#57319) Fix useRequest to support query change (elastic#57723) Allow custom paths in plugin generator (elastic#57766) [SIEM][Case] Merge header components (elastic#57816) [ML] New Platform server shim: update job audit messages routes (elastic#57925) [kbn/optimizer] emit success event from reducer when all bundles cached (elastic#57945) [APM] Don’t include UI filters when fetching a specific transaction (elastic#57934) Upgrade yargs (elastic#57720) skip flaky suite (elastic#57762) (elastic#57997) (elastic#57998) ... # Conflicts: # src/plugins/advanced_settings/public/management_app/components/field/__snapshots__/field.test.tsx.snap # src/plugins/advanced_settings/public/management_app/components/field/field.tsx # x-pack/plugins/translations/translations/ja-JP.json # x-pack/plugins/translations/translations/zh-CN.json
Closes #56830
Move server files of the APM plugin from
x-pack/legacy/plugins/apm
->x-pack/plugins/apm
. This still initializes legacy plugin, but it allows us to very easily switch over to the new platform when we fully migrate the client app.Also Closes #56832
Migrates uses of the saved objects client API from the legacy references to those exposed on the CoreStart object. It removes the requirement to pass in a saved objects client to the
getApmIndices()
function exposed on the APM plugin.