Skip to content

Commit

Permalink
[ML] Correctly pass on severity value to anomaly explorer charts. (#5…
Browse files Browse the repository at this point in the history
…5207) (#55329)

- Fixes passing on the severity value correctly to anomaly explorer charts. The wrong value of undefined being passed down caused anomaly markers not showing up.
- This bug surfaced that the severity value was never applied to filter multi-bucket anomalies which is now also fixed by this PR.
- Adds a check if topInfluencers is an array.
  • Loading branch information
walterra committed Jan 20, 2020
1 parent c85f7a7 commit 5bed96e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AppStateSelectedCells } from '../explorer/explorer_utils';

declare interface ExplorerProps {
explorerState: ExplorerState;
severity: number;
showCharts: boolean;
setSelectedCells: (swimlaneSelectedCells: AppStateSelectedCells) => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class Explorer extends React.Component {
static propTypes = {
explorerState: PropTypes.object.isRequired,
setSelectedCells: PropTypes.func.isRequired,
severity: PropTypes.number.isRequired,
showCharts: PropTypes.bool.isRequired,
};

Expand Down Expand Up @@ -260,7 +261,7 @@ export class Explorer extends React.Component {
};

render() {
const { showCharts } = this.props;
const { showCharts, severity } = this.props;

const {
annotationsData,
Expand All @@ -276,7 +277,6 @@ export class Explorer extends React.Component {
queryString,
selectedCells,
selectedJobs,
severity,
swimlaneContainerWidth,
tableData,
tableQueryString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ExplorerChartSingleMetric = injectI18n(
static propTypes = {
tooManyBuckets: PropTypes.bool,
seriesConfig: PropTypes.object,
severity: PropTypes.number,
severity: PropTypes.number.isRequired,
};

componentDidMount() {
Expand Down Expand Up @@ -312,13 +312,16 @@ export const ExplorerChartSingleMetric = injectI18n(
})
.on('mouseout', () => mlChartTooltipService.hide());

const isAnomalyVisible = d =>
_.has(d, 'anomalyScore') && Number(d.anomalyScore) >= severity;

// Update all dots to new positions.
dots
.attr('cx', d => lineChartXScale(d.date))
.attr('cy', d => lineChartYScale(d.value))
.attr('class', d => {
let markerClass = 'metric-value';
if (_.has(d, 'anomalyScore') && Number(d.anomalyScore) >= severity) {
if (isAnomalyVisible(d)) {
markerClass += ` anomaly-marker ${getSeverityWithLow(d.anomalyScore).id}`;
}
return markerClass;
Expand All @@ -328,9 +331,7 @@ export const ExplorerChartSingleMetric = injectI18n(
const multiBucketMarkers = lineChartGroup
.select('.chart-markers')
.selectAll('.multi-bucket')
.data(
data.filter(d => d.anomalyScore !== null && showMultiBucketAnomalyMarker(d) === true)
);
.data(data.filter(d => isAnomalyVisible(d) && showMultiBucketAnomalyMarker(d) === true));

// Remove multi-bucket markers that are no longer needed
multiBucketMarkers.exit().remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ export function loadViewByTopFieldValuesForSelectedTime(

const topFieldValues = [];
const topInfluencers = resp.influencers[viewBySwimlaneFieldName];
topInfluencers.forEach(influencerData => {
if (influencerData.maxAnomalyScore > 0) {
topFieldValues.push(influencerData.influencerFieldValue);
}
});
if (Array.isArray(topInfluencers)) {
topInfluencers.forEach(influencerData => {
if (influencerData.maxAnomalyScore > 0) {
topFieldValues.push(influencerData.influencerFieldValue);
}
});
}
resolve(topFieldValues);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const ExplorerUrlStateManager: FC<ExplorerUrlStateManagerProps> = ({ jobsWithTim
explorerState,
setSelectedCells,
showCharts,
severity: tableSeverity.val,
}}
/>
</div>
Expand Down

0 comments on commit 5bed96e

Please sign in to comment.