mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Consolidate logs volume logic (full range and limited) * Fix showing limited histogram message * Test passing meta data to logs volume provider * Improve readability * Clean up types * Add basic support for multiple log volumes * Move the comment back to the right place * Improve readability * Clean up the logic to support Logs Samples * Update docs * Sort log volumes * Provide title to logs volume panel * Move logs volume cache to the provider factory * Add helper functions * Reuse only if queries are the same * Fix alphabetical sorting * Move caching out of the provider * Support errors and loading state * Remove unused code * Consolidate supplementary query utils * Add tests for supplementaryQueries * Update tests * Simplify logs volume extra info * Update tests * Remove comment * Update tests * Fix hiding the histogram for hidden queries * Simplify loading message * Update tests * Wait for full fallback histogram to load before showing it * Fix a typo * Add feedback comments * Move feedback comments to github * Do not filter out hidden queries as they may be used as references in other queries * Group log volume by refId * Support showing fallback histograms per query to avoid duplicates * Improve type-checking * Fix supplementaryQueries.test.ts * Fix logsModel.test.ts * Fix loading fallback results * Fix unit tests * WIP * Update deprecated styles * Simplify test * Simplify rendering zoom info * Update deprecated styles * Simplify getLogsVolumeDataSourceInfo * Simplify isLogsVolumeLimited() * Simplify rendering zoom info
121 lines
3.5 KiB
TypeScript
121 lines
3.5 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import { groupBy } from 'lodash';
|
|
import React, { useMemo } from 'react';
|
|
|
|
import {
|
|
AbsoluteTimeRange,
|
|
DataFrame,
|
|
DataQueryResponse,
|
|
EventBus,
|
|
GrafanaTheme2,
|
|
isLogsVolumeLimited,
|
|
LoadingState,
|
|
SplitOpen,
|
|
TimeZone,
|
|
} from '@grafana/data';
|
|
import { Button, InlineField, useStyles2 } from '@grafana/ui';
|
|
|
|
import { LogsVolumePanel } from './LogsVolumePanel';
|
|
import { SupplementaryResultError } from './SupplementaryResultError';
|
|
|
|
type Props = {
|
|
logsVolumeData: DataQueryResponse | undefined;
|
|
absoluteRange: AbsoluteTimeRange;
|
|
timeZone: TimeZone;
|
|
splitOpen: SplitOpen;
|
|
width: number;
|
|
onUpdateTimeRange: (timeRange: AbsoluteTimeRange) => void;
|
|
onLoadLogsVolume: () => void;
|
|
onHiddenSeriesChanged: (hiddenSeries: string[]) => void;
|
|
eventBus: EventBus;
|
|
};
|
|
|
|
export const LogsVolumePanelList = ({
|
|
logsVolumeData,
|
|
absoluteRange,
|
|
onUpdateTimeRange,
|
|
width,
|
|
onLoadLogsVolume,
|
|
onHiddenSeriesChanged,
|
|
eventBus,
|
|
splitOpen,
|
|
timeZone,
|
|
}: Props) => {
|
|
const logVolumes = useMemo(
|
|
() => groupBy(logsVolumeData?.data || [], 'meta.custom.sourceQuery.refId'),
|
|
[logsVolumeData]
|
|
);
|
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
const numberOfLogVolumes = Object.keys(logVolumes).length;
|
|
|
|
const containsZoomed = Object.values(logVolumes).some((data: DataFrame[]) => {
|
|
const zoomRatio = logsLevelZoomRatio(data, absoluteRange);
|
|
return !isLogsVolumeLimited(data) && zoomRatio && zoomRatio < 1;
|
|
});
|
|
|
|
if (logsVolumeData?.state === LoadingState.Loading) {
|
|
return <span>Loading...</span>;
|
|
}
|
|
if (logsVolumeData?.error !== undefined) {
|
|
return <SupplementaryResultError error={logsVolumeData.error} title="Failed to load log volume for this query" />;
|
|
}
|
|
return (
|
|
<div className={styles.listContainer}>
|
|
{Object.keys(logVolumes).map((name, index) => {
|
|
const logsVolumeData = { data: logVolumes[name] };
|
|
return (
|
|
<LogsVolumePanel
|
|
key={index}
|
|
absoluteRange={absoluteRange}
|
|
width={width}
|
|
logsVolumeData={logsVolumeData}
|
|
onUpdateTimeRange={onUpdateTimeRange}
|
|
timeZone={timeZone}
|
|
splitOpen={splitOpen}
|
|
onLoadLogsVolume={onLoadLogsVolume}
|
|
// TODO: Support filtering level from multiple log levels
|
|
onHiddenSeriesChanged={numberOfLogVolumes > 1 ? () => {} : onHiddenSeriesChanged}
|
|
eventBus={eventBus}
|
|
/>
|
|
);
|
|
})}
|
|
{containsZoomed && (
|
|
<div className={styles.extraInfoContainer}>
|
|
<InlineField label="Reload log volume" transparent>
|
|
<Button size="xs" icon="sync" variant="secondary" onClick={onLoadLogsVolume} id="reload-volume" />
|
|
</InlineField>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
listContainer: css`
|
|
padding-top: 10px;
|
|
`,
|
|
extraInfoContainer: css`
|
|
display: flex;
|
|
justify-content: end;
|
|
position: absolute;
|
|
right: 5px;
|
|
top: 5px;
|
|
`,
|
|
oldInfoText: css`
|
|
font-size: ${theme.typography.bodySmall.fontSize};
|
|
color: ${theme.colors.text.secondary};
|
|
`,
|
|
};
|
|
};
|
|
|
|
function logsLevelZoomRatio(
|
|
logsVolumeData: DataFrame[] | undefined,
|
|
selectedTimeRange: AbsoluteTimeRange
|
|
): number | undefined {
|
|
const dataRange = logsVolumeData && logsVolumeData[0] && logsVolumeData[0].meta?.custom?.absoluteRange;
|
|
return dataRange ? (selectedTimeRange.from - selectedTimeRange.to) / (dataRange.from - dataRange.to) : undefined;
|
|
}
|