From 41e4fcd6753d808bb193f6ac42309bb67308598b Mon Sep 17 00:00:00 2001 From: John Schulz Date: Tue, 16 Jun 2020 18:05:39 -0400 Subject: [PATCH] Don't use filter to get default config & output (#69088) (#69325) * Don't use filter to get default config & output the KQL parsing takes up a lot of CPU time. Avoid it with a search string Also add a `refresh: false` as suggested by @bkobel * Does restoring await fix CI? * Remove 'refresh: false' from agent enroll Does this this fix the failing test? It does keep the PR more focused Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../server/services/agent_config.ts | 3 ++- .../ingest_manager/server/services/output.ts | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts index 5172d372d7be3..18d5d8dedfb1f 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts @@ -284,7 +284,8 @@ class AgentConfigService { public async getDefaultAgentConfigId(soClient: SavedObjectsClientContract) { const configs = await soClient.find({ type: AGENT_CONFIG_SAVED_OBJECT_TYPE, - filter: `${AGENT_CONFIG_SAVED_OBJECT_TYPE}.attributes.is_default:true`, + searchFields: ['is_default'], + search: 'true', }); if (configs.saved_objects.length === 0) { diff --git a/x-pack/plugins/ingest_manager/server/services/output.ts b/x-pack/plugins/ingest_manager/server/services/output.ts index b70578efe468c..b4af231024370 100644 --- a/x-pack/plugins/ingest_manager/server/services/output.ts +++ b/x-pack/plugins/ingest_manager/server/services/output.ts @@ -14,11 +14,16 @@ const SAVED_OBJECT_TYPE = OUTPUT_SAVED_OBJECT_TYPE; let cachedAdminUser: null | { username: string; password: string } = null; class OutputService { - public async ensureDefaultOutput(soClient: SavedObjectsClientContract) { - const outputs = await soClient.find({ + public async getDefaultOutput(soClient: SavedObjectsClientContract) { + return await soClient.find({ type: OUTPUT_SAVED_OBJECT_TYPE, - filter: `${OUTPUT_SAVED_OBJECT_TYPE}.attributes.is_default:true`, + searchFields: ['is_default'], + search: 'true', }); + } + + public async ensureDefaultOutput(soClient: SavedObjectsClientContract) { + const outputs = await this.getDefaultOutput(soClient); const cloud = appContextService.getCloud(); const cloudId = cloud?.isCloudEnabled && cloud.cloudId; const cloudUrl = cloudId && decodeCloudId(cloudId)?.elasticsearchUrl; @@ -50,10 +55,7 @@ class OutputService { } public async getDefaultOutputId(soClient: SavedObjectsClientContract) { - const outputs = await soClient.find({ - type: OUTPUT_SAVED_OBJECT_TYPE, - filter: `${OUTPUT_SAVED_OBJECT_TYPE}.attributes.is_default:true`, - }); + const outputs = await this.getDefaultOutput(soClient); if (!outputs.saved_objects.length) { return null;