mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
Explore/Loki: Fix defaulting to instant query when switching from Prometheus (#40216)
* Loki: Pass only wanted query props when importing from Prometheus * Update * Update public/app/plugins/datasource/loki/language_provider.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Add test * Fix strict error Co-authored-by: Giordano Ricci <me@giordanoricci.com>
This commit is contained in:
parent
b1f56b4863
commit
2f0eccb421
@ -254,6 +254,18 @@ describe('Query imports', () => {
|
||||
});
|
||||
|
||||
describe('prometheus query imports', () => {
|
||||
it('always results in range query type', async () => {
|
||||
const instance = new LanguageProvider(datasource);
|
||||
const result = await instance.importQueries(
|
||||
[{ refId: 'bar', expr: '{job="grafana"}', instant: true, range: false } as DataQuery],
|
||||
{
|
||||
meta: { id: 'prometheus' },
|
||||
} as DataSourceApi
|
||||
);
|
||||
expect(result).toEqual([{ refId: 'bar', expr: '{job="grafana"}', range: true }]);
|
||||
expect(result).not.toHaveProperty('instant');
|
||||
});
|
||||
|
||||
it('returns empty query from metric-only query', async () => {
|
||||
const instance = new LanguageProvider(datasource);
|
||||
const result = await instance.importPrometheusQuery('foo');
|
||||
|
@ -15,6 +15,7 @@ import syntax, { FUNCTIONS, PIPE_PARSERS, PIPE_OPERATORS } from './syntax';
|
||||
import { LokiQuery } from './types';
|
||||
import { dateTime, AbsoluteTimeRange, LanguageProvider, HistoryItem, DataQuery, DataSourceApi } from '@grafana/data';
|
||||
import { PromQuery } from '../prometheus/types';
|
||||
import { GraphiteQuery } from '../graphite/types';
|
||||
|
||||
import LokiDatasource from './datasource';
|
||||
import { CompletionItem, TypeaheadInput, TypeaheadOutput, CompletionItemGroup } from '@grafana/ui';
|
||||
@ -334,16 +335,20 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
return { context, suggestions };
|
||||
}
|
||||
|
||||
async importQueries(queries: DataQuery[], originDataSource: DataSourceApi): Promise<LokiQuery[]> {
|
||||
async importQueries(
|
||||
queries: PromQuery[] | GraphiteQuery[] | DataQuery[],
|
||||
originDataSource: DataSourceApi
|
||||
): Promise<LokiQuery[]> {
|
||||
const datasourceType = originDataSource.meta.id;
|
||||
if (datasourceType === 'prometheus') {
|
||||
return Promise.all(
|
||||
queries.map(async (query) => {
|
||||
const expr = await this.importPrometheusQuery((query as PromQuery).expr);
|
||||
const { ...rest } = query as PromQuery;
|
||||
[...(queries as PromQuery[])].map(async (query) => {
|
||||
const expr = await this.importPrometheusQuery(query.expr);
|
||||
const { refId } = query;
|
||||
return {
|
||||
...rest,
|
||||
expr,
|
||||
refId,
|
||||
range: true,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user