Skip to content

Commit

Permalink
[Observability RAC] Remove indexing of rule evaluation documents (ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort authored and kibanamachine committed Jul 19, 2021
1 parent 0a80918 commit 0a0ff6c
Show file tree
Hide file tree
Showing 7 changed files with 400 additions and 90 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/rule_registry/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type { RuleRegistryPluginSetupContract, RuleRegistryPluginStartContract }
export type { RacRequestHandlerContext, RacApiRequestHandlerContext } from './types';
export { RuleDataClient } from './rule_data_client';
export { IRuleDataClient } from './rule_data_client/types';
export { getRuleExecutorData, RuleExecutorData } from './utils/get_rule_executor_data';
export { getRuleData, RuleExecutorData } from './utils/get_rule_executor_data';
export {
createLifecycleRuleTypeFactory,
LifecycleAlertService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,37 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Assign } from '@kbn/utility-types';
import { PublicContract } from '@kbn/utility-types';
import type { RuleDataClient } from '.';
import { RuleDataReader, RuleDataWriter } from './types';

type MockInstances<T extends Record<string, any>> = {
[K in keyof T]: T[K] extends (...args: infer TArgs) => infer TReturn
? jest.MockInstance<TReturn, TArgs>
? jest.MockInstance<TReturn, TArgs> & T[K]
: never;
};

export function createRuleDataClientMock() {
type RuleDataClientMock = jest.Mocked<
Omit<PublicContract<RuleDataClient>, 'getWriter' | 'getReader'>
> & {
getWriter: (...args: Parameters<RuleDataClient['getWriter']>) => MockInstances<RuleDataWriter>;
getReader: (...args: Parameters<RuleDataClient['getReader']>) => MockInstances<RuleDataReader>;
};

export function createRuleDataClientMock(): RuleDataClientMock {
const bulk = jest.fn();
const search = jest.fn();
const getDynamicIndexPattern = jest.fn();

return ({
createOrUpdateWriteTarget: jest.fn(({ namespace }) => Promise.resolve()),
getReader: jest.fn(() => ({
return {
createWriteTargetIfNeeded: jest.fn(({}) => Promise.resolve()),
getReader: jest.fn((_options?: { namespace?: string }) => ({
getDynamicIndexPattern,
search,
})),
getWriter: jest.fn(() => ({
bulk,
})),
isWriteEnabled: jest.fn(() => true),
} as unknown) as Assign<
RuleDataClient & Omit<MockInstances<RuleDataClient>, 'options' | 'getClusterClient'>,
{
getWriter: (
...args: Parameters<RuleDataClient['getWriter']>
) => MockInstances<RuleDataWriter>;
getReader: (
...args: Parameters<RuleDataClient['getReader']>
) => MockInstances<RuleDataReader>;
}
>;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface RuleDataWriter {
export interface IRuleDataClient {
getReader(options?: { namespace?: string }): RuleDataReader;
getWriter(options?: { namespace?: string }): RuleDataWriter;
isWriteEnabled(): boolean;
createWriteTargetIfNeeded(options: { namespace?: string }): Promise<void>;
}

Expand Down
Loading

0 comments on commit 0a0ff6c

Please sign in to comment.