-
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
Manually building KueryNode
for Fleet's routes
#75693
Conversation
Nice the perf improvements seems significant 👍 |
@@ -37,6 +37,9 @@ import { SavedObjectUnsanitizedDoc } from './serialization'; | |||
import { SavedObjectsMigrationLogger } from './migrations/core/migration_logger'; | |||
import { SavedObject } from '../../types'; | |||
|
|||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | |||
import { KueryNode } from '../../../plugins/data/common'; |
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.
Refactoring this code to remove the circular reference became quite time-consuming. Since a circular reference already exists between core and the data plugin, I'd like to postpone fixing the circular reference to another PR to minimize the likelihood of this change not making 7.10.
This reverts commit 97e19c0.
Pinging @elastic/ingest-management (Team:Ingest Management) |
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
if (filter && filter.length > 0 && indexMapping) { | ||
const filterKueryNode = esKuery.fromKueryExpression(filter); | ||
if (filter && indexMapping) { | ||
const filterKueryNode = | ||
typeof filter === 'string' ? esKuery.fromKueryExpression(filter) : filter; |
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.
NIT: we are no longer ignoring empty string filters, but I guess this has no impact?
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.
Empty strings are still ignored, I added 195a5a1#diff-c5ab35755205b8adbf6cfc858d69ea3bR86-R88 to double-check this. JavaScript treats an empty-string as being falsy, so checking filter
and filter.length > 0
is redundant, we only need to check filter
.
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.
Wait what? Kibana is not Java code?
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.
Unfortunately, no... Maybe in the future though! New-new platform??
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.
We would need to find a more suitable codename if we switch to java. NewPlatformBijectiveAdapterFactory maybe.
@elasticmachine merge upstream |
💚 Build SucceededBuild metrics
History
To update your PR or re-run it, just comment with: |
* Simple benchmark tests for kuery * Building manually is "better" still not free * Building the KueryNode manually * Removing benchmark tests * Another query is building the KueryNode manually * Empty strings are inherently falsy * No longer reaching into the data plugin, import from the "root" indexes * Using AGENT_ACTION_SAVED_OBJECT_TYPE everywhere * Adding SavedObjectsRepository#find unit test for KueryNode * Adding KQL KueryNode test for validateConvertFilterToKueryNode * /s/KQL string/KQL expression * Updating API docs * Adding micro benchmark * Revert "Adding micro benchmark" This reverts commit 97e19c0. * Adding an empty string filters test Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
* master: (223 commits) skip flaky suite (elastic#75724) [Reporting] Add functional test for Reports in non-default spaces (elastic#76053) [Enterprise Search] Fix various icons in dark mode (elastic#76430) skip flaky suite (elastic#76245) Add `auto` interval to histogram AggConfig (elastic#76001) [Resolver] generator uses setup_node_env (elastic#76422) [Ingest Manager] Support both zip & tar archives from Registry (elastic#76197) [Ingest Manager] Improve agent vs kibana version checks (elastic#76238) Manually building `KueryNode` for Fleet's routes (elastic#75693) remove dupe tinymath section (elastic#76093) Create APM issue template (elastic#76362) Delete unused file. (elastic#76386) [SECURITY_SOLUTION][ENDPOINT] Trusted Apps Create API (elastic#76178) [Detections Engine] Add Alert actions to the Timeline (elastic#73228) [Dashboard First] Library Notification (elastic#76122) [Maps] Add mvt support for ES doc sources (elastic#75698) Add setHeaderActionMenu API to AppMountParameters (elastic#75422) [ML] Remove "Are you sure" from data frame analytics jobs (elastic#76214) [yarn] remove typings-tester, use @ts-expect-error (elastic#76341) [Reporting/CSV] Do not fail the job if scroll ID can not be cleared (elastic#76014) ...
Parsing a string to create the KQL query is computationally expensive. It accounted for nearly 17% of the CPU time when enrolling 1,000 agents using
fleet-loadtest
over 5 minutes.This approach manually builds the
KueryNode
, so we no longer have to do the string parsing, which was the most expensive part.Impact
Micro benchmark
6396334 nanoseconds
766089 nanoseconds
Shortest test
Running https://github.com/nchaulet/fleet-load-test-scenarios before these changes
And after
Short-test
Running
fleet-loadtest
withRATE=15 AGENTS=4000 go run main.go
until 200 agents checked-in and got their policyAfter these changes
This reduces the mean health check latency from
458.72ms
to257.06ms
Longer test
Running fleet-loadtest with RATE=15 AGENTS=2000 go run main.go until completion