Skip to content

Commit

Permalink
Don't use filter to get default config & output (#69088) (#69325)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
John Schulz and elasticmachine authored Jun 16, 2020
1 parent d4c48b0 commit 41e4fcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions x-pack/plugins/ingest_manager/server/services/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output>({
public async getDefaultOutput(soClient: SavedObjectsClientContract) {
return await soClient.find<Output>({
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 41e4fcd

Please sign in to comment.