Skip to content

Commit

Permalink
Fix depth calculation for 7.10+ signals on pre-7.10 signals
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain committed Sep 2, 2020
1 parent 39a5f49 commit de9debb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const buildParent = (doc: SignalSourceHit): Ancestor => {
id: doc._id,
type: 'signal',
index: doc._index,
depth: doc._source.signal.depth,
// We first look for signal.depth and use that if it exists. If it doesn't exist, this should be a pre-7.10 signal
// and should have signal.parent.depth instead. signal.parent.depth is treated as equivalent to signal.depth.
depth: doc._source.signal.depth ?? doc._source.signal?.parent?.depth ?? 1,
};
} else {
return {
Expand All @@ -37,8 +39,8 @@ export const buildAncestorsSignal = (doc: SignalSourceHit): Signal['ancestors']
};

export const buildSignal = (docs: SignalSourceHit[], rule: Partial<RulesSchema>): Signal => {
const depth = docs.reduce((acc, doc) => Math.max(doc._source.signal?.depth ?? 0, acc), 0) + 1;
const parents = docs.map(buildParent);
const depth = parents.reduce((acc, parent) => Math.max(parent.depth, acc), 0) + 1;
const ancestors = docs.reduce(
(acc: Ancestor[], doc) => acc.concat(buildAncestorsSignal(doc)),
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export interface SignalSource {
rule: {
id: string;
};
depth: number;
// signal.depth doesn't exist on pre-7.10 signals
depth?: number;
};
}

Expand Down

0 comments on commit de9debb

Please sign in to comment.