mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Live: support streaming results out-of-the-box (#32821)
This commit is contained in:
@@ -178,6 +178,7 @@ export class CentrifugeLiveChannel<TMessage = any, TPublish = any> implements Li
|
||||
|
||||
shutdownWithError(err: string) {
|
||||
this.currentStatus.error = err;
|
||||
this.sendStatus();
|
||||
this.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Centrifuge from 'centrifuge/dist/centrifuge';
|
||||
import { GrafanaLiveSrv, setGrafanaLiveSrv, getGrafanaLiveSrv, config } from '@grafana/runtime';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { LiveChannel, LiveChannelScope, LiveChannelAddress } from '@grafana/data';
|
||||
import { LiveChannel, LiveChannelScope, LiveChannelAddress, LiveChannelConnectionState } from '@grafana/data';
|
||||
import { CentrifugeLiveChannel, getErrorChannel } from './channel';
|
||||
import {
|
||||
GrafanaLiveScope,
|
||||
@@ -104,7 +104,10 @@ export class CentrifugeSrv implements GrafanaLiveSrv {
|
||||
|
||||
// Initialize the channel in the background
|
||||
this.initChannel(scope, channel).catch((err) => {
|
||||
channel?.shutdownWithError(err);
|
||||
if (channel) {
|
||||
channel.currentStatus.state = LiveChannelConnectionState.Invalid;
|
||||
channel.shutdownWithError(err);
|
||||
}
|
||||
this.open.delete(id);
|
||||
});
|
||||
|
||||
@@ -116,7 +119,7 @@ export class CentrifugeSrv implements GrafanaLiveSrv {
|
||||
const { addr } = channel;
|
||||
const support = await scope.getChannelSupport(addr.namespace);
|
||||
if (!support) {
|
||||
throw new Error(channel.addr.namespace + 'does not support streaming');
|
||||
throw new Error(channel.addr.namespace + ' does not support streaming');
|
||||
}
|
||||
const config = support.getChannelConfig(addr.path);
|
||||
if (!config) {
|
||||
|
||||
@@ -73,7 +73,10 @@ export class GrafanaLiveDataSourceScope extends GrafanaLiveScope {
|
||||
*/
|
||||
async getChannelSupport(namespace: string) {
|
||||
const ds = await getDataSourceSrv().get(namespace);
|
||||
return ds.channelSupport;
|
||||
if (ds.channelSupport) {
|
||||
return ds.channelSupport;
|
||||
}
|
||||
return new LiveMeasurementsSupport(); // default support?
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,10 +122,13 @@ export class GrafanaLivePluginScope extends GrafanaLiveScope {
|
||||
*/
|
||||
async getChannelSupport(namespace: string) {
|
||||
const plugin = await loadPlugin(namespace);
|
||||
if (!plugin.channelSupport) {
|
||||
throw new Error('Unknown plugin: ' + namespace);
|
||||
if (!plugin) {
|
||||
throw new Error('Unknown streaming plugin: ' + namespace);
|
||||
}
|
||||
return plugin.channelSupport;
|
||||
if (plugin.channelSupport) {
|
||||
return plugin.channelSupport; // explicit
|
||||
}
|
||||
throw new Error('Plugin does not support streaming: ' + namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ export class DatasourceSrv implements DataSourceService {
|
||||
private datasources: Record<string, DataSourceApi> = {};
|
||||
private settingsMapByName: Record<string, DataSourceInstanceSettings> = {};
|
||||
private settingsMapByUid: Record<string, DataSourceInstanceSettings> = {};
|
||||
private settingsMapById: Record<string, DataSourceInstanceSettings> = {};
|
||||
private defaultName = '';
|
||||
|
||||
/** @ngInject */
|
||||
@@ -38,6 +39,7 @@ export class DatasourceSrv implements DataSourceService {
|
||||
|
||||
for (const dsSettings of Object.values(settingsMapByName)) {
|
||||
this.settingsMapByUid[dsSettings.uid] = dsSettings;
|
||||
this.settingsMapById[dsSettings.id] = dsSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,9 +117,12 @@ export class DatasourceSrv implements DataSourceService {
|
||||
return Promise.resolve(expressionDatasource);
|
||||
}
|
||||
|
||||
const dsConfig = this.settingsMapByName[name];
|
||||
let dsConfig = this.settingsMapByName[name];
|
||||
if (!dsConfig) {
|
||||
return Promise.reject({ message: `Datasource named ${name} was not found` });
|
||||
dsConfig = this.settingsMapById[name];
|
||||
if (!dsConfig) {
|
||||
return Promise.reject({ message: `Datasource named ${name} was not found` });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
|
||||
import { TestDataQuery, StreamingQuery } from './types';
|
||||
import { getRandomLine } from './LogIpsum';
|
||||
import { perf } from '@grafana/runtime/src/measurement/perf'; // not exported
|
||||
import { perf } from '@grafana/runtime/src/utils/perf'; // not exported
|
||||
|
||||
export const defaultStreamQuery: StreamingQuery = {
|
||||
type: 'signal',
|
||||
|
||||
Reference in New Issue
Block a user