Skip to content

Commit

Permalink
[ML] Listing global calendars on the job management page (#63124) (#6…
Browse files Browse the repository at this point in the history
…3499)

* [ML] Listing global calendars on the job management page

* tiny refactor

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

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jgowdyelastic and elasticmachine committed Apr 15, 2020
1 parent 562f62c commit 34e2b0f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions x-pack/plugins/ml/server/models/job_service/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DatafeedWithStats,
CombinedJobWithStats,
} from '../../../common/types/anomaly_detection_jobs';
import { GLOBAL_CALENDAR } from '../../../common/constants/calendars';
import { datafeedsProvider, MlDatafeedsResponse, MlDatafeedsStatsResponse } from './datafeeds';
import { jobAuditMessagesProvider } from '../job_audit_messages';
import { resultsServiceProvider } from '../results_service';
Expand Down Expand Up @@ -227,6 +228,8 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
const groups: { [jobId: string]: string[] } = {};
const datafeeds: { [id: string]: DatafeedWithStats } = {};
const calendarsByJobId: { [jobId: string]: string[] } = {};
const globalCalendars: string[] = [];

const requests: [
Promise<MlJobsResponse>,
Promise<MlJobsStatsResponse>,
Expand Down Expand Up @@ -298,7 +301,9 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
if (calendarResults) {
calendarResults.forEach(cal => {
cal.job_ids.forEach(id => {
if (groups[id]) {
if (id === GLOBAL_CALENDAR) {
globalCalendars.push(cal.calendar_id);
} else if (groups[id]) {
groups[id].forEach(jId => {
if (calendarsByJobId[jId] !== undefined) {
calendarsByJobId[jId].push(cal.calendar_id);
Expand All @@ -325,8 +330,12 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
jobResults.jobs.forEach(job => {
const tempJob = job as CombinedJobWithStats;

if (calendarsByJobId[tempJob.job_id].length) {
tempJob.calendars = calendarsByJobId[tempJob.job_id];
const calendars: string[] = [
...(calendarsByJobId[tempJob.job_id] || []),
...(globalCalendars || []),
];
if (calendars.length) {
tempJob.calendars = calendars;
}

if (jobStatsResults && jobStatsResults.jobs) {
Expand Down

0 comments on commit 34e2b0f

Please sign in to comment.