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] Listing global calendars on the job management page #63124

Merged
Changes from 2 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
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