Live: optionally send queries over websocket connection (#41653)

Co-authored-by: ArturWierzbicki <artur.wierzbicki@grafana.com>
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Alexander Emelin
2022-01-05 08:02:12 -08:00
committed by GitHub
co-authored by ArturWierzbicki Ryan McKinley
parent bfecbdc0bd
commit b4204628e4
10 changed files with 103 additions and 15 deletions
@@ -52,6 +52,7 @@ export interface FeatureToggles {
recordedQueries: boolean;
newNavigation: boolean;
fullRangeLogsVolume: boolean;
queryOverLive: boolean;
dashboardPreviews: boolean;
}
+1
View File
@@ -69,6 +69,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
recordedQueries: false,
newNavigation: false,
fullRangeLogsVolume: false,
queryOverLive: false,
dashboardPreviews: false,
};
licenseInfo: LicenseInfo = {} as LicenseInfo;
+20 -2
View File
@@ -1,5 +1,6 @@
import {
DataFrame,
DataFrameJSON,
DataQueryRequest,
DataQueryResponse,
LiveChannelAddress,
LiveChannelEvent,
@@ -38,12 +39,20 @@ export interface StreamingFrameOptions {
*/
export interface LiveDataStreamOptions {
addr: LiveChannelAddress;
frame?: DataFrame; // initial results
frame?: DataFrameJSON; // initial results
key?: string;
buffer?: Partial<StreamingFrameOptions>;
filter?: LiveDataFilter;
}
/**
* @alpha -- experimental: send a normal query request over websockt
*/
export interface LiveQueryDataOptions {
request: DataQueryRequest;
body: any; // processed queries, same as sent to `/api/query/ds`
}
/**
* @alpha -- experimental
*/
@@ -63,6 +72,15 @@ export interface GrafanaLiveSrv {
*/
getDataStream(options: LiveDataStreamOptions): Observable<DataQueryResponse>;
/**
* Execute a query over the live websocket and potentiall subscribe to a live channel.
*
* Since the initial request and subscription are on the same socket, this will support HA setups
*
* @alpha -- this function requires the feature toggle `queryOverLive` to be set
*/
getQueryData(options: LiveQueryDataOptions): Observable<DataQueryResponse>;
/**
* For channels that support presence, this will request the current state from the server.
*
@@ -11,6 +11,7 @@ import {
parseLiveChannelAddress,
getDataSourceRef,
DataSourceRef,
dataFrameToJSON,
} from '@grafana/data';
import { merge, Observable, of } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
@@ -21,6 +22,7 @@ import {
StreamingFrameOptions,
StreamingFrameAction,
} from '../services';
import { config } from '../config';
import { BackendDataSourceResponse, toDataQueryResponse } from './queryResponse';
/**
@@ -155,6 +157,13 @@ class DataSourceWithBackend<
body.to = range.to.valueOf().toString();
}
if (config.featureToggles.queryOverLive) {
return getGrafanaLiveSrv().getQueryData({
request,
body,
});
}
return getBackendSrv()
.fetch<BackendDataSourceResponse>({
url: '/api/ds/query',
@@ -271,7 +280,7 @@ export function toStreamingDataResponse<TQuery extends DataQuery = DataQuery>(
live.getDataStream({
addr,
buffer: getter(req, frame),
frame,
frame: dataFrameToJSON(f),
})
);
} else {