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

Loki: Deprecate resolution #70326

Merged
merged 6 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 6 additions & 6 deletions docs/sources/datasources/loki/query-editor/index.md
Expand Up @@ -208,12 +208,12 @@ 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`. |
| **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`. |
| **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 @@ -99,6 +99,27 @@ describe('LokiQueryBuilderOptions', () => {
expect(screen.getByText('Type: Range')).toBeInTheDocument();
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();
});
});

function setup(queryOverrides: Partial<LokiQuery> = {}) {
Expand Down
Expand Up @@ -4,7 +4,7 @@ import React, { 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 @@ -118,18 +118,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