-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[DataUsage][Serverless] Data usage metrics page enhancements #195556
Merged
ashokaditya
merged 20 commits into
elastic:main
from
ashokaditya:feat/data-usage-metrics-ux-api-192965-192966
Oct 14, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e0d9128
refactor page vs component logic
ashokaditya 547ace0
add data streams filter
ashokaditya 78a9ceb
use metering stats instead to get data streams list
ashokaditya dfaf1e5
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine 0e613d3
Merge branch 'main' into feat/data-usage-metrics-ux-api-192965-192966
ashokaditya 8489b66
Merge branch 'main' into feat/data-usage-metrics-ux-api-192965-192966
ashokaditya b68a3fa
fix checks
ashokaditya 06be6d8
fix bad merge
ashokaditya d6c9c79
remove `clear all` as payload is required
ashokaditya 92e60db
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 1790cda
Revert "remove `clear all` as payload is required"
ashokaditya ba31edd
fix type imports
ashokaditya 94aa478
add a callout when no data streams selected
ashokaditya 9f32e32
hide metrics filter for now
ashokaditya dc2587a
comment
ashokaditya 6c1d4a8
remove console.log
ashokaditya e7f32cd
fix
ashokaditya 68369f4
Merge branch 'main' into feat/data-usage-metrics-ux-api-192965-192966
ashokaditya d9fe7a3
fix
ashokaditya f9b4718
cleanup schema
ashokaditya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
x-pack/plugins/data_usage/public/app/components/data_usage_metrics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useCallback, useEffect, memo, useState } from 'react'; | ||
import { css } from '@emotion/react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiLoadingElastic, EuiCallOut } from '@elastic/eui'; | ||
import { Charts } from './charts'; | ||
import { useBreadcrumbs } from '../../utils/use_breadcrumbs'; | ||
import { useKibanaContextForPlugin } from '../../utils/use_kibana'; | ||
import { PLUGIN_NAME } from '../../../common'; | ||
import { useGetDataUsageMetrics } from '../../hooks/use_get_usage_metrics'; | ||
import { useDataUsageMetricsUrlParams } from '../hooks/use_charts_url_params'; | ||
import { DEFAULT_DATE_RANGE_OPTIONS, useDateRangePicker } from '../hooks/use_date_picker'; | ||
import { DEFAULT_METRIC_TYPES, UsageMetricsRequestBody } from '../../../common/rest_types'; | ||
import { ChartFilters } from './filters/charts_filters'; | ||
import { UX_LABELS } from '../translations'; | ||
|
||
const EuiItemCss = css` | ||
width: 100%; | ||
`; | ||
|
||
const FlexItemWithCss = memo(({ children }: { children: React.ReactNode }) => ( | ||
<EuiFlexItem css={EuiItemCss}>{children}</EuiFlexItem> | ||
)); | ||
|
||
export const DataUsageMetrics = () => { | ||
const { | ||
services: { chrome, appParams }, | ||
} = useKibanaContextForPlugin(); | ||
|
||
const { | ||
metricTypes: metricTypesFromUrl, | ||
dataStreams: dataStreamsFromUrl, | ||
startDate: startDateFromUrl, | ||
endDate: endDateFromUrl, | ||
setUrlMetricTypesFilter, | ||
setUrlDateRangeFilter, | ||
} = useDataUsageMetricsUrlParams(); | ||
|
||
const [metricsFilters, setMetricsFilters] = useState<UsageMetricsRequestBody>({ | ||
metricTypes: [...DEFAULT_METRIC_TYPES], | ||
dataStreams: [], | ||
from: DEFAULT_DATE_RANGE_OPTIONS.startDate, | ||
to: DEFAULT_DATE_RANGE_OPTIONS.endDate, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!metricTypesFromUrl) { | ||
setUrlMetricTypesFilter(metricsFilters.metricTypes.join(',')); | ||
} | ||
if (!startDateFromUrl || !endDateFromUrl) { | ||
setUrlDateRangeFilter({ startDate: metricsFilters.from, endDate: metricsFilters.to }); | ||
} | ||
}, [ | ||
endDateFromUrl, | ||
metricTypesFromUrl, | ||
metricsFilters.from, | ||
metricsFilters.metricTypes, | ||
metricsFilters.to, | ||
setUrlDateRangeFilter, | ||
setUrlMetricTypesFilter, | ||
startDateFromUrl, | ||
]); | ||
|
||
useEffect(() => { | ||
setMetricsFilters((prevState) => ({ | ||
...prevState, | ||
metricTypes: metricTypesFromUrl?.length ? metricTypesFromUrl : prevState.metricTypes, | ||
dataStreams: dataStreamsFromUrl?.length ? dataStreamsFromUrl : prevState.dataStreams, | ||
})); | ||
}, [metricTypesFromUrl, dataStreamsFromUrl]); | ||
|
||
const { dateRangePickerState, onRefreshChange, onTimeChange } = useDateRangePicker(); | ||
|
||
const { | ||
error, | ||
data, | ||
isFetching, | ||
isFetched, | ||
refetch: refetchDataUsageMetrics, | ||
} = useGetDataUsageMetrics( | ||
{ | ||
...metricsFilters, | ||
from: dateRangePickerState.startDate, | ||
to: dateRangePickerState.endDate, | ||
}, | ||
{ | ||
retry: false, | ||
} | ||
); | ||
|
||
const onRefresh = useCallback(() => { | ||
refetchDataUsageMetrics(); | ||
}, [refetchDataUsageMetrics]); | ||
|
||
const onChangeDataStreamsFilter = useCallback( | ||
(selectedDataStreams: string[]) => { | ||
setMetricsFilters((prevState) => ({ ...prevState, dataStreams: selectedDataStreams })); | ||
}, | ||
[setMetricsFilters] | ||
); | ||
|
||
const onChangeMetricTypesFilter = useCallback( | ||
(selectedMetricTypes: string[]) => { | ||
setMetricsFilters((prevState) => ({ ...prevState, metricTypes: selectedMetricTypes })); | ||
}, | ||
[setMetricsFilters] | ||
); | ||
|
||
useBreadcrumbs([{ text: PLUGIN_NAME }], appParams, chrome); | ||
|
||
return ( | ||
<EuiFlexGroup alignItems="flexStart" direction="column"> | ||
<FlexItemWithCss> | ||
<ChartFilters | ||
dateRangePickerState={dateRangePickerState} | ||
isDataLoading={isFetching} | ||
onClick={refetchDataUsageMetrics} | ||
onRefresh={onRefresh} | ||
onRefreshChange={onRefreshChange} | ||
onTimeChange={onTimeChange} | ||
onChangeDataStreamsFilter={onChangeDataStreamsFilter} | ||
onChangeMetricTypesFilter={onChangeMetricTypesFilter} | ||
showMetricsTypesFilter={false} | ||
/> | ||
</FlexItemWithCss> | ||
{!isFetching && error?.message && ( | ||
<FlexItemWithCss> | ||
<EuiCallOut | ||
size="s" | ||
title={UX_LABELS.noDataStreamsSelected} | ||
iconType="iInCircle" | ||
color="warning" | ||
/> | ||
</FlexItemWithCss> | ||
)} | ||
<FlexItemWithCss> | ||
{isFetched && data?.metrics ? ( | ||
<Charts data={data} /> | ||
) : isFetching ? ( | ||
<EuiLoadingElastic /> | ||
) : null} | ||
</FlexItemWithCss> | ||
</EuiFlexGroup> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
useGetDataUsageDataStreams
needs to be called somewhere on this page first because we have to get the top 10 by default (looks like nothing is selected by default at the moment) and have them selected by default when the user first lands.dataStreams
will be required for the/metrics
endpoint so getting the data streams has to happen first so we can pass it to/metrics
. Datastreams can instead be passed down as props to theChartFilters
? Does that make sense? Ideally we can call them in parallel but I think we agreed this simplifies things and avoids us having to "get all" data streams in/metrics
. Might make more sense after my PR goes in. #195640