Skip to content

Commit

Permalink
[Uptime] Remove static constant for index name completely (#62256) (#…
Browse files Browse the repository at this point in the history
…62322)

Fixes #62255 . There were some remaining usages of a static defined
index name.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
andrewvc and elasticmachine committed Apr 2, 2020
1 parent 4170cac commit 457aacf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
1 change: 0 additions & 1 deletion x-pack/legacy/plugins/uptime/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export { ACTION_GROUP_DEFINITIONS } from './alerts';
export { CHART_FORMAT_LIMITS } from './chart_format_limits';
export { CLIENT_DEFAULTS } from './client_defaults';
export { CONTEXT_DEFAULTS } from './context_defaults';
export { INDEX_NAMES } from './index_names';
export * from './capabilities';
export { PLUGIN } from './plugin';
export { QUERY, STATES } from './query';
Expand Down
9 changes: 0 additions & 9 deletions x-pack/legacy/plugins/uptime/common/constants/index_names.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
hasMLJobSelector,
hasNewMLJobSelector,
isMLJobCreatingSelector,
selectDynamicSettings,
} from '../../../state/selectors';
import { createMLJobAction, getExistingMLJobAction } from '../../../state/actions';
import { MLJobLink } from './ml_job_link';
Expand All @@ -24,6 +25,7 @@ import { MLFlyoutView } from './ml_flyout';
import { ML_JOB_ID } from '../../../../common/constants';
import { UptimeRefreshContext, UptimeSettingsContext } from '../../../contexts';
import { useUrlParams } from '../../../hooks';
import { getDynamicSettings } from '../../../state/actions/dynamic_settings';

interface Props {
onClose: () => void;
Expand Down Expand Up @@ -65,16 +67,25 @@ export const MachineLearningFlyout: React.FC<Props> = ({ onClose }) => {
const dispatch = useDispatch();
const { data: hasMLJob, error } = useSelector(hasNewMLJobSelector);
const isMLJobCreating = useSelector(isMLJobCreatingSelector);
const { settings } = useSelector(selectDynamicSettings);
useEffect(() => {
// Attempt to load or refresh the dynamic settings
dispatch(getDynamicSettings({}));
}, [dispatch]);
const heartbeatIndices = settings?.heartbeatIndices || '';
const { basePath } = useContext(UptimeSettingsContext);

const { refreshApp } = useContext(UptimeRefreshContext);

let { monitorId } = useParams();
monitorId = atob(monitorId || '');

const createMLJob = () => dispatch(createMLJobAction.get({ monitorId: monitorId as string }));
const canCreateMLJob = useSelector(canCreateMLJobSelector) && heartbeatIndices !== '';

const canCreateMLJob = useSelector(canCreateMLJobSelector);
// This function is a noop in the form's disabled state
const createMLJob = heartbeatIndices
? () => dispatch(createMLJobAction.get({ monitorId: monitorId as string, heartbeatIndices }))
: () => null;

const { data: uptimeJobs } = useSelector(hasMLJobSelector);

Expand Down Expand Up @@ -130,9 +141,9 @@ export const MachineLearningFlyout: React.FC<Props> = ({ onClose }) => {
useEffect(() => {
if (hasExistingMLJob) {
setIsCreatingJob(true);
dispatch(createMLJobAction.get({ monitorId: monitorId as string }));
dispatch(createMLJobAction.get({ monitorId: monitorId as string, heartbeatIndices }));
}
}, [dispatch, hasExistingMLJob, monitorId]);
}, [dispatch, hasExistingMLJob, heartbeatIndices, monitorId]);

if (hasExistingMLJob) {
return null;
Expand Down
14 changes: 10 additions & 4 deletions x-pack/legacy/plugins/uptime/public/state/actions/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { createAction } from 'redux-actions';
import { createAsyncAction } from './utils';
import { PrivilegesResponse } from '../../../../../../plugins/ml/common/types/privileges';
import { AnomaliesTableRecord } from '../../../../../../plugins/ml/common/types/anomalies';
import { CreateMLJobSuccess, DeleteJobResults, MonitorIdParam } from './types';
import {
CreateMLJobSuccess,
DeleteJobResults,
MonitorIdParam,
HeartbeatIndicesParam,
} from './types';
import { JobExistResult } from '../../../../../../plugins/ml/common/types/data_recognizer';

export const resetMLState = createAction('RESET_ML_STATE');
Expand All @@ -17,9 +22,10 @@ export const getExistingMLJobAction = createAsyncAction<MonitorIdParam, JobExist
'GET_EXISTING_ML_JOB'
);

export const createMLJobAction = createAsyncAction<MonitorIdParam, CreateMLJobSuccess | null>(
'CREATE_ML_JOB'
);
export const createMLJobAction = createAsyncAction<
MonitorIdParam & HeartbeatIndicesParam,
CreateMLJobSuccess | null
>('CREATE_ML_JOB');

export const getMLCapabilitiesAction = createAsyncAction<any, PrivilegesResponse>(
'GET_ML_CAPABILITIES'
Expand Down
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/uptime/public/state/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface MonitorIdParam {
monitorId: string;
}

export interface HeartbeatIndicesParam {
heartbeatIndices: string;
}

export interface QueryParams {
monitorId: string;
dateStart: string;
Expand Down
14 changes: 10 additions & 4 deletions x-pack/legacy/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import moment from 'moment';
import { apiService } from './utils';
import { AnomalyRecords, AnomalyRecordsParams } from '../actions';
import { API_URLS, INDEX_NAMES, ML_JOB_ID, ML_MODULE_ID } from '../../../common/constants';
import { API_URLS, ML_JOB_ID, ML_MODULE_ID } from '../../../common/constants';
import { PrivilegesResponse } from '../../../../../../plugins/ml/common/types/privileges';
import { CreateMLJobSuccess, DeleteJobResults, MonitorIdParam } from '../actions/types';
import {
CreateMLJobSuccess,
DeleteJobResults,
MonitorIdParam,
HeartbeatIndicesParam,
} from '../actions/types';
import { DataRecognizerConfigResponse } from '../../../../../../plugins/ml/common/types/modules';
import { JobExistResult } from '../../../../../../plugins/ml/common/types/data_recognizer';

Expand All @@ -25,7 +30,8 @@ export const getExistingJobs = async (): Promise<JobExistResult> => {

export const createMLJob = async ({
monitorId,
}: MonitorIdParam): Promise<CreateMLJobSuccess | null> => {
heartbeatIndices,
}: MonitorIdParam & HeartbeatIndicesParam): Promise<CreateMLJobSuccess | null> => {
const url = API_URLS.ML_SETUP_MODULE + ML_MODULE_ID;

const data = {
Expand All @@ -35,7 +41,7 @@ export const createMLJob = async ({
start: moment()
.subtract(24, 'h')
.valueOf(),
indexPatternName: INDEX_NAMES.HEARTBEAT,
indexPatternName: heartbeatIndices,
query: {
bool: {
filter: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export interface GetMonitorStatusParams {
filters?: string;
Expand Down Expand Up @@ -51,7 +50,7 @@ const getLocationClause = (locations: string[]) => ({
export const getMonitorStatus: UMElasticsearchQueryFn<
GetMonitorStatusParams,
GetMonitorStatusResult[]
> = async ({ callES, filters, locations, numTimes, timerange: { from, to } }) => {
> = async ({ callES, dynamicSettings, filters, locations, numTimes, timerange: { from, to } }) => {
const queryResults: Array<Promise<GetMonitorStatusResult[]>> = [];
let afterKey: MonitorStatusKey | undefined;

Expand All @@ -60,7 +59,7 @@ export const getMonitorStatus: UMElasticsearchQueryFn<
// multiple status types for this alert, and this will become a parameter
const STATUS = 'down';
const esParams: any = {
index: INDEX_NAMES.HEARTBEAT,
index: dynamicSettings.heartbeatIndices,
body: {
query: {
bool: {
Expand Down

0 comments on commit 457aacf

Please sign in to comment.