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

[Alerts] Replaces legacy es client with the ElasticsearchClient for alerts and triggers_actions_ui plugins. #93364

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
58a1e61
[Alerts] Replaces legasy es client with the ElasticsearchClient
YulNaumenko Mar 3, 2021
fe562d3
fixed build
YulNaumenko Mar 3, 2021
b411fbd
fixed build
YulNaumenko Mar 3, 2021
2e3b0ef
fixed ci build
YulNaumenko Mar 3, 2021
8881c3b
fixed ci build
YulNaumenko Mar 3, 2021
8e94717
fixed infra callCLuster
YulNaumenko Mar 3, 2021
2ecfc15
fixed infra callCLuster
YulNaumenko Mar 3, 2021
86f5d4b
fixed infra callCLuster
YulNaumenko Mar 5, 2021
29e64ef
fixed ci build
YulNaumenko Mar 5, 2021
c458fe5
Merge remote-tracking branch upstream/master
YulNaumenko Mar 5, 2021
4c9384b
fixed ci build
YulNaumenko Mar 6, 2021
3163f20
fixed ci build
YulNaumenko Mar 6, 2021
4242b1e
Merge remote-tracking branch upstream/master
YulNaumenko Mar 6, 2021
d40e90e
fixed infra tests
YulNaumenko Mar 6, 2021
176b8af
fixed security tests
YulNaumenko Mar 6, 2021
bec9e71
fixed security tests
YulNaumenko Mar 6, 2021
557c34c
fixed security tests
YulNaumenko Mar 6, 2021
07e6755
fixed tests
YulNaumenko Mar 7, 2021
585cca8
fixed monitoring unit tests
YulNaumenko Mar 7, 2021
a340c71
fixed monitoring unit tests
YulNaumenko Mar 7, 2021
4d748ab
fixed type checks
YulNaumenko Mar 7, 2021
a58b0b7
Merge remote-tracking branch upstream/master
YulNaumenko Mar 7, 2021
f416fa1
fixed type checks
YulNaumenko Mar 8, 2021
17377bf
fixed type checks
YulNaumenko Mar 8, 2021
3586481
migrated lists plugin
YulNaumenko Mar 8, 2021
55f1eaa
fixed type checks
YulNaumenko Mar 8, 2021
4cc2069
fixed tests
YulNaumenko Mar 8, 2021
2326e80
fixed security tests
YulNaumenko Mar 8, 2021
f9a9042
fixed type checks
YulNaumenko Mar 8, 2021
98d2fb4
Merge remote-tracking branch upstream/master
YulNaumenko Mar 8, 2021
633c230
Merge remote-tracking branch upstream/master
YulNaumenko Mar 8, 2021
b36a879
fixed tests
YulNaumenko Mar 9, 2021
3ffb5cf
fixed type checks
YulNaumenko Mar 9, 2021
4ae826e
fixed tests
YulNaumenko Mar 9, 2021
c87626c
fixed tests
YulNaumenko Mar 9, 2021
9a0c821
fixed tests
YulNaumenko Mar 9, 2021
f8a8a95
fixed due to comments
YulNaumenko Mar 9, 2021
9590624
fixed tests
YulNaumenko Mar 9, 2021
6ac3f7c
Merge remote-tracking branch upstream/master
YulNaumenko Mar 9, 2021
256538c
fixed comment
YulNaumenko Mar 9, 2021
482c206
fixed tests
YulNaumenko Mar 9, 2021
9ad926c
Merge remote-tracking branch upstream/master
YulNaumenko Mar 9, 2021
356fdc4
fixed tests
YulNaumenko Mar 9, 2021
8d52447
fixed searh
YulNaumenko Mar 10, 2021
a5743af
fixed searh
YulNaumenko Mar 10, 2021
3643065
Merge remote-tracking branch upstream/master
YulNaumenko Mar 11, 2021
a821b9a
fixed test
YulNaumenko Mar 11, 2021
694afbd
fixed due to comment
YulNaumenko Mar 11, 2021
3651f96
fixed detections failing test and replaces scopedClusterClient exposu…
YulNaumenko Mar 15, 2021
97eaaf8
Merge remote-tracking branch upstream/master
YulNaumenko Mar 15, 2021
e595e85
fixed test
YulNaumenko Mar 15, 2021
3acd943
fixed test
YulNaumenko Mar 16, 2021
c0ff617
fixed test
YulNaumenko Mar 16, 2021
c62ab0c
fixed typecheck
YulNaumenko Mar 16, 2021
04aeeff
fixed typecheck
YulNaumenko Mar 16, 2021
7da1ae0
Merge remote-tracking branch upstream/master
YulNaumenko Mar 16, 2021
51d6f30
fixed typecheck
YulNaumenko Mar 16, 2021
d7947f9
fixed merge
YulNaumenko Mar 16, 2021
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
Prev Previous commit
Next Next commit
fixed detections failing test and replaces scopedClusterClient exposu…
…re with IScopedClusterClient instead of ElasticsearchClient asCurrentUser
  • Loading branch information
YulNaumenko committed Mar 15, 2021
commit 3651f96c081d0c517a92a260bb4eb0bec9b6a7e7
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class AlertingPlugin {
): (request: KibanaRequest) => Services {
return (request) => ({
savedObjectsClient: this.getScopedClientWithAlertSavedObjectType(savedObjects, request),
scopedClusterClient: elasticsearch.client.asScoped(request).asCurrentUser,
scopedClusterClient: elasticsearch.client.asScoped(request),
});
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { PluginSetupContract, PluginStartContract } from './plugin';
import { AlertsClient } from './alerts_client';
export * from '../common';
import {
ElasticsearchClient,
IScopedClusterClient,
KibanaRequest,
SavedObjectAttributes,
SavedObjectsClientContract,
Expand Down Expand Up @@ -62,7 +62,7 @@ export type AlertingRouter = IRouter<AlertingRequestHandlerContext>;

export interface Services {
savedObjectsClient: SavedObjectsClientContract;
scopedClusterClient: ElasticsearchClient;
scopedClusterClient: IScopedClusterClient;
}

export interface AlertServices<
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/lib/alerts/alerting_es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function alertingEsClient<TParams extends ESSearchRequest>(
>,
params: TParams
): Promise<ApiResponse<ESSearchResponse<unknown, TParams>>> {
return services.scopedClusterClient.search({
return services.scopedClusterClient.asCurrentUser.search({
...params,
ignore_unavailable: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =

const results = await Promise.all(
criteria.map((c) =>
evaluateCondition(c, nodeType, source, services.scopedClusterClient, filterQuery)
evaluateCondition(
c,
nodeType,
source,
services.scopedClusterClient.asCurrentUser,
filterQuery
)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const createMetricThresholdExecutor = (
);
const config = source.configuration;
const alertResults = await evaluateAlert(
services.scopedClusterClient,
services.scopedClusterClient.asCurrentUser,
params as EvaluatedAlertParams,
config
);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/alerts/base_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class BaseAlert {
`Executing alert with params: ${JSON.stringify(params)} and state: ${JSON.stringify(state)}`
);

const esClient = services.scopedClusterClient;
const esClient = services.scopedClusterClient.asCurrentUser;
const availableCcs = Globals.app.config.ui.ccs.enabled ? await fetchAvailableCcs(esClient) : [];
const clusters = await this.fetchClusters(esClient, params as CommonAlertParams, availableCcs);
const data = await this.fetchData(params, esClient, clusters, availableCcs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const rulesNotificationAlertType = ({
size: DEFAULT_RULE_NOTIFICATION_QUERY_SIZE,
index: ruleParams.outputIndex,
ruleId: ruleParams.ruleId,
esClient: services.scopedClusterClient,
esClient: services.scopedClusterClient.asCurrentUser,
});

const signals = results.hits.hits.map((hit) => hit._source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export const getIndexVersion = async (
return 0;
}
const writeIndexMapping = await readIndex(esClient, writeIndex);
return get(writeIndexMapping, [writeIndex, 'mappings', '_meta', 'version']) ?? 0;
return get(writeIndexMapping, ['body', writeIndex, 'mappings', '_meta', 'version']) ?? 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

};
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const signalRulesAlertType = ({
const inputIndices = await getInputIndex(services, version, index);
const [privileges, timestampFieldCaps] = await Promise.all([
checkPrivileges(services, inputIndices),
services.scopedClusterClient.fieldCaps({
services.scopedClusterClient.asCurrentUser.fieldCaps({
index,
fields: hasTimestampOverride
? ['@timestamp', timestampOverride as string]
Expand Down Expand Up @@ -585,7 +585,7 @@ export const signalRulesAlertType = ({
}
try {
const signalIndexVersion = await getIndexVersion(
services.scopedClusterClient,
services.scopedClusterClient.asCurrentUser,
outputIndex
);
if (isOutdated({ current: signalIndexVersion, target: MIN_EQL_RULE_INDEX_VERSION })) {
Expand Down Expand Up @@ -614,7 +614,9 @@ export const signalRulesAlertType = ({
eventCategoryOverride
);
const eqlSignalSearchStart = performance.now();
const { body: response } = (await services.scopedClusterClient.transport.request(
const {
body: response,
} = (await services.scopedClusterClient.asCurrentUser.transport.request(
request
)) as ApiResponse<EqlSignalSearchResponse>;
const eqlSignalSearchEnd = performance.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const singleBulkCreate = async ({
}),
]);
const start = performance.now();
const { body: response } = await services.scopedClusterClient.bulk<BulkResponse>({
const { body: response } = await services.scopedClusterClient.asCurrentUser.bulk<BulkResponse>({
index: signalsIndex,
refresh,
body: bulkBody,
Expand Down Expand Up @@ -244,7 +244,7 @@ export const bulkInsertSignals = async (
doc._source,
]);
const start = performance.now();
const { body: response } = await services.scopedClusterClient.bulk<BulkResponse>({
const { body: response } = await services.scopedClusterClient.asCurrentUser.bulk<BulkResponse>({
refresh,
body: bulkBody,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const singleSearchAfter = async ({
const start = performance.now();
const {
body: nextSearchAfterResult,
} = await services.scopedClusterClient.search<SignalSearchResponse>(searchAfterQuery);
} = await services.scopedClusterClient.asCurrentUser.search<SignalSearchResponse>(
searchAfterQuery
);
const end = performance.now();
const searchErrors = createErrorsFromShard({
errors: nextSearchAfterResult._shards.failures ?? [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const buildThreatEnrichment = ({
},
};
const threatResponse = await getThreatList({
esClient: services.scopedClusterClient,
esClient: services.scopedClusterClient.asCurrentUser,
exceptionItems,
threatFilters: [...threatFilters, matchedThreatsFilter],
query: threatQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createThreatSignals = async ({
};

let threatListCount = await getThreatListCount({
esClient: services.scopedClusterClient,
esClient: services.scopedClusterClient.asCurrentUser,
exceptionItems,
threatFilters,
query: threatQuery,
Expand All @@ -76,7 +76,7 @@ export const createThreatSignals = async ({
logger.debug(buildRuleMessage(`Total indicator items: ${threatListCount}`));

let threatList = await getThreatList({
esClient: services.scopedClusterClient,
esClient: services.scopedClusterClient.asCurrentUser,
exceptionItems,
threatFilters,
query: threatQuery,
Expand Down Expand Up @@ -166,7 +166,7 @@ export const createThreatSignals = async ({
logger.debug(buildRuleMessage(`Indicator items left to check are ${threatListCount}`));

threatList = await getThreatList({
esClient: services.scopedClusterClient,
esClient: services.scopedClusterClient.asCurrentUser,
exceptionItems,
query: threatQuery,
language: threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const checkPrivileges = async (
indices: string[]
): Promise<Privilege> =>
(
await services.scopedClusterClient.transport.request({
await services.scopedClusterClient.asCurrentUser.transport.request({
path: '/_security/user/_has_privileges',
method: 'POST',
body: {
Expand Down Expand Up @@ -208,7 +208,7 @@ export const getListsClient = ({
}

const listClient = lists.getListClient(
services.scopedClusterClient,
services.scopedClusterClient.asCurrentUser,
spaceId,
updatedByUser ?? 'elastic'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function getAlertType(
const { alertId, name, services, params, state } = options;
const previousTimestamp = state.latestTimestamp;

const esClient = services.scopedClusterClient;
const esClient = services.scopedClusterClient.asCurrentUser;
const { parsedQuery, dateStart, dateEnd } = getSearchParams(params);

const compareFn = ComparatorFns.get(params.thresholdComparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const getGeoContainmentExecutor = (log: Logger): GeoContainmentAlertType[
params.boundaryIndexTitle,
params.boundaryGeoField,
params.geoField,
services.scopedClusterClient,
services.scopedClusterClient.asCurrentUser,
log,
alertId,
params.boundaryNameField,
Expand All @@ -158,7 +158,7 @@ export const getGeoContainmentExecutor = (log: Logger): GeoContainmentAlertType[

const executeEsQuery = await executeEsQueryFactory(
params,
services.scopedClusterClient,
services.scopedClusterClient.asCurrentUser,
log,
shapesFilters
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function getAlertType(
);
}

const esClient = services.scopedClusterClient;
const esClient = services.scopedClusterClient.asCurrentUser;
const date = new Date().toISOString();
// the undefined values below are for config-schema optional types
const queryParams: TimeSeriesQuery = {
Expand Down