Skip to content

Commit

Permalink
Loki: Deprecate resolution (#70326)
Browse files Browse the repository at this point in the history
* Loki: Deprecate resolution and only show it if it was selected before

* Deprecate

* Fix merge, add missing brackets
  • Loading branch information
ivanahuckova authored and harisrozajac committed Jun 30, 2023
1 parent b5b8cfa commit 7eba492
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 25 deletions.
14 changes: 7 additions & 7 deletions docs/sources/datasources/loki/query-editor/index.md
Expand Up @@ -208,13 +208,13 @@ This section is only shown if the `Explain query` switch from the query editor t

## Configure query settings

| Name | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Type** | Selects the query type to run. The `instant` type queries against a single point in time. We use the "To" time from the time range. The `range` type queries over the selected range of time. |
| **Line limit** | Defines the upper limit for the number of log lines returned by a query. The default is Loki's configured maximum lines limit. |
| **Legend** | _(Available only in a dashboard)_ Controls the time series name, using a name or pattern. For example, `{{hostname}}` is replaced with the label value for the label `hostname`. |
| **Step** | Sets the step parameter of Loki metrics queries. The default value equals to the value of `$__interval` variable, which is calculated using the time range and the width of the graph (the number of pixels). |
| **Resolution** | Sets the step parameter of Loki metrics range queries. With a resolution of `1/1`, each pixel corresponds to one data point. `1/2` retrieves one data point for every other pixel, `1/10` retrieves one data point per 10 pixels, and so on. Lower resolutions perform better. |
| Name | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Type** | Selects the query type to run. The `instant` type queries against a single point in time. We use the "To" time from the time range. The `range` type queries over the selected range of time. |
| **Line limit** | Defines the upper limit for the number of log lines returned by a query. The default is Loki's configured maximum lines limit. |
| **Legend** | _(Available only in a dashboard)_ Controls the time series name, using a name or pattern. For example, `{{hostname}}` is replaced with the label value for the label `hostname`. |
| **Step** | Sets the step parameter of Loki metrics queries. The default value equals to the value of `$__interval` variable, which is calculated using the time range and the width of the graph (the number of pixels). |
| **Resolution** | Deprecated. Sets the step parameter of Loki metrics range queries. With a resolution of `1/1`, each pixel corresponds to one data point. `1/2` retrieves one data point for every other pixel, `1/10` retrieves one data point per 10 pixels, and so on. Lower resolutions perform better. |

## Apply annotations

Expand Down
Expand Up @@ -25,7 +25,7 @@ title: LokiDataQuery kind
| `maxLines` | integer | No | | Used to limit the number of log rows returned. |
| `queryType` | string | No | | Specify the query flavor<br/>TODO make this required and give it a default |
| `range` | boolean | No | | @deprecated, now use queryType. |
| `resolution` | integer | No | | Used to scale the interval value. |
| `resolution` | integer | No | | @deprecated, now use step. |
| `step` | string | No | | Used to set step value for range queries. |


Expand Up @@ -56,7 +56,7 @@ export interface LokiDataQuery extends common.DataQuery {
*/
range?: boolean;
/**
* Used to scale the interval value.
* @deprecated, now use step.
*/
resolution?: number;
/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/app/plugins/datasource/loki/dataquery.cue
Expand Up @@ -37,7 +37,7 @@ composableKinds: DataQuery: {
legendFormat?: string
// Used to limit the number of log rows returned.
maxLines?: int64
// Used to scale the interval value.
// @deprecated, now use step.
resolution?: int64
editorMode?: #QueryEditorMode
// @deprecated, now use queryType.
Expand Down
2 changes: 1 addition & 1 deletion public/app/plugins/datasource/loki/dataquery.gen.ts
Expand Up @@ -57,7 +57,7 @@ export interface Loki extends common.DataQuery {
*/
range?: boolean;
/**
* Used to scale the interval value.
* @deprecated, now use step.
*/
resolution?: number;
/**
Expand Down
Expand Up @@ -100,6 +100,27 @@ describe('LokiQueryBuilderOptions', () => {
expect(screen.getByText('Step: 1m')).toBeInTheDocument();
});

it('does not shows resolution field if resolution is not set', async () => {
setup({ expr: 'rate({foo="bar"}[5m]' });
await userEvent.click(screen.getByTitle('Click to edit options'));
expect(screen.queryByText('Resolution')).not.toBeInTheDocument();
});

it('does not shows resolution field if resolution is set to default value 1', async () => {
setup({ expr: 'rate({foo="bar"}[5m]', resolution: 1 });
await userEvent.click(screen.getByTitle('Click to edit options'));
expect(screen.queryByText('Resolution')).not.toBeInTheDocument();
});

it('does shows resolution field with warning if resolution is set to non-default value', async () => {
setup({ expr: 'rate({foo="bar"}[5m]', resolution: 2 });
await userEvent.click(screen.getByTitle('Click to edit options'));
expect(screen.getByText('Resolution')).toBeInTheDocument();
expect(
screen.getByText("The 'Resolution' is deprecated. Use 'Step' editor instead to change step parameter.")
).toBeInTheDocument();
});

it('shows correct options for metric query with invalid step', async () => {
setup({ expr: 'rate({foo="bar"}[5m]', step: 'abc' });
expect(screen.queryByText('Line limit: 20')).not.toBeInTheDocument();
Expand Down
Expand Up @@ -4,7 +4,7 @@ import React, { useMemo, useState } from 'react';
import { CoreApp, isValidDuration, SelectableValue } from '@grafana/data';
import { EditorField, EditorRow } from '@grafana/experimental';
import { config, reportInteraction } from '@grafana/runtime';
import { AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
import { Alert, AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
import { QueryOptionGroup } from 'app/plugins/datasource/prometheus/querybuilder/shared/QueryOptionGroup';

import { preprocessMaxLines, queryTypeOptions, RESOLUTION_OPTIONS } from '../../components/LokiOptionFields';
Expand Down Expand Up @@ -127,18 +127,26 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
onCommitChange={onStepChange}
/>
</EditorField>
<EditorField
label="Resolution"
tooltip="Changes the step parameter of Loki metrics range queries. With a resolution of 1/1, each pixel corresponds to one data point. 1/10 retrieves one data point per 10 pixels. Lower resolutions perform better."
>
<Select
isSearchable={false}
onChange={onResolutionChange}
options={RESOLUTION_OPTIONS}
value={query.resolution || 1}
aria-label="Select resolution"
/>
</EditorField>
{query.resolution !== undefined && query.resolution > 1 && (
<>
<EditorField
label="Resolution"
tooltip="Changes the step parameter of Loki metrics range queries. With a resolution of 1/1, each pixel corresponds to one data point. 1/10 retrieves one data point per 10 pixels. Lower resolutions perform better."
>
<Select
isSearchable={false}
onChange={onResolutionChange}
options={RESOLUTION_OPTIONS}
value={query.resolution || 1}
aria-label="Select resolution"
/>
</EditorField>
<Alert
severity="warning"
title="The 'Resolution' is deprecated. Use 'Step' editor instead to change step parameter."
/>
</>
)}
</>
)}
{config.featureToggles.lokiQuerySplittingConfig && config.featureToggles.lokiQuerySplitting && (
Expand Down

0 comments on commit 7eba492

Please sign in to comment.