Skip to content

Commit

Permalink
Support MDS in feature anywhere (opensearch-project#964)
Browse files Browse the repository at this point in the history
* first setup for alerting MDS support

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fixed some create-monitor issues

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fixed create Monitor

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fixed monitor actions for mds support

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fix jest tests and added neo support for alertTriggers

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* minor bug fixes

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* minor bug fixes

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* featureAnywhere support

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* adPLugin changes

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* resolve merge conflict

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* feature anywhere updated

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* bug fix to clear the form when dataSource is changed

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* test fixed

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* feature-anywhere changes

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* removing unnecessarily added comma

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* bug fixes

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* address the comments

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

---------

Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com>
  • Loading branch information
riysaxen-amzn authored Jun 5, 2024
1 parent 9c4dfb0 commit b892e44
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useColumns } from './helpers';
import { ConfirmUnlinkDetectorModal } from './ConfirmUnlinkModal';
import { deleteAlertingAugmentVisSavedObj } from '../../../utils/savedObjectHelper';
import { getNotifications } from '../../../services';
import { constructUrlFromDataSource } from '../../../pages/utils/helpers';

const AssociatedMonitors = ({ embeddable, closeFlyout, setFlyoutMode, monitors, isAssociateAllowed, limitReachedCallout, setAssociatedMonitors }) => {
const title = embeddable.vis.title;
Expand All @@ -37,7 +38,7 @@ const AssociatedMonitors = ({ embeddable, closeFlyout, setFlyoutMode, monitors,
}, []);
const onEdit = useCallback(
(item) => {
window.open(`alerting#/monitors/${item.id}?action=update-monitor`, '_blank');
window.open(constructUrlFromDataSource(`alerting#/monitors/${item.id}?action=update-monitor`), '_blank');
},
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EuiHealth, EuiLink } from '@elastic/eui';
import { stateToLabel } from '../../../utils/contextMenu/monitors';
import { dateOptionsLong } from '../../../utils/contextMenu/helpers';
import { PLUGIN_NAME } from '../../../../utils/constants';
import { constructUrlFromDataSource } from '../../../pages/utils/helpers';

export const useColumns = ({ onUnlink, onEdit }) => {
const columns = useMemo(
Expand All @@ -19,7 +20,7 @@ export const useColumns = ({ onUnlink, onEdit }) => {
truncateText: true,
width: '50%',
render: (name, monitor) => (
<EuiLink href={`${PLUGIN_NAME}#/monitors/${monitor.id}`} target="_blank">
<EuiLink href={constructUrlFromDataSource(`${PLUGIN_NAME}#/monitors/${monitor.id}`)} target="_blank">
{name}
</EuiLink>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import MonitorsList from './components/MonitorsList';
import MonitorsEditor from './components/MonitorsEditor';
import { monitorTypesForComposition } from '../../../../utils/constants';
import { titleTemplate } from '../../../../utils/helpers';
import { getDataSourceQueryObj } from '../../../utils/helpers';
import { getDataSourceId } from '../../../utils/helpers';

export const getMonitors = async (httpClient) => {
const dataSourceQuery = getDataSourceQueryObj();
const queryObj = {
from: 0,
size: 1000,
search: '',
sortField: 'name',
sortDirection: 'desc',
state: 'all',
dataSourceId: getDataSourceId()
};
const response = await httpClient.get('../api/alerting/monitors', {
query: { ...queryObj, ...dataSourceQuery?.query },
query: queryObj,
});

if (response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ConfigureTriggers extends React.Component {
}

async onQueryMappings() {
const indices = this.props.monitor.inputs[0].search.indices;
const indices = this.props.monitor.inputs[0].search?.indices || [];
try {
const mappings = await this.queryMappings(indices);
const dataTypes = getPathsPerDataType(mappings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default class CreateTrigger extends Component {
}

async onQueryMappings() {
const indices = this.props.monitor.inputs[0].search.indices;
const indices = this.props.monitor.inputs[0].search?.indices || [];
try {
const mappings = await this.queryMappings(indices);
const dataTypes = getPathsPerDataType(mappings);
Expand Down
5 changes: 3 additions & 2 deletions public/pages/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class Main extends Component {
}

async updateBreadcrumbs() {
if (this.props.dataSourceEnabled && this.props.location?.search) {
const dataSourceId = parseQueryStringAndGetDataSource(this.props.location?.search);
if (this.props.dataSourceEnabled && this.props.location) {
const search = this.props.location?.search;
const dataSourceId = search ? parseQueryStringAndGetDataSource(search) : parseQueryStringAndGetDataSource(this.props.location?.pathname);
if (dataSourceId) {
setDataSource({ dataSourceId });
this.setState({
Expand Down
3 changes: 1 addition & 2 deletions public/pages/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ export function parseQueryStringAndGetDataSource(queryString) {
}

export function constructUrlFromDataSource(url) {
const dataSourceId = getDataSource()?.dataSourceId;
return dataSourceEnabled() && dataSourceId ? `${url}&dataSourceId=${dataSourceId}` : url;
return dataSourceEnabled() ? `${url}&dataSourceId=${getDataSource()?.dataSourceId}` : url;
}
20 changes: 19 additions & 1 deletion public/utils/contextMenu/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { createAlertingAction } from '../../actions/alerting_dashboard_action';
import { Action } from '../../../../../src/plugins/ui_actions/public';
import DocumentationTitle from '../../components/FeatureAnywhereContextMenu/DocumentationTitle';
import Container from '../../components/FeatureAnywhereContextMenu/Container';
import { getOverlays } from '../../services';
import { getOverlays, setDataSource } from '../../services';
import { dataSourceEnabled } from '../../pages/utils/helpers';

export const ALERTING_ACTION_CONTEXT = 'ALERTING_ACTION_CONTEXT';
export const ALERTING_ACTION_CONTEXT_GROUP_ID = 'ALERTING_ACTION_CONTEXT_GROUP_ID';
Expand All @@ -38,6 +39,12 @@ export const openContainerInFlyout = async ({
embeddable: any;
detectorId?: string;
}) => {

if (dataSourceEnabled()) {
const indexPattern = embeddable.vis.data.indexPattern;
setDataSourceIdFromSavedObject(indexPattern);
}

const clonedEmbeddable = await _.cloneDeep(embeddable);
const overlayService = getOverlays();
const openFlyout = overlayService.openFlyout;
Expand Down Expand Up @@ -118,3 +125,14 @@ export const getAdAction = () =>
defaultFlyoutMode: 'adMonitor',
}),
});

function setDataSourceIdFromSavedObject(indexPattern: any) {
try {
const foundRef = indexPattern.dataSourceRef
const dataSourceId = foundRef ? foundRef.id : '';
setDataSource({ dataSourceId });
} catch (error) {
console.error("Error fetching index pattern:", error);
}
}

2 changes: 1 addition & 1 deletion public/utils/contextMenu/monitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const parseMonitor = (monitor) => {
date: latestAlert, // this is the last alert time
id: monitor.id,
type: monitor.monitor.monitor_type,
indexes: monitor.monitor.inputs[0].search.indices,
indexes: monitor.monitor.inputs[0].search?.indices || [],
triggers: [{ name: 'example trigger' }],
activeAlerts: monitor.active,
};
Expand Down

0 comments on commit b892e44

Please sign in to comment.