Skip to content

Commit

Permalink
add buildRuleMessage fn to params
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley14 committed Sep 28, 2020
1 parent 08522ef commit b114812
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
Expand Up @@ -34,6 +34,7 @@ interface BulkCreateMlSignalsParams {
refresh: RefreshTypes;
tags: string[];
throttle: string;
buildRuleMessage: BuildRuleMessage;
}

interface EcsAnomaly extends Anomaly {
Expand Down Expand Up @@ -82,10 +83,10 @@ const transformAnomalyResultsToEcs = (results: AnomalyResults): SearchResponse<E
};

export const bulkCreateMlSignals = async (
params: BulkCreateMlSignalsParams,
buildRuleMessage: BuildRuleMessage
params: BulkCreateMlSignalsParams
): Promise<SingleBulkCreateResponse> => {
const anomalyResults = params.someResult;
const ecsResults = transformAnomalyResultsToEcs(anomalyResults);
const buildRuleMessage = params.buildRuleMessage;
return singleBulkCreate({ ...params, filteredEvents: ecsResults, buildRuleMessage });
};
Expand Up @@ -41,6 +41,7 @@ interface BulkCreateThresholdSignalsParams {
tags: string[];
throttle: string;
startedAt: Date;
buildRuleMessage: BuildRuleMessage;
}

interface FilterObject {
Expand Down Expand Up @@ -185,8 +186,7 @@ export const transformThresholdResultsToEcs = (
};

export const bulkCreateThresholdSignals = async (
params: BulkCreateThresholdSignalsParams,
buildRuleMessage: BuildRuleMessage
params: BulkCreateThresholdSignalsParams
): Promise<SingleBulkCreateResponse> => {
const thresholdResults = params.someResult;
const ecsResults = transformThresholdResultsToEcs(
Expand All @@ -197,6 +197,7 @@ export const bulkCreateThresholdSignals = async (
params.ruleParams.threshold!,
params.ruleParams.ruleId
);
const buildRuleMessage = params.buildRuleMessage;

return singleBulkCreate({ ...params, filteredEvents: ecsResults, buildRuleMessage });
};
Expand Up @@ -239,28 +239,26 @@ export const signalRulesAlertType = ({
errors,
bulkCreateDuration,
createdItemsCount,
} = await bulkCreateMlSignals(
{
actions,
throttle,
someResult: anomalyResults,
ruleParams: params,
services,
logger,
id: alertId,
signalsIndex: outputIndex,
name,
createdBy,
createdAt,
updatedBy,
updatedAt,
interval,
enabled,
refresh,
tags,
},
buildRuleMessage
);
} = await bulkCreateMlSignals({
actions,
throttle,
someResult: anomalyResults,
ruleParams: params,
services,
logger,
id: alertId,
signalsIndex: outputIndex,
name,
createdBy,
createdAt,
updatedBy,
updatedAt,
interval,
enabled,
refresh,
tags,
buildRuleMessage,
});
// The legacy ES client does not define failures when it can be present on the structure, hence why I have the & { failures: [] }
const shardFailures =
(anomalyResults._shards as typeof anomalyResults._shards & { failures: [] }).failures ??
Expand Down Expand Up @@ -306,31 +304,29 @@ export const signalRulesAlertType = ({
bulkCreateDuration,
createdItemsCount,
errors,
} = await bulkCreateThresholdSignals(
{
actions,
throttle,
someResult: thresholdResults,
ruleParams: params,
filter: esFilter,
services,
logger,
id: alertId,
inputIndexPattern: inputIndex,
signalsIndex: outputIndex,
startedAt,
name,
createdBy,
createdAt,
updatedBy,
updatedAt,
interval,
enabled,
refresh,
tags,
},
buildRuleMessage
);
} = await bulkCreateThresholdSignals({
actions,
throttle,
someResult: thresholdResults,
ruleParams: params,
filter: esFilter,
services,
logger,
id: alertId,
inputIndexPattern: inputIndex,
signalsIndex: outputIndex,
startedAt,
name,
createdBy,
createdAt,
updatedBy,
updatedAt,
interval,
enabled,
refresh,
tags,
buildRuleMessage,
});
result = mergeReturns([
result,
createSearchAfterReturnTypeFromResponse({ searchResult: thresholdResults }),
Expand Down

0 comments on commit b114812

Please sign in to comment.