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

[Backport 2.x] [Bug fix] Metrics datasource #2245

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
7 changes: 4 additions & 3 deletions public/components/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

interface MetricsProps {
parentBreadcrumb: ChromeBreadcrumb;
renderProps: RouteComponentProps<any, StaticContext, any>;

Check warning on line 35 in public/components/metrics/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 35 in public/components/metrics/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
pplService: PPLService;
savedObjects: SavedObjects;
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
Expand All @@ -55,7 +55,7 @@
// Side bar constants
const [selectedDataSource, setSelectedDataSource] = useState<OptionType[]>([]);
const [selectedOTIndex, setSelectedOTIndex] = useState([]);
const [dataSourceMDSId, setDataSourceMDSId] = useState<string>('');
const [dataSourceMDSId, setDataSourceMDSId] = useState<string | null>(null);
const [reloadSidebar, setReloadSidebar] = useState<boolean>(false);

useEffect(() => {
Expand All @@ -77,7 +77,7 @@
const dispatch = useDispatch();

const onSelectedDataSource = async (dataSources: DataSourceOption[]) => {
const id = dataSources[0] ? dataSources[0].id : '';
const id = dataSources[0] ? dataSources[0].id : null;
setDataSourceMDSId(id);
debounce(() => {
dispatch(setSelectedDataSourceMDSId(id));
Expand All @@ -100,7 +100,7 @@
}}
/>
);
}, [setActionMenu, savedObjectsMDSClient.client, notifications]);

Check warning on line 103 in public/components/metrics/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has a missing dependency: 'onSelectedDataSource'. Either include it or remove the dependency array

return (
<>
Expand All @@ -111,7 +111,7 @@
path={['/:id', '/']}
render={(routerProps) => (
<div>
{reloadSidebar && (
{(dataSourceEnabled ? dataSourceMDSId !== null : true) && reloadSidebar && (
<EuiPage>
<EuiPageBody component="div">
<TopMenu />
Expand All @@ -133,6 +133,7 @@
selectedOTIndex={selectedOTIndex}
setSelectedOTIndex={setSelectedOTIndex}
dataSourceMDSId={dataSourceMDSId}
dataSourceEnabled={dataSourceEnabled}
/>
</EuiResizablePanel>

Expand Down
9 changes: 8 additions & 1 deletion public/components/metrics/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
selectedOTIndex: React.SetStateAction<Array<{}>>;
setSelectedOTIndex: React.Dispatch<React.SetStateAction<unknown>>;
additionalSelectedMetricId?: string;
dataSourceMDSId: string;
dataSourceMDSId: string | null;
dataSourceEnabled: boolean;
}
export const Sidebar = ({
selectedDataSource,
Expand All @@ -49,6 +50,7 @@
setSelectedOTIndex,
additionalSelectedMetricId,
dataSourceMDSId,
dataSourceEnabled,
}: SideBarMenuProps) => {
const dispatch = useDispatch();
const [availableOTDocuments, setAvailableOTDocuments] = useState([]);
Expand All @@ -67,7 +69,7 @@
setSelectedOTIndex([]);
await dispatch(clearSelectedMetrics());
})();
}, [dataSourceMDSId]);

Check warning on line 72 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'dispatch', 'setSelectedDataSource', and 'setSelectedOTIndex'. Either include them or remove the dependency array. If 'setSelectedDataSource' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
batch(() => {
Expand All @@ -88,13 +90,18 @@
await dispatch(addSelectedMetric(additionalMetric, dataSourceMDSId));
})();
}
}, [additionalMetric?.id, dataSourceMDSId]);

Check warning on line 93 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'additionalMetric' and 'dispatch'. Either include them or remove the dependency array

const selectedMetricsList = useMemo(() => {
return selectedMetricsIds.map((id) => selectedMetrics[id]).filter((m) => m); // filter away null entries
}, [selectedMetrics, selectedMetricsIds, dataSourceMDSId]);

Check warning on line 97 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has an unnecessary dependency: 'dataSourceMDSId'. Either exclude it or remove the dependency array

useEffect(() => {
// If data source is enabled but is still null prevent the invalid call
if (dataSourceEnabled && dataSourceMDSId === null) {
return;
}

if (selectedOTIndex.length > 0 && selectedDataSource[0]?.label === 'OpenTelemetry') {
const fetchOtelDocuments = async () => {
try {
Expand All @@ -103,7 +110,7 @@
dataSourceMDSId
)();
const availableOtelDocuments = documentNames?.aggregations?.distinct_names?.buckets.map(
(item: any) => {

Check warning on line 113 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return {
id: item.key,
name: item.key,
Expand All @@ -129,21 +136,21 @@
};
fetchOtelDocuments();
}
}, [dispatch, selectedDataSource, selectedOTIndex, dataSourceMDSId]);

Check warning on line 139 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'dataSourceEnabled'. Either include it or remove the dependency array

const indexPicker = useMemo(() => {
const isOpenTelemetry = selectedDataSource[0]?.label === 'OpenTelemetry' ? true : false;
if (isOpenTelemetry) {
return <IndexPicker otelIndices={otelIndices} setSelectedOTIndex={setSelectedOTIndex} />;
}
}, [selectedDataSource, dataSourceMDSId]);

Check warning on line 146 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has missing dependencies: 'otelIndices' and 'setSelectedOTIndex'. Either include them or remove the dependency array

const availableMetrics = useMemo(() => {
if (selectedDataSource[0]?.label === 'OpenTelemetry' && selectedOTIndex.length > 0)
return promethuesMetrics;
else if (selectedDataSource[0]?.label === 'Prometheus') return promethuesMetrics;
else return [];
}, [

Check warning on line 153 in public/components/metrics/sidebar/sidebar.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has unnecessary dependencies: 'availableOTDocuments' and 'dataSourceMDSId'. Either exclude them or remove the dependency array
promethuesMetrics,
selectedDataSource,
availableOTDocuments,
Expand Down
Loading