Loki: Change format of query builder hints (#60228)

* change format of query builder hints

* fix tests

* add hint property on query actions

* revert changes to prometheus hints

* respond to feedback

* fix failing tests

* trigger drone

Co-authored-by: Matias Chomicki <matyax@gmail.com>
This commit is contained in:
Gareth Dawson
2022-12-19 16:28:46 +00:00
committed by GitHub
parent 158502572e
commit 90185bea00
4 changed files with 9 additions and 4 deletions

View File

@@ -511,6 +511,7 @@ export interface DataQueryTimings {
}
export interface QueryFix {
title?: string;
label: string;
action?: QueryFixAction;
}

View File

@@ -23,6 +23,7 @@ export function getQueryHints(query: string, series: DataFrame[]): QueryHint[] {
type: 'ADD_JSON_PARSER',
label: 'Selected log stream selector has JSON formatted logs.',
fix: {
title: 'add json parser',
label: 'Consider using JSON parser.',
action: {
type: 'ADD_JSON_PARSER',
@@ -37,6 +38,7 @@ export function getQueryHints(query: string, series: DataFrame[]): QueryHint[] {
type: 'ADD_LOGFMT_PARSER',
label: 'Selected log stream selector has logfmt formatted logs.',
fix: {
title: 'add logfmt parser',
label: 'Consider using logfmt parser to turn key-value pairs in your log lines to labels.',
action: {
type: 'ADD_LOGFMT_PARSER',
@@ -57,6 +59,7 @@ export function getQueryHints(query: string, series: DataFrame[]): QueryHint[] {
type: 'ADD_NO_PIPELINE_ERROR',
label: 'Some logs in your selected log streams have parsing error.',
fix: {
title: 'remove pipeline errors',
label: 'Consider filtering out logs with parsing errors.',
action: {
type: 'ADD_NO_PIPELINE_ERROR',
@@ -79,6 +82,7 @@ export function getQueryHints(query: string, series: DataFrame[]): QueryHint[] {
type: 'ADD_LEVEL_LABEL_FORMAT',
label: `Some logs in your selected log stream have "${levelLikeLabel}" label.`,
fix: {
title: 'add label level format',
label: `If ${levelLikeLabel} label has level values, consider using label_format to rename it to "level". Level label can be then visualized in log volumes.`,
action: {
type: 'ADD_LEVEL_LABEL_FORMAT',

View File

@@ -149,7 +149,7 @@ describe('PromQueryBuilder', () => {
});
await openMetricSelect(container);
await userEvent.click(screen.getByText('histogram_metric_bucket'));
await waitFor(() => expect(screen.getByText('hint: add histogram_quantile()')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('hint: add histogram_quantile')).toBeInTheDocument());
});
it('shows hints for counter metrics', async () => {
@@ -160,7 +160,7 @@ describe('PromQueryBuilder', () => {
});
await openMetricSelect(container);
await userEvent.click(screen.getByText('histogram_metric_sum'));
await waitFor(() => expect(screen.getByText('hint: add rate()')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('hint: add rate')).toBeInTheDocument());
});
it('shows hints for counter metrics', async () => {
@@ -171,7 +171,7 @@ describe('PromQueryBuilder', () => {
});
await openMetricSelect(container);
await userEvent.click(screen.getByText('histogram_metric_sum'));
await waitFor(() => expect(screen.getByText('hint: add rate()')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('hint: add rate')).toBeInTheDocument());
});
it('shows multiple hints', async () => {

View File

@@ -56,7 +56,7 @@ export const QueryBuilderHints = <T extends PromLokiVisualQuery>({
size="sm"
className={styles.hint}
>
{'hint: ' + hint.fix?.action?.type.toLowerCase().replace('_', ' ') + '()'}
hint: {hint.fix?.title || hint.fix?.action?.type.toLowerCase().replace('_', ' ')}
</Button>
</Tooltip>
);