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 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 added the release_note:skip Skip the PR/issue when compiling release notes label Nov 2, 2019
@ogupte ogupte requested review from rudolf and legrego November 2, 2019 07:19
@ogupte ogupte requested a review from a team as a code owner November 2, 2019 07:19
@ogupte ogupte self-assigned this Nov 2, 2019
@ogupte ogupte added the v7.6.0 label Nov 2, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@sorenlouv
Copy link
Member

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

};
}

export async function storeApmTelemetry(
Copy link
Member

@sorenlouv sorenlouv Nov 6, 2019

Choose a reason for hiding this comment

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

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, {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this use the constant APM_TELEMETRY_DOC_ID?

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

Copy link
Member

@sorenlouv sorenlouv Nov 11, 2019

Choose a reason for hiding this comment

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

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';

Copy link
Member

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

constant APM_TELEMETRY_DOC_ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@sorenlouv sorenlouv Nov 11, 2019

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

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 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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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 apm-49993-saved-objects-client-req-context branch from 6ccb72c to b3a4c08 Compare November 12, 2019 00:30
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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

💚 Build Succeeded

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@ogupte ogupte Nov 12, 2019

Choose a reason for hiding this comment

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

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.

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

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 apm-49993-saved-objects-client-req-context branch from 561445c to 81ceef9 Compare November 12, 2019 23:04
- 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 apm-49993-saved-objects-client-req-context branch from 81ceef9 to fca8cef Compare November 13, 2019 22:19
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@ogupte ogupte merged commit cd67add into elastic:master Nov 14, 2019
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.
@ogupte ogupte removed their assignment Jan 15, 2020
@dgieselaar dgieselaar self-assigned this Jan 21, 2020
@dgieselaar
Copy link
Member

Functionality was tested as part of #53541.

@dgieselaar dgieselaar added the apm:test-plan-done Pull request that was successfully tested during the test plan label Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:test-plan-done Pull request that was successfully tested during the test plan release_note:skip Skip the PR/issue when compiling release notes v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Use SavedObjectsClient from the request context for APM indices APIs
5 participants