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

[v10.0.x] Explore: Improve logs volume panel empty state #70255

Merged
merged 1 commit into from
Jun 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions public/app/features/explore/LogsVolumePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock('./Graph/ExploreGraph', () => {
};
});

function renderPanel(logsVolumeData?: DataQueryResponse) {
function renderPanel(logsVolumeData: DataQueryResponse) {
render(
<LogsVolumePanel
absoluteRange={{ from: 0, to: 1 }}
Expand All @@ -30,21 +30,11 @@ function renderPanel(logsVolumeData?: DataQueryResponse) {
}

describe('LogsVolumePanel', () => {
it('shows no volume data', () => {
renderPanel({ state: LoadingState.Done, error: undefined, data: [] });
expect(screen.getByText('No volume data.')).toBeInTheDocument();
});

it('renders logs volume histogram graph', () => {
renderPanel({ state: LoadingState.Done, error: undefined, data: [{}] });
expect(screen.getByText('ExploreGraph')).toBeInTheDocument();
});

it('does not show the panel when there is no volume data', () => {
renderPanel(undefined);
expect(screen.queryByText('Log volume')).not.toBeInTheDocument();
});

it('renders a loading indicator when data is streaming', () => {
renderPanel({ state: LoadingState.Streaming, error: undefined, data: [{}] });
expect(screen.getByTestId('logs-volume-streaming')).toBeInTheDocument();
Expand Down
50 changes: 17 additions & 33 deletions public/app/features/explore/LogsVolumePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getLogsVolumeDataSourceInfo, isLogsVolumeLimited } from '../logs/utils'
import { ExploreGraph } from './Graph/ExploreGraph';

type Props = {
logsVolumeData: DataQueryResponse | undefined;
logsVolumeData: DataQueryResponse;
allLogsVolumeMaximum: number;
absoluteRange: AbsoluteTimeRange;
timeZone: TimeZone;
Expand All @@ -37,10 +37,6 @@ export function LogsVolumePanel(props: Props) {
const spacing = parseInt(theme.spacing(2).slice(0, -2), 10);
const height = 150;

if (props.logsVolumeData === undefined) {
return null;
}

const logsVolumeData = props.logsVolumeData;

const logsVolumeInfo = getLogsVolumeDataSourceInfo(logsVolumeData?.data);
Expand All @@ -55,33 +51,6 @@ export function LogsVolumePanel(props: Props) {
.join('. ');
}

let LogsVolumePanelContent;

if (logsVolumeData?.data) {
if (logsVolumeData.data.length > 0) {
LogsVolumePanelContent = (
<ExploreGraph
graphStyle="lines"
loadingState={logsVolumeData.state ?? LoadingState.Done}
data={logsVolumeData.data}
height={height}
width={width - spacing * 2}
absoluteRange={props.absoluteRange}
onChangeTime={onUpdateTimeRange}
timeZone={timeZone}
splitOpenFn={splitOpen}
tooltipDisplayMode={TooltipDisplayMode.Multi}
onHiddenSeriesChanged={onHiddenSeriesChanged}
anchorToZero
yAxisMaximum={allLogsVolumeMaximum}
eventBus={props.eventBus}
/>
);
} else {
LogsVolumePanelContent = <span>No volume data.</span>;
}
}

let extraInfoComponent = <span>{extraInfo}</span>;

if (logsVolumeData.state === LoadingState.Streaming) {
Expand All @@ -97,7 +66,22 @@ export function LogsVolumePanel(props: Props) {

return (
<div style={{ height }} className={styles.contentContainer}>
{LogsVolumePanelContent}
<ExploreGraph
graphStyle="lines"
loadingState={logsVolumeData.state ?? LoadingState.Done}
data={logsVolumeData.data}
height={height}
width={width - spacing * 2}
absoluteRange={props.absoluteRange}
onChangeTime={onUpdateTimeRange}
timeZone={timeZone}
splitOpenFn={splitOpen}
tooltipDisplayMode={TooltipDisplayMode.Multi}
onHiddenSeriesChanged={onHiddenSeriesChanged}
anchorToZero
yAxisMaximum={allLogsVolumeMaximum}
eventBus={props.eventBus}
/>
{extraInfoComponent && <div className={styles.extraInfoContainer}>{extraInfoComponent}</div>}
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions public/app/features/explore/LogsVolumePanelList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ describe('LogsVolumePanelList', () => {
await userEvent.click(screen.getByRole('button', { name: 'Retry' }));
expect(onLoadCallback).toHaveBeenCalled();
});

it('shows an info message if no log volume data is available', async () => {
renderPanel({ state: LoadingState.Done, data: [] });
expect(screen.getByRole('status')).toBeInTheDocument();
expect(screen.getByText('No logs volume available')).toBeInTheDocument();
});
});
18 changes: 17 additions & 1 deletion public/app/features/explore/LogsVolumePanelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SplitOpen,
TimeZone,
} from '@grafana/data';
import { Button, InlineField, useStyles2 } from '@grafana/ui';
import { Button, InlineField, Alert, useStyles2 } from '@grafana/ui';

import { mergeLogsVolumeDataFrames, isLogsVolumeLimited, getLogsVolumeMaximumRange } from '../logs/utils';

Expand Down Expand Up @@ -98,6 +98,17 @@ export const LogsVolumePanelList = ({
} else if (logsVolumeData?.error !== undefined) {
return <SupplementaryResultError error={logsVolumeData.error} title="Failed to load log volume for this query" />;
}

if (numberOfLogVolumes === 0) {
return (
<div className={styles.alertContainer}>
<Alert severity="info" title="No logs volume available">
No volume information available for the current queries and time range.
</Alert>
</div>
);
}

return (
<div className={styles.listContainer}>
{Object.keys(logVolumes).map((name, index) => {
Expand Down Expand Up @@ -146,6 +157,11 @@ const getStyles = (theme: GrafanaTheme2) => {
font-size: ${theme.typography.bodySmall.fontSize};
color: ${theme.colors.text.secondary};
`,
alertContainer: css`
width: 50%;
min-width: ${theme.breakpoints.values.sm}px;
margin: 0 auto;
`,
};
};

Expand Down