Skip to content

Commit 385b1ed

Browse files
maryam-saeidiJoseLuisGJ
authored andcommitted
[Custom threshold] Use createLazy instead of create when initializing searchSource (elastic#213904)
## Summary In this PR, we use a similar approach as was introduced in the ES Query rule in this [PR](elastic#183694) for the custom threshold rule to reduce the field_caps traffic using createLazy. (Thanks @mikecote for pointing this out!) ||Screenshot| |---|---| |Create (796 ms)|![image](https://github.com/user-attachments/assets/2df8f864-bbc5-44e4-af43-7ae70f5dd2c3)| |CreateLazy (321 ms)|![image](https://github.com/user-attachments/assets/cd9a6e51-af7e-411a-ab2e-5d7a2efd3ce5)| ### 🧪 How to test - Enable APM locally ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: username ``` - Create a custom threshold rule and check its execution in [traces](https://kibana-cloud-apm.elastic.dev/app/apm/traces?rangeFrom=now-15m&rangeTo=now) filtered for your `username` as the environment. There should be one with your rule name: <img src="https://github.com/user-attachments/assets/59274acc-3edf-4de7-8870-3b175af73523" width=500 /> The timing for `_field_caps` would be more if you replace the `createLazy` with the `create` function.
1 parent 2ee0e88 commit 385b1ed

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

x-pack/solutions/observability/plugins/observability/server/lib/rules/custom_threshold/custom_threshold_executor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const setup = () => {
183183
...alertsServices,
184184
getSearchSourceClient: jest.fn().mockResolvedValue({
185185
...searchSourceCommonMock,
186-
create: jest.fn(() => Promise.resolve(mockedSearchSource)),
186+
createLazy: jest.fn(() => Promise.resolve(mockedSearchSource)),
187187
}),
188188
};
189189

x-pack/solutions/observability/plugins/observability/server/lib/rules/custom_threshold/custom_threshold_executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const createCustomThresholdExecutor = ({
125125
)
126126
: [];
127127

128-
const initialSearchSource = await searchSourceClient.create(params.searchConfiguration);
128+
const initialSearchSource = await searchSourceClient.createLazy(params.searchConfiguration);
129129
const dataView = initialSearchSource.getField('index')!;
130130
const { id: dataViewId, timeFieldName } = dataView;
131131
const runtimeMappings = dataView.getRuntimeMappings();

0 commit comments

Comments
 (0)