-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[APM] Use SavedObjectsClient from the request context for APM indices endpoints #49994
Conversation
💚 Build Succeeded
|
Thanks for looking into this! I'll take a better look after EAH but overall looks good 👍 |
}; | ||
} | ||
|
||
export async function storeApmTelemetry( |
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.
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, { |
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.
Shouldn't this use the constant APM_TELEMETRY_DOC_ID
?
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 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.
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 think having two constants makes sense. You did something similar of ui indices:
kibana/x-pack/legacy/plugins/apm/server/lib/settings/apm_indices/get_apm_indices.ts
Lines 26 to 27 in 1cc2a34
export const APM_INDICES_SAVED_OBJECT_TYPE = 'apm-indices'; | |
export const APM_INDICES_SAVED_OBJECT_ID = 'apm-indices'; |
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'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', |
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.
constant APM_TELEMETRY_DOC_ID
?
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.
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'; |
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.
Is it possible to rename this to apm-services-telemetry
to indicate it is not all apm telemetry data?
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 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.
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.
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.
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.
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.
|
||
export async function createApmAgentConfigurationIndex( | ||
core: InternalCoreSetup | ||
) { | ||
try { | ||
const { server } = core.http; | ||
const indices = await getApmIndices(server); | ||
const config = server.config(); | ||
const savedObjectsClient = getSavedObjectsClient(server); |
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.
What do you think about renaming this to:
const savedObjectsClient = getSavedObjectsClient(server); | |
const unscopedSavedObjectsClient = getUnscopedSavedObjectsClient(server); |
Or perhaps:
const savedObjectsClient = getSavedObjectsClient(server); | |
const internalSavedObjectsClient = getInternalSavedObjectsClient(server); |
Just to make the distinction between the "scoped" (getScopedSavedObjectsClient
) and unscoped saved objects client really obvious.
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. 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?
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 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.
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 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?
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.
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.
x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_agent_config_index.ts
Show resolved
Hide resolved
6ccb72c
to
b3a4c08
Compare
💚 Build Succeeded
|
b3a4c08
to
561445c
Compare
💚 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'; |
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.
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': { |
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 know I asked for this but I gotta ask: will this cause migration issues?
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 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.
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.
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.
561445c
to
81ceef9
Compare
- 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.
81ceef9
to
fca8cef
Compare
💚 Build Succeeded |
…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.
…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.
Functionality was tested as part of #53541. |
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.