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

[BugFix] AlertSummary still displays when agents required are not configured #1142

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions public/pages/Dashboard/containers/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
getDataSourceId,
appendCommentsAction,
getIsCommentsEnabled,
getIsAgentConfigured
} from '../../utils/helpers';
import { getUseUpdatedUx } from '../../../services';

Expand Down Expand Up @@ -78,6 +79,7 @@ export default class Dashboard extends Component {
totalTriggers: 0,
chainedAlert: undefined,
commentsEnabled: false,
isAgentConfigured: false,
};
}

Expand All @@ -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;
Expand Down Expand Up @@ -361,6 +373,7 @@ export default class Dashboard extends Component {
totalAlerts,
totalTriggers,
commentsEnabled,
isAgentConfigured,
} = this.state;
const {
monitorIds,
Expand Down Expand Up @@ -444,6 +457,7 @@ export default class Dashboard extends Component {
location,
monitors,
notifications,
isAgentConfigured,
setFlyout,
this.openFlyout,
this.closeFlyout,
Expand Down
4 changes: 2 additions & 2 deletions public/pages/Dashboard/containers/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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();
});
Expand Down
5 changes: 3 additions & 2 deletions public/pages/Dashboard/utils/tableUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const alertColumns = (
location,
monitors,
notifications,
isAgentConfigured,
setFlyout,
openFlyout,
closeFlyout,
Expand Down Expand Up @@ -167,7 +168,7 @@ export const alertColumns = (
}}
data-test-subj={`euiLink_${alert.trigger_name}`}
>
{`${total} alerts`}
{total > 1 ? `${total} alerts`:`${total} alert`}
</EuiLink>
);
const contextProvider = async () => {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion public/pages/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSourceOption>({});
export const dataSourceObservable = new BehaviorSubject<DataSourceOption>({});
export const SUMMARY_AGENT_CONFIG_ID = 'os_summary';
export const LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID = 'os_summary_with_log_pattern';
26 changes: 24 additions & 2 deletions public/pages/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
000FLMS marked this conversation as resolved.
Show resolved Hide resolved
}
}

export async function getIsCommentsEnabled(httpClient) {
let commentsEnabled = await getClusterSetting(httpClient, COMMENTS_ENABLED_SETTING, false);

Expand Down
9 changes: 5 additions & 4 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -57,6 +57,7 @@ export interface AlertingStartDeps {
data: DataPublicPluginStart;
navigation: NavigationPublicPluginStart;
contentManagement: ContentManagementPluginStart;
assistantDashboards?: AssistantPublicPluginStart;
}

export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetupDeps, AlertingStartDeps> {
Expand Down Expand Up @@ -200,7 +201,6 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
}

setAssistantDashboards(assistantDashboards || { getFeatureStatus: () => ({ chat: false, alertInsight: false }) });

setUISettings(core.uiSettings);

// Set the HTTP client so it can be pulled into expression fns to make
Expand Down Expand Up @@ -230,7 +230,7 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
uiActions.addTriggerAction(alertingTriggerAd.id, adAction);
}

public start(core: CoreStart, { visAugmenter, embeddable, data, navigation, contentManagement }: AlertingStartDeps): AlertingStart {
public start(core: CoreStart, { visAugmenter, embeddable, data, navigation, contentManagement, assistantDashboards }: AlertingStartDeps): AlertingStart {
setEmbeddable(embeddable);
setOverlays(core.overlays);
setQueryService(data.query);
Expand All @@ -241,6 +241,7 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
setApplication(core.application);
setContentManagementStart(contentManagement);
registerAlertsCard();
setAssistantClient(assistantDashboards?.assistantClient || {agentConfigExists: (agentConfigName: string | string[], options?: string) => {return Promise.resolve({ exists: false });}})
return {};
}
}
5 changes: 4 additions & 1 deletion public/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BrowserServices | null>(null);

Expand All @@ -35,6 +35,9 @@ export const [getAssistantDashboards, setAssistantDashboards] = createGetterSett
AssistantSetup | {}
>('assistantDashboards');

export const [getAssistantClient, setAssistantClient] =
createGetterSetter<AssistantPublicPluginStart['assistantClient'] | {}>('AssistantClient');

export const [getEmbeddable, setEmbeddable] = createGetterSetter<EmbeddableStart>('embeddable');

export const [getOverlays, setOverlays] =
Expand Down
1 change: 1 addition & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*/
// @ts-ignore
export type { AssistantSetup } from '../../dashboards-assistant/public';
export type { AssistantPublicPluginStart } from '../../dashboards-assistant/public/';
Loading