@@ -8,6 +8,7 @@ import { createAgentAction } from './actions';
88import { SavedObject } from 'kibana/server' ;
99import { AgentAction } from '../../../common/types/models' ;
1010import { savedObjectsClientMock } from 'src/core/server/mocks' ;
11+ import { esKuery } from '../../../../../../src/plugins/data/server' ;
1112
1213describe ( 'test agent actions services' , ( ) => {
1314 it ( 'should create a new action' , async ( ) => {
@@ -35,3 +36,71 @@ describe('test agent actions services', () => {
3536 expect ( createdAction ?. sent_at ) . toEqual ( newAgentAction . sent_at ) ;
3637 } ) ;
3738} ) ;
39+
40+ class Benchmark {
41+ private static NS_PER_SEC = 1e9 ;
42+ #startTime?: [ number , number ] ;
43+ #elapsed?: [ number , number ] ;
44+
45+ start ( ) {
46+ if ( this . #startTime) {
47+ throw new Error ( `Start?? We're started, we can't start again!` ) ;
48+ }
49+
50+ this . #startTime = process . hrtime ( ) ;
51+ }
52+ stop ( ) {
53+ if ( this . #startTime == null ) {
54+ throw new Error ( `Stop?? We haven't even started yet!` ) ;
55+ }
56+
57+ this . #elapsed = process . hrtime ( this . #startTime) ;
58+ }
59+
60+ describe ( ) {
61+ if ( this . #elapsed == null ) {
62+ return `Benchmark is still running` ;
63+ }
64+
65+ return `Benchmark took ${
66+ this . #elapsed[ 0 ] * Benchmark . NS_PER_SEC + this . #elapsed[ 1 ]
67+ } nanoseconds`;
68+ }
69+ }
70+
71+ describe ( 'micro-benchmark' , ( ) => {
72+ test ( 'parsing KQL expression' , ( ) => {
73+ const b = new Benchmark ( ) ;
74+ b . start ( ) ;
75+ esKuery . fromKueryExpression (
76+ 'not fleet-agent-actions.attributes.sent_at: * and fleet-agent-actions.attributes.agent_id:1234567'
77+ ) ;
78+ b . stop ( ) ;
79+ console . log ( b . describe ( ) ) ;
80+ } ) ;
81+
82+ test ( 'manually building KueryNode' , ( ) => {
83+ const b = new Benchmark ( ) ;
84+ b . start ( ) ;
85+ esKuery . nodeTypes . function . buildNode ( 'and' , [
86+ esKuery . nodeTypes . function . buildNode (
87+ 'not' ,
88+ esKuery . nodeTypes . function . buildNode ( 'is' , 'fleet-agent-actions.attributes.sent_at' , '*' )
89+ ) ,
90+ esKuery . nodeTypes . function . buildNode (
91+ 'is' ,
92+ 'fleet-agent-actions.attributes.agent_id' ,
93+ '1234567'
94+ ) ,
95+ ] ) ;
96+ b . stop ( ) ;
97+ console . log ( b . describe ( ) ) ;
98+ } ) ;
99+
100+ test ( 'doing nothing' , ( ) => {
101+ const b = new Benchmark ( ) ;
102+ b . start ( ) ;
103+ b . stop ( ) ;
104+ console . log ( b . describe ( ) ) ;
105+ } ) ;
106+ } ) ;
0 commit comments