diff --git a/test/analytics/plugins/analytics_ftr_helpers/server/plugin.ts b/test/analytics/plugins/analytics_ftr_helpers/server/plugin.ts index d4bf140aa4e62..f599f5651374b 100644 --- a/test/analytics/plugins/analytics_ftr_helpers/server/plugin.ts +++ b/test/analytics/plugins/analytics_ftr_helpers/server/plugin.ts @@ -14,7 +14,7 @@ import { fetchEvents } from '../common/fetch_events'; import { CustomShipper } from './custom_shipper'; export class AnalyticsFTRHelpers implements Plugin { - public setup({ analytics, http }: CoreSetup, deps: {}) { + public setup({ analytics, http }: CoreSetup, _deps: {}) { const { optIn, registerShipper } = analytics; const events$ = new ReplaySubject(); @@ -31,7 +31,7 @@ export class AnalyticsFTRHelpers implements Plugin { }), }, }, - (context, req, res) => { + (_context, req, res) => { const { consent } = req.query; optIn({ global: { enabled: consent } }); @@ -67,7 +67,7 @@ export class AnalyticsFTRHelpers implements Plugin { }), }, }, - async (context, req, res) => { + async (_context, req, res) => { const { takeNumberOfEvents, ...options } = req.query; const events = await fetchEvents(events$, takeNumberOfEvents, options); return res.ok({ body: events }); @@ -82,10 +82,25 @@ export class AnalyticsFTRHelpers implements Plugin { eventTypes: schema.arrayOf(schema.string()), withTimeoutMs: schema.number(), fromTimestamp: schema.maybe(schema.string()), + filters: schema.maybe( + schema.recordOf( + schema.string(), + schema.recordOf( + schema.oneOf([ + schema.literal('eq'), + schema.literal('gte'), + schema.literal('gt'), + schema.literal('lte'), + schema.literal('lt'), + ]), + schema.any() + ) + ) + ), }), }, }, - async (context, req, res) => { + async (_context, req, res) => { const events = await fetchEvents(events$, Number.MAX_SAFE_INTEGER, req.query); return res.ok({ body: { count: events.length } }); } diff --git a/test/analytics/services/kibana_ebt.ts b/test/analytics/services/kibana_ebt.ts index f2b635dcbdbbe..925bdece221d3 100644 --- a/test/analytics/services/kibana_ebt.ts +++ b/test/analytics/services/kibana_ebt.ts @@ -28,7 +28,7 @@ export function KibanaEBTServerProvider({ getService }: FtrProviderContext): EBT setOptIn, getEvents: async ( takeNumberOfEvents, - { eventTypes = [], withTimeoutMs, fromTimestamp } = {} + { eventTypes = [], withTimeoutMs, fromTimestamp, filters } = {} ) => { await setOptIn(true); const resp = await supertest @@ -38,6 +38,7 @@ export function KibanaEBTServerProvider({ getService }: FtrProviderContext): EBT eventTypes: JSON.stringify(eventTypes), withTimeoutMs, fromTimestamp, + filters: JSON.stringify(filters), }) .set('kbn-xsrf', 'xxx') .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') @@ -45,11 +46,16 @@ export function KibanaEBTServerProvider({ getService }: FtrProviderContext): EBT return resp.body; }, - getEventCount: async ({ eventTypes = [], withTimeoutMs, fromTimestamp }) => { + getEventCount: async ({ eventTypes = [], withTimeoutMs, fromTimestamp, filters }) => { await setOptIn(true); const resp = await supertest .get(`/internal/analytics_ftr_helpers/count_events`) - .query({ eventTypes: JSON.stringify(eventTypes), withTimeoutMs, fromTimestamp }) + .query({ + eventTypes: JSON.stringify(eventTypes), + withTimeoutMs, + fromTimestamp, + filters: JSON.stringify(filters), + }) .set('kbn-xsrf', 'xxx') .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') .expect(200); diff --git a/test/analytics/tests/analytics_from_the_server.ts b/test/analytics/tests/analytics_from_the_server.ts index af15d083419a3..bb1df0735107e 100644 --- a/test/analytics/tests/analytics_from_the_server.ts +++ b/test/analytics/tests/analytics_from_the_server.ts @@ -203,6 +203,30 @@ export default function ({ getService }: FtrProviderContext) { }); expect(eventCount).to.be(1); }); + it('should return 0 events when filtering by invalid properties', async () => { + const eventCount = await ebtServerHelper.getEventCount({ + withTimeoutMs: 500, + eventTypes: ['test-plugin-lifecycle'], + filters: { + 'properties.plugin': { + eq: 'analyticsPluginB', + }, + }, + }); + expect(eventCount).to.be(0); + }); + it('should return 1 event when filtering by valid properties', async () => { + const eventCount = await ebtServerHelper.getEventCount({ + withTimeoutMs: 500, + eventTypes: ['test-plugin-lifecycle'], + filters: { + 'properties.step': { + eq: 'start', + }, + }, + }); + expect(eventCount).to.be(1); + }); }); }); });