Skip to content
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

Merged
merged 10 commits into from
Feb 19, 2020

Conversation

ogupte
Copy link
Contributor

@ogupte ogupte commented Feb 13, 2020

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.

@ogupte ogupte added release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Feb 13, 2020
@ogupte ogupte requested review from a team as code owners February 13, 2020 03:23
@ogupte ogupte force-pushed the apm-56830-np-migration-plugin-server branch from 0b888d4 to 6698349 Compare February 13, 2020 08:39
const apmIndices = await framework.plugins.apm.getApmIndices(
requestContext.core.savedObjects.client
);
const apmIndices = await framework.plugins.apm.getApmIndices();
Copy link
Contributor Author

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"]
Copy link
Contributor Author

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,
Copy link
Contributor Author

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 @@
/*
Copy link
Contributor Author

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;
Copy link
Contributor Author

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(
Copy link
Contributor Author

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;
Copy link
Contributor Author

@ogupte ogupte Feb 13, 2020

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);
});
Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor

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:

export NODE_OPTIONS="$NODE_OPTIONS --throw-deprecation"

In dev-mode (when running yarn start), the magic is here:

"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.

Copy link
Contributor

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 🙂

Copy link
Member

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';
Copy link
Contributor Author

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

@ogupte ogupte force-pushed the apm-56830-np-migration-plugin-server branch from 6698349 to 3ec54f2 Compare February 13, 2020 23:59
} 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';
Copy link
Member

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?

Copy link
Member

@sorenlouv sorenlouv Feb 14, 2020

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(
Copy link
Member

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';
Copy link
Member

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();
});
Copy link
Member

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();

@ogupte ogupte force-pushed the apm-56830-np-migration-plugin-server branch from fdcdb8d to d6b6314 Compare February 18, 2020 17:57
@spalger spalger requested a review from a team as a code owner February 18, 2020 17:57
@spalger spalger requested a review from a team February 18, 2020 17:57
@spalger spalger requested review from a team as code owners February 18, 2020 17:57
@spalger spalger requested review from kindsun and removed request for a team and kindsun February 18, 2020 18:14
@kindsun kindsun removed their request for review February 18, 2020 20:03
@kindsun
Copy link
Contributor

kindsun commented Feb 18, 2020

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!

@ogupte ogupte force-pushed the apm-56830-np-migration-plugin-server branch from d6b6314 to 7074e7b Compare February 19, 2020 01:00
Copy link
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infra changes LGTM 👍

@ogupte ogupte force-pushed the apm-56830-np-migration-plugin-server branch from 7074e7b to b150999 Compare February 19, 2020 18:01
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@ogupte
Copy link
Contributor Author

ogupte commented Feb 19, 2020

cla/trigger

@ogupte ogupte merged commit 96a0aa0 into elastic:master Feb 19, 2020
ogupte added a commit to ogupte/kibana that referenced this pull request Feb 20, 2020
…#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
ogupte added a commit that referenced this pull request Feb 20, 2020
…#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
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 20, 2020
* 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
v1v added a commit to v1v/apm-integration-testing that referenced this pull request Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes v7.7.0
Projects
None yet
7 participants