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

[ML] Fix Single Metric Viewer not loading if job is metric with no partition #83880

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ export const PlotByFunctionControls = ({
selectedDetectorIndex,
selectedJobId,
selectedEntities,
entityControlsCount,
}: {
functionDescription: undefined | string;
setFunctionDescription: (func: string) => void;
selectedDetectorIndex: number;
selectedJobId: string;
selectedEntities: Record<string, any>;
entityControlsCount: number;
}) => {
const toastNotificationService = useToastNotificationService();

Expand Down Expand Up @@ -73,9 +75,12 @@ export const PlotByFunctionControls = ({
return;
}
const selectedJob = mlJobService.getJob(selectedJobId);
// if no controls, it's okay to fetch
// if there are series controls, only fetch if user has selected something
const validEntities =
entityControlsCount === 0 || (entityControlsCount > 0 && selectedEntities !== undefined);
if (
// set if only entity controls are picked
selectedEntities !== undefined &&
validEntities &&
functionDescription === undefined &&
isMetricDetector(selectedJob, selectedDetectorIndex)
) {
Expand All @@ -95,6 +100,7 @@ export const PlotByFunctionControls = ({
selectedEntities,
selectedJobId,
functionDescription,
entityControlsCount,
]);

if (functionDescription === undefined) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useStorage } from '../../../contexts/ml/use_storage';
import { EntityFieldType } from '../../../../../common/types/anomalies';
import { FieldDefinition } from '../../../services/results_service/result_service_rx';
import { getViewableDetectors } from '../../timeseriesexplorer_utils/get_viewable_detectors';
import { PlotByFunctionControls } from '../plot_function_controls';

function getEntityControlOptions(fieldValues: FieldDefinition['values']): ComboBoxOption[] {
if (!Array.isArray(fieldValues)) {
Expand Down Expand Up @@ -67,6 +68,8 @@ interface SeriesControlsProps {
bounds: any;
appStateHandler: Function;
selectedEntities: Record<string, any>;
functionDescription: string;
setFunctionDescription: (func: string) => void;
}

/**
Expand All @@ -79,6 +82,8 @@ export const SeriesControls: FC<SeriesControlsProps> = ({
appStateHandler,
children,
selectedEntities,
functionDescription,
setFunctionDescription,
}) => {
const {
services: {
Expand Down Expand Up @@ -306,6 +311,15 @@ export const SeriesControls: FC<SeriesControlsProps> = ({
/>
);
})}
<PlotByFunctionControls
selectedJobId={selectedJobId}
selectedDetectorIndex={selectedDetectorIndex}
selectedEntities={selectedEntities}
functionDescription={functionDescription}
setFunctionDescription={setFunctionDescription}
entityControlsCount={entityControls.length}
/>

{children}
</EuiFlexGroup>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import { ANOMALY_DETECTION_DEFAULT_TIME_RANGE } from '../../../common/constants/
import { getControlsForDetector } from './get_controls_for_detector';
import { SeriesControls } from './components/series_controls';
import { TimeSeriesChartWithTooltips } from './components/timeseries_chart/timeseries_chart_with_tooltip';
import { PlotByFunctionControls } from './components/plot_function_controls';
import { aggregationTypeTransform } from '../../../common/util/anomaly_utils';
import { isMetricDetector } from './get_function_description';
import { getViewableDetectors } from './timeseriesexplorer_utils/get_viewable_detectors';
Expand Down Expand Up @@ -1013,15 +1012,9 @@ export class TimeSeriesExplorer extends React.Component {
selectedDetectorIndex={selectedDetectorIndex}
selectedEntities={this.props.selectedEntities}
bounds={bounds}
functionDescription={this.props.functionDescription}
setFunctionDescription={this.setFunctionDescription}
>
<PlotByFunctionControls
selectedJobId={selectedJobId}
selectedDetectorIndex={selectedDetectorIndex}
selectedEntities={this.props.selectedEntities}
functionDescription={this.props.functionDescription}
setFunctionDescription={this.setFunctionDescription}
/>

{arePartitioningFieldsProvided && (
<EuiFlexItem style={{ textAlign: 'right' }}>
<EuiFormRow hasEmptyLabelSpace style={{ maxWidth: '100%' }}>
Expand Down