-
Notifications
You must be signed in to change notification settings - Fork 55
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
[Bug fix] Metrics datasource #2242
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -49,6 +50,7 @@ | |
setSelectedOTIndex, | ||
additionalSelectedMetricId, | ||
dataSourceMDSId, | ||
dataSourceEnabled, | ||
}: SideBarMenuProps) => { | ||
const dispatch = useDispatch(); | ||
const [availableOTDocuments, setAvailableOTDocuments] = useState([]); | ||
|
@@ -67,7 +69,7 @@ | |
setSelectedOTIndex([]); | ||
await dispatch(clearSelectedMetrics()); | ||
})(); | ||
}, [dataSourceMDSId]); | ||
Check warning on line 72 in public/components/metrics/sidebar/sidebar.tsx GitHub Actions / Lint
|
||
|
||
useEffect(() => { | ||
batch(() => { | ||
|
@@ -88,13 +90,18 @@ | |
await dispatch(addSelectedMetric(additionalMetric, dataSourceMDSId)); | ||
})(); | ||
} | ||
}, [additionalMetric?.id, dataSourceMDSId]); | ||
|
||
const selectedMetricsList = useMemo(() => { | ||
return selectedMetricsIds.map((id) => selectedMetrics[id]).filter((m) => m); // filter away null entries | ||
}, [selectedMetrics, selectedMetricsIds, dataSourceMDSId]); | ||
|
||
useEffect(() => { | ||
// If data source is enabled but is still null prevent the invalid call | ||
if (dataSourceEnabled && dataSourceMDSId === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if local cluster is selected, what would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Local cluster is just an empty string "" when selected it get sets and is no longer null |
||
return; | ||
} | ||
|
||
if (selectedOTIndex.length > 0 && selectedDataSource[0]?.label === 'OpenTelemetry') { | ||
const fetchOtelDocuments = async () => { | ||
try { | ||
|
@@ -103,7 +110,7 @@ | |
dataSourceMDSId | ||
)(); | ||
const availableOtelDocuments = documentNames?.aggregations?.distinct_names?.buckets.map( | ||
(item: any) => { | ||
return { | ||
id: item.key, | ||
name: item.key, | ||
|
@@ -129,21 +136,21 @@ | |
}; | ||
fetchOtelDocuments(); | ||
} | ||
}, [dispatch, selectedDataSource, selectedOTIndex, dataSourceMDSId]); | ||
|
||
const indexPicker = useMemo(() => { | ||
const isOpenTelemetry = selectedDataSource[0]?.label === 'OpenTelemetry' ? true : false; | ||
if (isOpenTelemetry) { | ||
return <IndexPicker otelIndices={otelIndices} setSelectedOTIndex={setSelectedOTIndex} />; | ||
} | ||
}, [selectedDataSource, dataSourceMDSId]); | ||
|
||
const availableMetrics = useMemo(() => { | ||
if (selectedDataSource[0]?.label === 'OpenTelemetry' && selectedOTIndex.length > 0) | ||
return promethuesMetrics; | ||
else if (selectedDataSource[0]?.label === 'Prometheus') return promethuesMetrics; | ||
else return []; | ||
}, [ | ||
promethuesMetrics, | ||
selectedDataSource, | ||
availableOTDocuments, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one question: What's the condition when
dataSources[0]
will be undefined and we have to set the id asnull
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only condition this should be triggered is when a workspace is created and its datasource is removed putting it in a state where it has no data sources available at all. In this case metrics won't work and we don't want to display options.
We should probably have an empty state for this such as " No connected data source with redirection to associate one".