mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Consolidate logs volume logic (full range and limited) * Fix showing limited histogram message * Test passing meta data to logs volume provider * Improve readability * Clean up types * Add basic support for multiple log volumes * Move the comment back to the right place * Improve readability * Clean up the logic to support Logs Samples * Update docs * Sort log volumes * Provide title to logs volume panel * Move logs volume cache to the provider factory * Add helper functions * Reuse only if queries are the same * Fix alphabetical sorting * Move caching out of the provider * Support errors and loading state * Remove unused code * Consolidate supplementary query utils * Add tests for supplementaryQueries * Update tests * Simplify logs volume extra info * Update tests * Remove comment * Update tests * Fix hiding the histogram for hidden queries * Simplify loading message * Update tests * Wait for full fallback histogram to load before showing it * Fix a typo * Add feedback comments * Move feedback comments to github * Do not filter out hidden queries as they may be used as references in other queries * Group log volume by refId * Support showing fallback histograms per query to avoid duplicates * Improve type-checking * Fix supplementaryQueries.test.ts * Fix logsModel.test.ts * Fix loading fallback results * Fix unit tests * WIP * Update deprecated styles * Simplify test * Simplify rendering zoom info * Update deprecated styles * Simplify getLogsVolumeDataSourceInfo * Simplify isLogsVolumeLimited() * Simplify rendering zoom info
106 lines
2.4 KiB
TypeScript
106 lines
2.4 KiB
TypeScript
import { Observable } from 'rxjs';
|
|
|
|
import {
|
|
DataQueryRequest,
|
|
DataQueryResponse,
|
|
DataSourceApi,
|
|
DataSourceInstanceSettings,
|
|
DataSourcePluginMeta,
|
|
DataSourceRef,
|
|
getDataSourceUID,
|
|
} from '@grafana/data';
|
|
|
|
export class DatasourceSrvMock {
|
|
constructor(private defaultDS: DataSourceApi, private datasources: { [name: string]: DataSourceApi }) {
|
|
//
|
|
}
|
|
|
|
get(ref?: DataSourceRef | string): Promise<DataSourceApi> {
|
|
if (!ref) {
|
|
return Promise.resolve(this.defaultDS);
|
|
}
|
|
const uid = getDataSourceUID(ref) ?? '';
|
|
const ds = this.datasources[uid];
|
|
if (ds) {
|
|
return Promise.resolve(ds);
|
|
}
|
|
return Promise.reject(`Unknown Datasource: ${JSON.stringify(ref)}`);
|
|
}
|
|
}
|
|
|
|
export class MockDataSourceApi extends DataSourceApi {
|
|
result: DataQueryResponse = { data: [] };
|
|
|
|
constructor(
|
|
name?: string,
|
|
result?: DataQueryResponse,
|
|
meta?: DataSourcePluginMeta,
|
|
public error: string | null = null
|
|
) {
|
|
super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings);
|
|
if (result) {
|
|
this.result = result;
|
|
}
|
|
|
|
this.meta = meta || ({} as DataSourcePluginMeta);
|
|
}
|
|
|
|
query(request: DataQueryRequest): Promise<DataQueryResponse> {
|
|
if (this.error) {
|
|
return Promise.reject(this.error);
|
|
}
|
|
|
|
return new Promise((resolver) => {
|
|
setTimeout(() => {
|
|
resolver(this.result);
|
|
});
|
|
});
|
|
}
|
|
|
|
testDatasource() {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
setupMixed(value: boolean) {
|
|
this.meta = this.meta || {};
|
|
this.meta.mixed = value;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
export class MockObservableDataSourceApi extends DataSourceApi {
|
|
results: DataQueryResponse[] = [{ data: [] }];
|
|
|
|
constructor(
|
|
name?: string,
|
|
results?: DataQueryResponse[],
|
|
meta?: DataSourcePluginMeta,
|
|
private error: string | null = null
|
|
) {
|
|
super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings);
|
|
|
|
if (results) {
|
|
this.results = results;
|
|
}
|
|
|
|
this.meta = meta || ({} as DataSourcePluginMeta);
|
|
}
|
|
|
|
query(request: DataQueryRequest): Observable<DataQueryResponse> {
|
|
return new Observable((observer) => {
|
|
if (this.error) {
|
|
observer.error(this.error);
|
|
}
|
|
|
|
if (this.results) {
|
|
this.results.forEach((response) => observer.next(response));
|
|
observer.complete();
|
|
}
|
|
});
|
|
}
|
|
|
|
testDatasource() {
|
|
return Promise.resolve();
|
|
}
|
|
}
|