Explore: Create DataSourceWithSupplementaryQueriesSupport interface to support log volume and samples (#61298)

* Create DataSourceWithLogsSampleSupport check and move to 1 place

* Add new SupplementaryQueryType

* Add and change utility functions for loading, storing ancd checking supp queries

* Add logic to redux for processing of new type of supp query

* Implement queryLogsSample used to run samples queries

* Fix tests to include also Log samples

* Add tests

* Temporarily, default to false

* Change comment

* Fix lint error

* Refactor handling of supplementary queries in query.ts

* Fix looping over array

* Remove changes for any => unknowns as in utils.ts

* Fix logic

* Fix incorrect imports after function was moved to different file

* Migrate old log volume key

* Update public/app/features/explore/utils/supplementaryQueries.ts

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>

* Refactor to use DataSourceWithSupplementaryQueriesSupport

* Refactor, improve tests,  change internal API

* Update packages/grafana-data/src/types/logs.ts

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>

* Add deprecation for DataSourceWithLogsVolumeSupport, but still support it

* Update comment with correct new issue

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
This commit is contained in:
Ivana Huckova
2023-01-20 14:20:49 +01:00
committed by GitHub
parent e517cc0cea
commit c106c7700b
17 changed files with 627 additions and 237 deletions

View File

@@ -1,6 +1,8 @@
import { Observable } from 'rxjs';
import { Labels } from './data';
import { DataFrame } from './dataFrame';
import { DataQueryResponse } from './datasource';
import { DataQueryRequest, DataQueryResponse } from './datasource';
import { DataQuery } from './query';
import { AbsoluteTimeRange } from './time';
@@ -176,3 +178,42 @@ export const hasLogsContextSupport = (datasource: unknown): datasource is DataSo
return withLogsSupport.getLogRowContext !== undefined && withLogsSupport.showContextToggle !== undefined;
};
/**
* Types of supplementary queries that can be run in Explore.
* @internal
*/
export enum SupplementaryQueryType {
LogsVolume = 'LogsVolume',
LogsSample = 'LogsSample',
}
/**
* Data sources that support supplementary queries in Explore.
* This will enable users to see additional data when running original queries.
* Supported supplementary queries are defined in SupplementaryQueryType enum.
* @internal
*/
export interface DataSourceWithSupplementaryQueriesSupport<TQuery extends DataQuery> {
getDataProvider(
type: SupplementaryQueryType,
request: DataQueryRequest<TQuery>
): Observable<DataQueryResponse> | undefined;
getSupportedSupplementaryQueryTypes(): SupplementaryQueryType[];
}
export const hasSupplementaryQuerySupport = <TQuery extends DataQuery>(
datasource: unknown,
type: SupplementaryQueryType
): datasource is DataSourceWithSupplementaryQueriesSupport<TQuery> => {
if (!datasource) {
return false;
}
const withSupplementaryQueriesSupport = datasource as DataSourceWithSupplementaryQueriesSupport<TQuery>;
return (
withSupplementaryQueriesSupport.getDataProvider !== undefined &&
withSupplementaryQueriesSupport.getSupportedSupplementaryQueryTypes().includes(type)
);
};

View File

@@ -4,17 +4,20 @@ import { DataQueryRequest, DataQueryResponse } from './datasource';
import { DataQuery } from './query';
/**
* TODO: This should be added to ./logs.ts but because of cross reference between ./datasource.ts and ./logs.ts it can
* be done only after decoupling "logs" from "datasource" (https://github.com/grafana/grafana/pull/39536)
* Support for DataSourceWithLogsVolumeSupport is deprecated and will be removed in the next major version.
* Use DataSourceWithSupplementaryQueriesSupport instead.
*
* @internal
* @deprecated
*/
export interface DataSourceWithLogsVolumeSupport<TQuery extends DataQuery> {
getLogsVolumeDataProvider(request: DataQueryRequest<TQuery>): Observable<DataQueryResponse> | undefined;
}
/**
* @internal
* Support for hasLogsVolumeSupport is deprecated and will be removed in the next major version.
* Use DataSourceWithSupplementaryQueriesSupport and hasSupplementaryQuerySupport instead.
*
* @deprecated
*/
export const hasLogsVolumeSupport = <TQuery extends DataQuery>(
datasource: unknown