Loki: Deprecate resolution (#70326)

* Loki: Deprecate resolution and only show it if it was selected before

* Deprecate

* Fix merge, add missing brackets
pull/70503/head
Ivana Huckova 2 years ago committed by GitHub
parent a83a040f35
commit 55d18361dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      docs/sources/datasources/loki/query-editor/index.md
  2. 2
      docs/sources/developers/kinds/composable/loki/dataquery/schema-reference.md
  3. 2
      packages/grafana-schema/src/raw/composable/loki/dataquery/x/LokiDataQuery_types.gen.ts
  4. 2
      pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go
  5. 2
      public/app/plugins/datasource/loki/dataquery.cue
  6. 2
      public/app/plugins/datasource/loki/dataquery.gen.ts
  7. 21
      public/app/plugins/datasource/loki/querybuilder/components/LokiQueryBuilderOptions.test.tsx
  8. 34
      public/app/plugins/datasource/loki/querybuilder/components/LokiQueryBuilderOptions.tsx

@ -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

@ -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. |

@ -56,7 +56,7 @@ export interface LokiDataQuery extends common.DataQuery {
*/
range?: boolean;
/**
* Used to scale the interval value.
* @deprecated, now use step.
*/
resolution?: number;
/**

@ -103,7 +103,7 @@ type LokiDataQuery struct {
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
// Used to scale the interval value.
// @deprecated, now use step.
Resolution *int64 `json:"resolution,omitempty"`
// Used to set step value for range queries.

@ -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.

@ -57,7 +57,7 @@ export interface Loki extends common.DataQuery {
*/
range?: boolean;
/**
* Used to scale the interval value.
* @deprecated, now use step.
*/
resolution?: number;
/**

@ -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();

@ -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';
@ -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 && (

Loading…
Cancel
Save