Streaming: support streaming and a javascript test datasource (#16729)

This commit is contained in:
Ryan McKinley
2019-04-25 14:01:02 -04:00
committed by GitHub
parent ab3860a334
commit 470634e2d6
15 changed files with 1100 additions and 177 deletions

View File

@@ -105,7 +105,6 @@ export class Graph extends PureComponent<GraphProps> {
};
try {
console.log('Graph render');
$.plot(this.element, series, flotOptions);
} catch (err) {
console.log('Graph rendering error', err, flotOptions, series);

View File

@@ -1,6 +1,7 @@
export enum LoadingState {
NotStarted = 'NotStarted',
Loading = 'Loading',
Streaming = 'Streaming',
Done = 'Done',
Error = 'Error',
}

View File

@@ -1,7 +1,7 @@
import { ComponentClass } from 'react';
import { TimeRange } from './time';
import { PluginMeta } from './plugin';
import { TableData, TimeSeries, SeriesData } from './data';
import { TableData, TimeSeries, SeriesData, LoadingState } from './data';
import { PanelData } from './panel';
export interface DataSourcePluginOptionsEditorProps<TOptions> {
@@ -105,7 +105,7 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
/**
* Main metrics / data query action
*/
query(options: DataQueryRequest<TQuery>): Promise<DataQueryResponse>;
query(options: DataQueryRequest<TQuery>, observer?: DataStreamObserver): Promise<DataQueryResponse>;
/**
* Test & verify datasource settings & connection details
@@ -183,6 +183,47 @@ export type LegacyResponseData = TimeSeries | TableData | any;
export type DataQueryResponseData = SeriesData | LegacyResponseData;
export type DataStreamObserver = (event: DataStreamState) => void;
export interface DataStreamState {
/**
* when Done or Error no more events will be processed
*/
state: LoadingState;
/**
* Consistent key across events.
*/
key: string;
/**
* The stream request. The properties of this request will be examined
* to determine if the stream matches the original query. If not, it
* will be unsubscribed.
*/
request: DataQueryRequest;
/**
* Series data may not be known yet
*/
series?: SeriesData[];
/**
* Error in stream (but may still be running)
*/
error?: DataQueryError;
/**
* Optionally return only the rows that changed in this event
*/
delta?: SeriesData[];
/**
* Stop listening to this stream
*/
unsubscribe: () => void;
}
export interface DataQueryResponse {
data: DataQueryResponseData[];
}