Skip to content
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

[Observability RAC] Remove indexing of rule evaluation documents #104970

Merged
merged 4 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } from './utils/create_lifecycle_rule_type_factory';
export {
LifecycleRuleExecutor,
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