Loki: Add maxLines option to getParserAndLabelKeys (#77460)

* Loki: Add logsCount option to getParserAndLabelKeys

* Rename logsCount to maxLines
This commit is contained in:
Ivana Huckova
2023-11-01 17:22:33 +01:00
committed by GitHub
parent 5d5f8dfc52
commit a38c9d4f44
4 changed files with 58 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
import { AbstractLabelOperator, DataFrame } from '@grafana/data';
import LanguageProvider from './LanguageProvider';
import { LokiDatasource } from './datasource';
import { DEFAULT_MAX_LINES_SAMPLE, LokiDatasource } from './datasource';
import { createLokiDatasource, createMetadataRequest } from './mocks';
import {
extractLogParserFromDataFrame,
@@ -275,6 +275,40 @@ describe('Query imports', () => {
});
expect(extractLogParserFromDataFrameMock).not.toHaveBeenCalled();
});
it('calls dataSample with correct default maxLines', async () => {
jest.spyOn(datasource, 'getDataSamples').mockResolvedValue([]);
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
extractedLabelKeys: [],
unwrapLabelKeys: [],
hasJSON: false,
hasLogfmt: false,
hasPack: false,
});
expect(datasource.getDataSamples).toHaveBeenCalledWith({
expr: '{place="luna"}',
maxLines: DEFAULT_MAX_LINES_SAMPLE,
refId: 'data-samples',
});
});
it('calls dataSample with correctly set sampleSize', async () => {
jest.spyOn(datasource, 'getDataSamples').mockResolvedValue([]);
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}', { maxLines: 5 })).toEqual({
extractedLabelKeys: [],
unwrapLabelKeys: [],
hasJSON: false,
hasLogfmt: false,
hasPack: false,
});
expect(datasource.getDataSamples).toHaveBeenCalledWith({
expr: '{place="luna"}',
maxLines: 5,
refId: 'data-samples',
});
});
});
});