Skip to content

Commit

Permalink
Renamed to be shorter and more consumable
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Sep 22, 2020
1 parent 48e790a commit 8215f29
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
createSearchAfterReturnTypeFromResponse,
createTotalHitsFromSearchResult,
getSignalTimeTuples,
mergeSearchAfterAndBulkCreate,
mergeReturns,
} from './utils';
import { SearchAfterAndBulkCreateParams, SearchAfterAndBulkCreateReturnType } from './types';

Expand Down Expand Up @@ -90,7 +90,7 @@ export const searchAfterAndBulkCreate = async ({
pageSize: tuple.maxSignals < pageSize ? Math.ceil(tuple.maxSignals) : pageSize, // maximum number of docs to receive per search result.
timestampOverride: ruleParams.timestampOverride,
});
toReturn = mergeSearchAfterAndBulkCreate([
toReturn = mergeReturns([
toReturn,
createSearchAfterReturnTypeFromResponse({ searchResult }),
createSearchAfterReturnType({
Expand Down Expand Up @@ -171,7 +171,7 @@ export const searchAfterAndBulkCreate = async ({
tags,
throttle,
});
toReturn = mergeSearchAfterAndBulkCreate([
toReturn = mergeReturns([
toReturn,
createSearchAfterReturnType({
success: bulkSuccess,
Expand Down Expand Up @@ -200,7 +200,7 @@ export const searchAfterAndBulkCreate = async ({
}
} catch (exc: unknown) {
logger.error(buildRuleMessage(`[-] search_after and bulk threw an error ${exc}`));
return mergeSearchAfterAndBulkCreate([
return mergeReturns([
toReturn,
createSearchAfterReturnType({
success: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
MAX_RULE_GAP_RATIO,
createErrorsFromShard,
createSearchAfterReturnType,
mergeSearchAfterAndBulkCreate,
mergeReturns,
createSearchAfterReturnTypeFromResponse,
} from './utils';
import { signalParamsSchema } from './signal_params_schema';
Expand Down Expand Up @@ -256,7 +256,7 @@ export const signalRulesAlertType = ({
const searchErrors = createErrorsFromShard({
errors: shardFailures,
});
result = mergeSearchAfterAndBulkCreate([
result = mergeReturns([
result,
createSearchAfterReturnType({
success: success && anomalyResults._shards.failed === 0,
Expand Down Expand Up @@ -317,7 +317,7 @@ export const signalRulesAlertType = ({
refresh,
tags,
});
result = mergeSearchAfterAndBulkCreate([
result = mergeReturns([
result,
createSearchAfterReturnTypeFromResponse({ searchResult: thresholdResults }),
createSearchAfterReturnType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
createErrorsFromShard,
createSearchAfterReturnTypeFromResponse,
createSearchAfterReturnType,
mergeSearchAfterAndBulkCreate,
mergeReturns,
createTotalHitsFromSearchResult,
} from './utils';
import { BulkResponseErrorAggregation, SearchAfterAndBulkCreateReturnType } from './types';
Expand Down Expand Up @@ -967,12 +967,9 @@ describe('utils', () => {
});
});

describe('mergeSearchAfterAndBulkCreate', () => {
describe('mergeReturns', () => {
test('it merges a default "prev" and "next" correctly ', () => {
const merged = mergeSearchAfterAndBulkCreate([
createSearchAfterReturnType(),
createSearchAfterReturnType(),
]);
const merged = mergeReturns([createSearchAfterReturnType(), createSearchAfterReturnType()]);
const expected: SearchAfterAndBulkCreateReturnType = {
bulkCreateTimes: [],
createdSignalsCount: 0,
Expand All @@ -985,23 +982,23 @@ describe('utils', () => {
});

test('it merges search in with two default search results where "prev" "success" is false correctly', () => {
const { success } = mergeSearchAfterAndBulkCreate([
const { success } = mergeReturns([
createSearchAfterReturnType({ success: false }),
createSearchAfterReturnType(),
]);
expect(success).toEqual(false);
});

test('it merges search in with two default search results where "next" "success" is false correctly', () => {
const { success } = mergeSearchAfterAndBulkCreate([
const { success } = mergeReturns([
createSearchAfterReturnType(),
createSearchAfterReturnType({ success: false }),
]);
expect(success).toEqual(false);
});

test('it merges search where the lastLookBackDate is the "next" date when given', () => {
const { lastLookBackDate } = mergeSearchAfterAndBulkCreate([
const { lastLookBackDate } = mergeReturns([
createSearchAfterReturnType({
lastLookBackDate: new Date('2020-08-21T19:21:46.194Z'),
}),
Expand All @@ -1013,7 +1010,7 @@ describe('utils', () => {
});

test('it merges search where the lastLookBackDate is the "prev" if given undefined for "next', () => {
const { lastLookBackDate } = mergeSearchAfterAndBulkCreate([
const { lastLookBackDate } = mergeReturns([
createSearchAfterReturnType({
lastLookBackDate: new Date('2020-08-21T19:21:46.194Z'),
}),
Expand All @@ -1025,7 +1022,7 @@ describe('utils', () => {
});

test('it merges search where values from "next" and "prev" are computed together', () => {
const merged = mergeSearchAfterAndBulkCreate([
const merged = mergeReturns([
createSearchAfterReturnType({
bulkCreateTimes: ['123'],
createdSignalsCount: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export const createSearchAfterReturnType = ({
};
};

export const mergeSearchAfterAndBulkCreate = (
export const mergeReturns = (
searchAfters: SearchAfterAndBulkCreateReturnType[]
): SearchAfterAndBulkCreateReturnType => {
return searchAfters.reduce((prev, next) => {
Expand Down

0 comments on commit 8215f29

Please sign in to comment.