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] Use SavedObjectsClient from the request context for APM indices endpoints #49994

Merged

Conversation

@ogupte
Copy link
Contributor

ogupte commented Nov 2, 2019

Closes #49993

Updated APM Indices endpoints to use the SavedObjectsClient from the legacy request context, and set the apm-indices schema object to be namspace-agnostic.

@ogupte ogupte requested review from rudolf and legrego Nov 2, 2019
@ogupte ogupte requested a review from elastic/apm-ui as a code owner Nov 2, 2019
@ogupte ogupte self-assigned this Nov 2, 2019
@ogupte ogupte added the v7.6.0 label Nov 2, 2019
@elasticmachine

This comment has been minimized.

Copy link
Contributor

elasticmachine commented Nov 2, 2019

@sqren

This comment has been minimized.

Copy link
Member

sqren commented Nov 3, 2019

Thanks for looking into this! I'll take a better look after EAH but overall looks good 👍

};
}

export async function storeApmTelemetry(

This comment has been minimized.

Copy link
@sqren

sqren Nov 6, 2019

Member

Can you rename this, so it's clear that it's just telemetry for the service overview page and not apm telemetry in general? Something like storeApmServicesTelemetry

) {
try {
const savedObjectsClient = getSavedObjectsClient(server);
await savedObjectsClient.create('apm-telemetry', apmTelemetry, {

This comment has been minimized.

Copy link
@sqren

sqren Nov 6, 2019

Member

Shouldn't this use the constant APM_TELEMETRY_DOC_ID?

This comment has been minimized.

Copy link
@ogupte

ogupte Nov 11, 2019

Author Contributor

I didn't do this because it would conflate the saved object type (the string literal) with the saved object id (the constant). I could alternatively make a second constant APM_TELEMETRY_SAVED_OBJ_TYPE or rename APM_TELEMETRY_DOC_ID to APM_TELEMETRY_DOC_ID_AND_SAVED_OBJ_TYPE and use it in both places.

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

I think having two constants makes sense. You did something similar of ui indices:

export const APM_INDICES_SAVED_OBJECT_TYPE = 'apm-indices';
export const APM_INDICES_SAVED_OBJECT_ID = 'apm-indices';

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

I'm wondering if it's better to have a apm_saved_object_constants.ts file where all saved objects are defined?

const savedObjectsClient = getSavedObjectsClient(server);
try {
const apmTelemetrySavedObject = await savedObjectsClient.get(
'apm-telemetry',

This comment has been minimized.

Copy link
@sqren

sqren Nov 6, 2019

Member

constant APM_TELEMETRY_DOC_ID?

This comment has been minimized.

import { InternalCoreSetup } from 'src/core/server';
import { isAgentName } from '../../../common/agent_name';
import { getSavedObjectsClient } from '../helpers/saved_objects_client';
export const APM_TELEMETRY_DOC_ID = 'apm-telemetry';

This comment has been minimized.

Copy link
@sqren

sqren Nov 6, 2019

Member

Is it possible to rename this to apm-services-telemetry to indicate it is not all apm telemetry data?

This comment has been minimized.

Copy link
@ogupte

ogupte Nov 11, 2019

Author Contributor

Yes we can do this, but it might be better to do this in the next minor version since we're so close to release, and I don't want to alarm folks by triggering a re-mapping of apm saved-objects.

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

since we're so close to release, and I don't want to alarm folks by triggering a re-mapping of apm saved-objects

I think I said 7.5 as well at some point but APM UI Indices is in 7.6, not 7.5, right? So this should go into 7.x not 7.5.

This comment has been minimized.

Copy link
@ogupte

ogupte Nov 12, 2019

Author Contributor

This PR is targeted for 7.5, so I'm hesitant to make that change here, but sure i can do it in a another PR targeted for 7.x.

@ogupte ogupte added v7.5.0 and removed v7.6.0 labels Nov 6, 2019

export async function createApmAgentConfigurationIndex(
core: InternalCoreSetup
) {
try {
const { server } = core.http;
const indices = await getApmIndices(server);
const config = server.config();
const savedObjectsClient = getSavedObjectsClient(server);

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

What do you think about renaming this to:

Suggested change
const savedObjectsClient = getSavedObjectsClient(server);
const unscopedSavedObjectsClient = getUnscopedSavedObjectsClient(server);

Or perhaps:

Suggested change
const savedObjectsClient = getSavedObjectsClient(server);
const internalSavedObjectsClient = getInternalSavedObjectsClient(server);

Just to make the distinction between the "scoped" (getScopedSavedObjectsClient) and unscoped saved objects client really obvious.

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

Btw. just like you can do server.savedObjects.getScopedSavedObjectsClient, is it also possible to do something like: server.savedObjects.getUnScopedSavedObjectsClient so we don't have to init our own?

This comment has been minimized.

Copy link
@rudolf

rudolf Nov 11, 2019

Contributor

I like the idea of making this more obvious, of the two options internalSavedObjectsClient would be more consistent with how we refer to it in other places.

This comment has been minimized.

Copy link
@sqren

sqren Nov 11, 2019

Member

Thanks for chiming in @rudolf! We'll stick to internalSavedObjectsClient then.
Btw. do you know if an instance of internalSavedObjectsClient already exists or do we need to instantiate our own?

This comment has been minimized.

Copy link
@rudolf

rudolf Nov 11, 2019

Contributor

you need to create your own like here, what APM is doing isn't wrong, but is unusual for Kibana plugins so there's no convenience factory for that. In the NP we will probably expose an internalRepository but not a internalSavedObjectsClient (they're almost the same, the repository just has a few more methods). The idea is to make it clear that you're doing something unusual and unless you have a special reason like a legacy architecture that doesn't support spaces or writing/reading telemetry data, you probably should use the scoped saved objects client.

@ogupte ogupte force-pushed the ogupte:apm-49993-saved-objects-client-req-context branch from 6ccb72c to b3a4c08 Nov 12, 2019
@elasticmachine

This comment has been minimized.

Copy link
Contributor

elasticmachine commented Nov 12, 2019

@ogupte ogupte added v7.6.0 and removed v7.5.0 labels Nov 12, 2019
@ogupte ogupte force-pushed the ogupte:apm-49993-saved-objects-client-req-context branch from b3a4c08 to 561445c Nov 12, 2019
@elasticmachine

This comment has been minimized.

Copy link
Contributor

elasticmachine commented Nov 12, 2019

'apm-services-telemetry';
export const APM_SERVICES_TELEMETRY_DOC_ID = 'apm-services-telemetry';
export const APM_INDICES_SAVED_OBJECT_TYPE = 'apm-indices';
export const APM_INDICES_DOC_ID = 'apm-indices';

This comment has been minimized.

Copy link
@sqren

sqren Nov 12, 2019

Member

WDYT about grouping them, and making the "id" constant naming consistent with the "type"?

// APM Services telemetry
export const APM_SERVICES_TELEMETRY_SAVED_OBJECT_TYPE = 'apm-services-telemetry';
export const APM_SERVICES_TELEMETRY_SAVED_OBJECT_ID = 'apm-services-telemetry';

// APM indices
export const APM_INDICES_SAVED_OBJECT_TYPE = 'apm-indices';
export const APM_INDICES_SAVED_OBJECT_ID = 'apm-indices';
@@ -48,7 +48,10 @@ export const apm: LegacyPluginInitializer = kibana => {
},
hacks: ['plugins/apm/hacks/toggle_app_link_in_nav'],
savedObjectSchemas: {
'apm-telemetry': {
'apm-services-telemetry': {

This comment has been minimized.

Copy link
@sqren

sqren Nov 12, 2019

Member

I know I asked for this but I gotta ask: will this cause migration issues?

This comment has been minimized.

Copy link
@ogupte

ogupte Nov 12, 2019

Author Contributor

It doesn't trigger a migration, as it's a different object type, but it would remove saved objects of the old type. This won't be an issue as the object is ephemeral, and only reference when triggered by the usage collector.

@sqren
sqren approved these changes Nov 12, 2019
Copy link
Member

sqren left a comment

LGTM. You should probably hold-off merging this until #50211 is merged since that's going into 7.5 and we better avoid delaying that with merge conflicts.

@ogupte ogupte force-pushed the ogupte:apm-49993-saved-objects-client-req-context branch from 561445c to 81ceef9 Nov 12, 2019
@ogupte ogupte referenced this pull request Nov 13, 2019
0 of 2 tasks complete
- move saved object types and document IDs to constants file
- Updated APM Indices endpoints to use the SavedObjectsClient from the
  legacy request context, and set the apm-indices schema object to be
  namspace-agnostic.
@ogupte ogupte force-pushed the ogupte:apm-49993-saved-objects-client-req-context branch from 81ceef9 to fca8cef Nov 13, 2019
@elasticmachine

This comment has been minimized.

Copy link
Contributor

elasticmachine commented Nov 13, 2019

@ogupte ogupte merged commit cd67add into elastic:master Nov 14, 2019
57 checks passed
57 checks passed
API integration tests node scripts/functional_tests --config test/api_integration/config.js --bail --debug
Details
Browser tests yarn run grunt test:browser-ci
Details
Build kbn_tp_sample_panel_action yarn build
Details
CLA All commits in pull request signed
Details
Check core API changes node scripts/check_core_api_changes
Details
Check file casing node scripts/check_file_casing --quiet
Details
Check licenses node scripts/check_licenses --dev
Details
Firefox smoke test node scripts/functional_tests --bail --debug --kibana-install-dir /dev/shm/workspace/kibana/build/oss/kibana-8.0.0-SNAPSHOT-linux-x86_64 --include-tag smoke --config test/functional/config.firefox.js
Details
Functional tests / Group 1 yarn run grunt run:functionalTests_ciGroup1
Details
Functional tests / Group 10 yarn run grunt run:functionalTests_ciGroup10
Details
Functional tests / Group 11 yarn run grunt run:functionalTests_ciGroup11
Details
Functional tests / Group 12 yarn run grunt run:functionalTests_ciGroup12
Details
Functional tests / Group 2 yarn run grunt run:functionalTests_ciGroup2
Details
Functional tests / Group 3 yarn run grunt run:functionalTests_ciGroup3
Details
Functional tests / Group 4 yarn run grunt run:functionalTests_ciGroup4
Details
Functional tests / Group 5 yarn run grunt run:functionalTests_ciGroup5
Details
Functional tests / Group 6 yarn run grunt run:functionalTests_ciGroup6
Details
Functional tests / Group 7 yarn run grunt run:functionalTests_ciGroup7
Details
Functional tests / Group 8 yarn run grunt run:functionalTests_ciGroup8
Details
Functional tests / Group 9 yarn run grunt run:functionalTests_ciGroup9
Details
Internationalization check node scripts/i18n_check --ignore-missing
Details
Interpreter functional tests node scripts/functional_tests --config test/interpreter_functional/config.js --bail --debug --kibana-install-dir /dev/shm/workspace/kibana/build/oss/kibana-8.0.0-SNAPSHOT-linux-x86_64-1
Details
Jest integration tests yarn run grunt test:jest_integration
Details
Jest tests yarn run grunt test:jest
Details
Kibana accessibility tests node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/kibana/build/oss/kibana-8.0.0-SNAPSHOT-linux-x86_64 --config test/accessibility/config.ts
Details
Kibana visual regression tests yarn run percy exec -t 500 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/kibana/build/oss/kibana-8.0.0-SNAPSHOT-linux-x86_64 --config test/visual_regression/config.ts
Details
Mocha tests node scripts/mocha
Details
Plugin functional tests node scripts/functional_tests --config test/plugin_functional/config.js --bail --debug --kibana-install-dir /dev/shm/workspace/kibana/build/oss/kibana-8.0.0-SNAPSHOT-linux-x86_64-1
Details
Project tests yarn run grunt test:projects
Details
Type check node scripts/type_check
Details
TypeScript - all files belong to a TypeScript project node scripts/check_ts_projects
Details
Verify NOTICE.txt node scripts/notice --validate
Details
Verify dependency versions yarn run grunt verifyDependencyVersions
Details
X-Pack Chrome Functional tests / Group 1 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-1 --include-tag ciGroup1
Details
X-Pack Chrome Functional tests / Group 10 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-10 --include-tag ciGroup10
Details
X-Pack Chrome Functional tests / Group 2 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-2 --include-tag ciGroup2
Details
X-Pack Chrome Functional tests / Group 3 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-3 --include-tag ciGroup3
Details
X-Pack Chrome Functional tests / Group 4 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-4 --include-tag ciGroup4
Details
X-Pack Chrome Functional tests / Group 5 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-5 --include-tag ciGroup5
Details
X-Pack Chrome Functional tests / Group 6 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-6 --include-tag ciGroup6
Details
X-Pack Chrome Functional tests / Group 7 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-7 --include-tag ciGroup7
Details
X-Pack Chrome Functional tests / Group 8 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-8 --include-tag ciGroup8
Details
X-Pack Chrome Functional tests / Group 9 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-9 --include-tag ciGroup9
Details
X-Pack Jest node scripts/jest --ci --verbose
Details
X-Pack Mocha yarn test
Details
X-Pack SIEM cyclic dependency test node legacy/plugins/siem/scripts/check_circular_deps
Details
X-Pack accessibility tests node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana --config test/accessibility/config.ts
Details
X-Pack firefox smoke test node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-11 --include-tag smoke --config test/functional/config.firefox.js
Details
X-Pack visual regression tests yarn run percy exec -t 500 node scripts/functional_tests --debug --bail --kibana-install-dir /dev/shm/workspace/install/kibana-13 --config test/visual_regression/config.js
Details
elasticsearch-ci/docs Build finished.
Details
eslint node scripts/eslint --no-cache
Details
kibana-ci Build finished.
Details
percy/kibana Visual review automatically approved, no visual changes found.
Details
prbot:outdated
prbot:release note labels
prbot:release version labels
sasslint node scripts/sasslint
Details
ogupte added a commit to ogupte/kibana that referenced this pull request Nov 14, 2019
…legacy request context, and set the apm-indices schema object to be namspace-agnostic

- rename apm-telemetry save object mapping -> apm-services-telemetry (elastic#49994)
- move saved object types and document IDs to constants file
- Updated APM Indices endpoints to use the SavedObjectsClient from the
  legacy request context, and set the apm-indices schema object to be
  namspace-agnostic.
ogupte added a commit that referenced this pull request Nov 14, 2019
…legacy request context, and set the apm-indices schema object to be namspace-agnostic (#50615)

- rename apm-telemetry save object mapping -> apm-services-telemetry (#49994)
- move saved object types and document IDs to constants file
- Updated APM Indices endpoints to use the SavedObjectsClient from the
  legacy request context, and set the apm-indices schema object to be
  namspace-agnostic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.