diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index c29ea303..e6447523 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -45,6 +45,7 @@ import { getDataSourceId, appendCommentsAction, getIsCommentsEnabled, + getIsAgentConfigured } from '../../utils/helpers'; import { getUseUpdatedUx } from '../../../services'; @@ -78,6 +79,7 @@ export default class Dashboard extends Component { totalTriggers: 0, chainedAlert: undefined, commentsEnabled: false, + isAgentConfigured: false, }; } @@ -102,20 +104,30 @@ export default class Dashboard extends Component { getIsCommentsEnabled(this.props.httpClient).then((commentsEnabled) => { this.setState({ commentsEnabled }); }); + this.getUpdatedAgentConfig(); } componentDidUpdate(prevProps, prevState) { const prevQuery = getQueryObjectFromState(prevState); const currQuery = getQueryObjectFromState(this.state); if (!_.isEqual(prevQuery, currQuery)) { + this.getUpdatedAgentConfig(); this.getUpdatedAlerts(); } if (isDataSourceChanged(prevProps, this.props)) { this.dataSourceQuery = getDataSourceQueryObj(); + this.getUpdatedAgentConfig(); this.getUpdatedAlerts(); } } + getUpdatedAgentConfig() { + const dataSourceId = getDataSourceId(); + getIsAgentConfigured(dataSourceId).then((isAgentConfigured) => { + this.setState({ isAgentConfigured }); + }); + } + getUpdatedAlerts() { const { page, size, search, sortField, sortDirection, severityLevel, alertState, monitorIds } = this.state; @@ -361,6 +373,7 @@ export default class Dashboard extends Component { totalAlerts, totalTriggers, commentsEnabled, + isAgentConfigured, } = this.state; const { monitorIds, @@ -444,6 +457,7 @@ export default class Dashboard extends Component { location, monitors, notifications, + isAgentConfigured, setFlyout, this.openFlyout, this.closeFlyout, diff --git a/public/pages/Dashboard/containers/Dashboard.test.js b/public/pages/Dashboard/containers/Dashboard.test.js index c5486e7b..ef88bf2f 100644 --- a/public/pages/Dashboard/containers/Dashboard.test.js +++ b/public/pages/Dashboard/containers/Dashboard.test.js @@ -9,7 +9,7 @@ import { mount } from 'enzyme'; import Dashboard from './Dashboard'; import { historyMock, httpClientMock } from '../../../../test/mocks'; import { setupCoreStart } from '../../../../test/utils/helpers'; -import { setAssistantDashboards } from '../../../services'; +import { setAssistantDashboards, setAssistantClient } from '../../../services'; const location = { hash: '', @@ -64,7 +64,7 @@ beforeAll(() => { describe('Dashboard', () => { setAssistantDashboards({ getFeatureStatus: () => ({ chat: false, alertInsight: false }) }); - + setAssistantClient({agentConfigExists: (agentConfigName, options) => {return Promise.resolve({ exists: false });}}) beforeEach(() => { jest.clearAllMocks(); }); diff --git a/public/pages/Dashboard/utils/tableUtils.js b/public/pages/Dashboard/utils/tableUtils.js index 0f35a706..a48c3837 100644 --- a/public/pages/Dashboard/utils/tableUtils.js +++ b/public/pages/Dashboard/utils/tableUtils.js @@ -136,6 +136,7 @@ export const alertColumns = ( location, monitors, notifications, + isAgentConfigured, setFlyout, openFlyout, closeFlyout, @@ -167,7 +168,7 @@ export const alertColumns = ( }} data-test-subj={`euiLink_${alert.trigger_name}`} > - {`${total} alerts`} + {total > 1 ? `${total} alerts`:`${total} alert`} ); const contextProvider = async () => { @@ -291,7 +292,7 @@ export const alertColumns = ( const assistantEnabled = getApplication().capabilities?.assistant?.enabled === true; const assistantFeatureStatus = getAssistantDashboards().getFeatureStatus(); - if (assistantFeatureStatus.alertInsight && assistantEnabled) { + if (assistantFeatureStatus.alertInsight && assistantEnabled && isAgentConfigured) { getAssistantDashboards().registerIncontextInsight([ { key: alertId, diff --git a/public/pages/utils/constants.ts b/public/pages/utils/constants.ts index ff30dd07..06455129 100644 --- a/public/pages/utils/constants.ts +++ b/public/pages/utils/constants.ts @@ -16,4 +16,6 @@ const LocalCluster: DataSourceOption = { }; // We should use empty object for default value as local cluster may be disabled -export const dataSourceObservable = new BehaviorSubject({}); \ No newline at end of file +export const dataSourceObservable = new BehaviorSubject({}); +export const SUMMARY_AGENT_CONFIG_ID = 'os_summary'; +export const LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID = 'os_summary_with_log_pattern'; \ No newline at end of file diff --git a/public/pages/utils/helpers.js b/public/pages/utils/helpers.js index 4acc59d1..1f36bde1 100644 --- a/public/pages/utils/helpers.js +++ b/public/pages/utils/helpers.js @@ -4,10 +4,14 @@ */ import React from 'react'; -import { getDataSourceEnabled, getDataSource } from '../../services/services'; +import { getDataSourceEnabled, getDataSource, getAssistantClient } from '../../services/services'; import _ from 'lodash'; import { ShowAlertComments } from '../../components/Comments/ShowAlertComments'; -import { COMMENTS_ENABLED_SETTING } from './constants'; +import { + COMMENTS_ENABLED_SETTING, + SUMMARY_AGENT_CONFIG_ID, + LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID + } from './constants'; export function dataSourceEnabled() { return getDataSourceEnabled()?.enabled; @@ -68,6 +72,24 @@ export const appendCommentsAction = (columns, httpClient) => { return columns; }; +export async function getIsAgentConfigured(dataSourceId){ + const assistantClient = getAssistantClient(); + try{ + const res = await assistantClient.agentConfigExists( + [ + SUMMARY_AGENT_CONFIG_ID, + LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID, + ], + { dataSourceId: dataSourceId } + ); + return res.exists; + } + catch(e){ + console.error('Error while checking if agent is configured:', e); + return false; + } +} + export async function getIsCommentsEnabled(httpClient) { let commentsEnabled = await getClusterSetting(httpClient, COMMENTS_ENABLED_SETTING, false); diff --git a/public/plugin.tsx b/public/plugin.tsx index bc63d80b..97d8c073 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -21,10 +21,10 @@ import { alertingTriggerAd } from './utils/contextMenu/triggers'; import { ExpressionsSetup } from '../../../src/plugins/expressions/public'; import { UiActionsSetup } from '../../../src/plugins/ui_actions/public'; import { overlayAlertsFunction } from './expressions/overlay_alerts'; -import { setClient, setEmbeddable, setNotifications, setOverlays, setSavedAugmentVisLoader, setUISettings, setQueryService, setSavedObjectsClient, setDataSourceEnabled, setDataSourceManagementPlugin, setNavigationUI, setApplication, setContentManagementStart, setAssistantDashboards } from './services'; +import { setClient, setEmbeddable, setNotifications, setOverlays, setSavedAugmentVisLoader, setUISettings, setQueryService, setSavedObjectsClient, setDataSourceEnabled, setDataSourceManagementPlugin, setNavigationUI, setApplication, setContentManagementStart, setAssistantDashboards, setAssistantClient } from './services'; import { VisAugmenterStart } from '../../../src/plugins/vis_augmenter/public'; import { DataPublicPluginStart } from '../../../src/plugins/data/public'; -import { AssistantSetup } from './types'; +import { AssistantSetup, AssistantPublicPluginStart } from './types'; import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public'; import { DataSourcePluginSetup } from '../../../src/plugins/data_source/public'; import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public'; @@ -57,6 +57,7 @@ export interface AlertingStartDeps { data: DataPublicPluginStart; navigation: NavigationPublicPluginStart; contentManagement: ContentManagementPluginStart; + assistantDashboards?: AssistantPublicPluginStart; } export class AlertingPlugin implements Plugin { @@ -200,7 +201,6 @@ export class AlertingPlugin implements Plugin ({ chat: false, alertInsight: false }) }); - setUISettings(core.uiSettings); // Set the HTTP client so it can be pulled into expression fns to make @@ -230,7 +230,7 @@ export class AlertingPlugin implements Plugin {return Promise.resolve({ exists: false });}}) return {}; } } diff --git a/public/services/services.ts b/public/services/services.ts index f908cbb8..bce90304 100644 --- a/public/services/services.ts +++ b/public/services/services.ts @@ -14,7 +14,7 @@ import { EmbeddableStart } from '../../../../src/plugins/embeddable/public'; import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; import { ContentManagementPluginStart } from '../../../../src/plugins/content_management/public'; import { createNullableGetterSetter } from './utils/helper'; -import { AssistantSetup } from '../types'; +import { AssistantSetup, AssistantPublicPluginStart } from '../types'; const ServicesContext = createContext(null); @@ -35,6 +35,9 @@ export const [getAssistantDashboards, setAssistantDashboards] = createGetterSett AssistantSetup | {} >('assistantDashboards'); +export const [getAssistantClient, setAssistantClient] = + createGetterSetter('AssistantClient'); + export const [getEmbeddable, setEmbeddable] = createGetterSetter('embeddable'); export const [getOverlays, setOverlays] = diff --git a/public/types.ts b/public/types.ts index 4734f3a9..f6858725 100644 --- a/public/types.ts +++ b/public/types.ts @@ -10,3 +10,4 @@ */ // @ts-ignore export type { AssistantSetup } from '../../dashboards-assistant/public'; +export type { AssistantPublicPluginStart } from '../../dashboards-assistant/public/';