Skip to content

Commit

Permalink
Merge branch 'main' into errorhandling-mds
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhswamy authored Oct 22, 2024
2 parents cd0bbf5 + f9ac8d0 commit 200e89a
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 37 deletions.
50 changes: 33 additions & 17 deletions public/components/overview/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EuiButtonEmpty,
EuiToolTip,
} from '@elastic/eui';
import React, { ReactNode, useEffect, useState } from 'react';
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
import { HashRouter, Route, Switch } from 'react-router-dom';
import { useObservable } from 'react-use';
import { EMPTY } from 'rxjs';
Expand Down Expand Up @@ -52,6 +52,18 @@ export const Home = () => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [showGetStarted, setShowGetStarted] = useState<boolean | null>(null); // Initial null state

const canUpdateUiSetting = useMemo(() => {
const capabilities = coreRefs.application?.capabilities;

// When workspace enabled, only workspace owner/OSD admin can update observability:defaultDashboard.
if (capabilities?.workspaces?.enabled) {
const isCurrentWorkspaceOwner = coreRefs.workspaces?.currentWorkspace$.getValue()?.owner;
const isDashboardAdmin = capabilities?.dashboards?.isDashboardAdmin !== false;
return isCurrentWorkspaceOwner || isDashboardAdmin;
}
return true;
}, [coreRefs.workspaces?.currentWorkspace$, coreRefs.application?.capabilities]);

ObsDashboardStateManager.showFlyout$.next(() => () => setIsFlyoutVisible(true));

const loadHomePage = () => {
Expand Down Expand Up @@ -95,14 +107,16 @@ export const Home = () => {
});
ObsDashboardStateManager.isDashboardSelected$.next(true);
} else {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
if (canUpdateUiSetting) {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
}
}
})
.catch((error) => {
Expand Down Expand Up @@ -316,14 +330,16 @@ export const Home = () => {
});
ObsDashboardStateManager.isDashboardSelected$.next(true);
} else {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
if (canUpdateUiSetting) {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
}
}
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
/* eslint-disable react-hooks/exhaustive-deps */

import dateMath from '@elastic/datemath';
import {
EuiBadge,
EuiContextMenu,
Expand All @@ -28,6 +29,12 @@ import round from 'lodash/round';
import React, { useEffect, useMemo, useState } from 'react';
import { DataSourceManagementPluginSetup } from '../../../../../../../src/plugins/data_source_management/public';
import { DataSourceOption } from '../../../../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import {
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
} from '../../../../../common/constants/data_sources';
import { observabilityLogsID } from '../../../../../common/constants/shared';
import { TRACE_ANALYTICS_DATE_FORMAT } from '../../../../../common/constants/trace_analytics';
import { setNavBreadCrumbs } from '../../../../../common/utils/set_nav_bread_crumbs';
import { coreRefs } from '../../../../framework/core_refs';
import { HeaderControlledComponentsWrapper } from '../../../../plugin_helpers/plugin_headerControl';
Expand All @@ -48,11 +55,6 @@ import { SearchBarProps, renderDatePicker } from '../common/search_bar';
import { SpanDetailFlyout } from '../traces/span_detail_flyout';
import { SpanDetailTable } from '../traces/span_detail_table';
import { ServiceMetrics } from './service_metrics';
import {
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
} from '../../../../../common/constants/data_sources';
import { observabilityLogsID } from '../../../../../common/constants/shared';

interface ServiceViewProps extends TraceAnalyticsComponentDeps {
serviceName: string;
Expand All @@ -74,7 +76,6 @@ export function ServiceView(props: ServiceViewProps) {
const [redirect, setRedirect] = useState(false);
const [actionsMenuPopover, setActionsMenuPopover] = useState(false);

const isNewNavEnabled = coreRefs?.chrome?.navGroup?.getNavGroupEnabled();
const refresh = () => {
const DSL = filtersToDsl(
mode,
Expand Down Expand Up @@ -178,11 +179,20 @@ export function ServiceView(props: ServiceViewProps) {
name: 'View logs',
'data-test-subj': 'viewLogsButton',
onClick: () => {
if (isNewNavEnabled) {
// NOTE: Discover has issue with PPL Time filter, hence adding +3/-3 days to actual timestamp
const startTime =
dateMath
.parse(props.startTime)!
.subtract(3, 'days')
.format(TRACE_ANALYTICS_DATE_FORMAT) ?? 'now-3y';
const endTime =
dateMath
.parse(props.endTime, { roundUp: true })!
.add(3, 'days')
.format(TRACE_ANALYTICS_DATE_FORMAT) ?? 'now';
if (coreRefs?.dataSource?.dataSourceEnabled) {
coreRefs?.application!.navigateToApp('data-explorer', {
path: `discover#?_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:${
props.startTime
},to:${props.endTime}))&_q=(filters:!(),query:(dataset:(dataSource:(id:'${
path: `discover#?_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'${startTime}',to:'${endTime}'))&_q=(filters:!(),query:(dataset:(dataSource:(id:'${
props.dataSourceMDSId[0].id ?? ''
}',title:'${props.dataSourceMDSId[0].label}',type:DATA_SOURCE),id:'${
props.dataSourceMDSId[0].id ?? ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import round from 'lodash/round';
import moment from 'moment';
import React, { useEffect, useState } from 'react';
import { HttpSetup } from '../../../../../../../src/core/public';
import {
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
} from '../../../../../common/constants/data_sources';
import { observabilityLogsID } from '../../../../../common/constants/shared';
import { TRACE_ANALYTICS_DATE_FORMAT } from '../../../../../common/constants/trace_analytics';
import { SpanField, TraceAnalyticsMode } from '../../../../../common/types/trace_analytics';
import { coreRefs } from '../../../../framework/core_refs';
Expand Down Expand Up @@ -301,17 +306,34 @@ export function SpanDetailFlyout(props: {
};

const redirectToExplorer = () => {
// NOTE: Discover has issue with PPL Time filter, hence adding +3/-3 days to actual timestamp
const startTime =
moment(span.startTime).subtract(3, 'days').format(TRACE_ANALYTICS_DATE_FORMAT) ?? 'now-3y';
const endTime =
moment(span.endTime).add(3, 'days').format(TRACE_ANALYTICS_DATE_FORMAT) ?? 'now';
const spanId = getSpanValue(span, mode, 'SPAN_ID');
const spanField = getSpanFieldKey(mode, 'SPAN_ID');
coreRefs?.application!.navigateToApp('data-explorer', {
path: `discover#?_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:${
props.startTime
},to:${props.endTime}))&_q=(filters:!(),query:(dataset:(dataSource:(id:'${
props.dataSourceMDSId ?? ''
}',title:${props.dataSourceMDSLabel},type:DATA_SOURCE),id:'${
props.dataSourceMDSId
}::ss4o_logs-*',timeFieldName:time,title:'ss4o_logs-*',type:INDEXES),language:PPL,query:'source%20%3D%20ss4o_logs-*%20%7C%20where%20${spanField}%20%3D%20!'${spanId}!''))`,
});

if (coreRefs?.dataSource?.dataSourceEnabled) {
coreRefs?.application!.navigateToApp('data-explorer', {
path: `discover#?_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'${startTime}',to:'${endTime}'))&_q=(filters:!(),query:(dataset:(dataSource:(id:'${
props.dataSourceMDSId ?? ''
}',title:${props.dataSourceMDSLabel},type:DATA_SOURCE),id:'${
props.dataSourceMDSId ?? ''
}::ss4o_logs-*',timeFieldName:'time',title:'ss4o_logs-*',type:INDEXES),language:PPL,query:'source%20%3D%20ss4o_logs-*%20%7C%20where%20${spanField}%20%3D%20!'${spanId}!''))`,
});
} else {
coreRefs?.application!.navigateToApp(observabilityLogsID, {
path: `#/explorer`,
state: {
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
queryToRun: `source = ss4o_logs-* | where ${spanField}='${spanId}'`,
startTimeRange: startTime,
endTimeRange: endTime,
},
});
}
};

return (
Expand Down
19 changes: 18 additions & 1 deletion public/components/trace_analytics/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {
} from '../../../../../src/core/public';
import {
DataSourceManagementPluginSetup,
DataSourceOption,
DataSourceSelectableConfig,
DataSourceViewConfig,
} from '../../../../../src/plugins/data_source_management/public';
import { DataSourceAttributes } from '../../../../../src/plugins/data_source_management/public/types';
import { TRACE_TABLE_TYPE_KEY } from '../../../common/constants/trace_analytics';
import { TraceAnalyticsMode, TraceQueryMode } from '../../../common/types/trace_analytics';
import { coreRefs } from '../../framework/core_refs';
Expand Down Expand Up @@ -122,7 +124,7 @@ export const Home = (props: HomeProps) => {
const queryParamsOnLoad = new URLSearchParams(window.location.href.split('?')[1]);
const dsFromURL = queryParamsOnLoad.get('datasourceId');

const [dataSourceMDSId, setDataSourceMDSId] = useState([
const [dataSourceMDSId, setDataSourceMDSId] = useState<DataSourceOption>([
{ id: dsFromURL ?? undefined, label: undefined },
]);
const [currentSelectedService, setCurrentSelectedService] = useState('');
Expand Down Expand Up @@ -194,13 +196,28 @@ export const Home = (props: HomeProps) => {
props.notifications,
]);

// This function sets mds label given the id is set in state:dataSourceMDSId
const getDatasourceAttributes = async () => {
const dataSourceAttributes = await coreRefs?.savedObjectsClient?.get<DataSourceAttributes>(
'data-source',
dataSourceMDSId[0].id
);
setDataSourceMDSId([
{ id: dataSourceMDSId[0].id, label: dataSourceAttributes?.attributes.title },
]);
};

useEffect(() => {
handleDataPrepperIndicesExistRequest(
props.http,
setDataPrepperIndicesExist,
dataSourceMDSId[0].id
);
handleJaegerIndicesExistRequest(props.http, setJaegerIndicesExist, dataSourceMDSId[0].id);
// When datasource is loaded form the URL, the label is set to undefined
if (dataSourceMDSId[0].id && dataSourceMDSId[0].label === undefined) {
getDatasourceAttributes();
}
}, [dataSourceMDSId]);

const modes = [
Expand Down
2 changes: 2 additions & 0 deletions public/framework/core_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IToasts,
OverlayStart,
SavedObjectsClientContract,
WorkspacesStart,
} from '../../../../src/core/public';
import { DashboardStart } from '../../../../src/plugins/dashboard/public';
import { DataSourcePluginStart } from '../../../../src/plugins/data_source/public';
Expand All @@ -38,6 +39,7 @@ class CoreRefs {
public dataSource?: DataSourcePluginStart;
public navigation?: NavigationPublicPluginStart;
public contentManagement?: ContentManagementPluginStart;
public workspaces?: WorkspacesStart;
private constructor() {
// ...
}
Expand Down
1 change: 1 addition & 0 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export class ObservabilityPlugin
coreRefs.dataSource = startDeps.dataSource;
coreRefs.navigation = startDeps.navigation;
coreRefs.contentManagement = startDeps.contentManagement;
coreRefs.workspaces = core.workspaces;

// redirect trace URL based on new navigation
if (window.location.pathname.includes(observabilityTracesID)) {
Expand Down

0 comments on commit 200e89a

Please sign in to comment.