Chore: Move StreamingDataFrame to @grafana/data (#72014)

This commit is contained in:
Andres Martinez Gotor 2023-07-24 13:30:52 +02:00 committed by GitHub
parent 3c48701f08
commit 987624f8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 75 additions and 69 deletions

View File

@ -55,6 +55,16 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
[0, 0, 0, "Do not use any type assertions.", "17"]
],
"packages/grafana-data/src/dataframe/StreamingDataFrame.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"],
[0, 0, 0, "Do not use any type assertions.", "7"]
],
"packages/grafana-data/src/dataframe/dimensions.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
@ -2682,16 +2692,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/live/data/StreamingDataFrame.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"],
[0, 0, 0, "Do not use any type assertions.", "7"]
],
"public/app/features/live/data/amendTimeSeries.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],

View File

@ -1,7 +1,12 @@
import { DataFrame, DataFrameJSON, FieldType, getFieldDisplayName, reduceField, ReducerID } from '@grafana/data';
import { StreamingFrameAction, StreamingFrameOptions } from '@grafana/runtime';
import { DataFrame, DataFrameJSON, FieldType, getFieldDisplayName, reduceField, ReducerID } from '..';
import { closestIdx, getStreamingFrameOptions, StreamingDataFrame } from './StreamingDataFrame';
import {
closestIdx,
getStreamingFrameOptions,
StreamingDataFrame,
StreamingFrameAction,
StreamingFrameOptions,
} from './StreamingDataFrame';
describe('Streaming JSON', () => {
describe('closestIdx', function () {
@ -721,8 +726,7 @@ describe('Streaming JSON', () => {
},
});
expect(stream.fields.map((f) => ({ name: f.name, labels: f.labels, values: f.values })))
.toMatchInlineSnapshot(`
expect(stream.fields.map((f) => ({ name: f.name, labels: f.labels, values: f.values }))).toMatchInlineSnapshot(`
[
{
"labels": undefined,

View File

@ -1,22 +1,38 @@
import { AlignedData } from 'uplot';
import { DataFrame, Field, FieldDTO, FieldType, Labels, parseLabels, QueryResultMeta } from '..';
import { join } from '../transformations/transformers/joinDataFrames';
import { renderLegendFormat } from '../utils/legend';
import {
DataFrame,
DataFrameJSON,
decodeFieldValueEntities,
Field,
FieldDTO,
FieldSchema,
FieldType,
guessFieldTypeFromValue,
Labels,
parseLabels,
QueryResultMeta,
toFilteredDataFrameDTO,
} from '@grafana/data';
import { join } from '@grafana/data/src/transformations/transformers/joinDataFrames';
import { StreamingFrameAction, StreamingFrameOptions } from '@grafana/runtime/src/services/live';
import { renderLegendFormat } from 'app/plugins/datasource/prometheus/legend';
} from '.';
/**
* Indicate if the frame is appened or replace
*
* @alpha
*/
export enum StreamingFrameAction {
Append = 'append',
Replace = 'replace',
}
/**
* @alpha
* */
export interface StreamingFrameOptions {
maxLength: number; // 1000
maxDelta: number; // how long to keep things
action: StreamingFrameAction; // default will append
/** optionally format field names based on labels */
displayNameFormat?: string;
}
/**
* Stream packet info is attached to StreamingDataFrames and indicate how many
@ -110,7 +126,7 @@ export class StreamingDataFrame implements DataFrame {
values: (f.values as unknown[]).slice(numberOfItemsToRemove),
}));
const length = dataFrameDTO.fields[0]?.values?.length ?? 0
const length = dataFrameDTO.fields[0]?.values?.length ?? 0;
return {
...dataFrameDTO,

View File

@ -8,3 +8,4 @@ export * from './ArrayDataFrame';
export * from './DataFrameJSON';
export * from './frameComparisons';
export { anySeriesWithTimeField, isTimeSeriesFrame, isTimeSeriesFrames } from './utils';
export { StreamingDataFrame, StreamingFrameAction, type StreamingFrameOptions } from './StreamingDataFrame';

View File

@ -24,3 +24,4 @@ export { anyToNumber } from './anyToNumber';
export { withLoadingIndicator, type WithLoadingIndicatorOptions } from './withLoadingIndicator';
export { convertOldAngularValueMappings, LegacyMappingType } from './valueMappings';
export { containsSearchFilter, type SearchFilterOptions, getSearchFilterScopedVar } from './variables';
export { renderLegendFormat } from './legend';

View File

@ -1,4 +1,4 @@
import { Labels } from '@grafana/data';
import { Labels } from '../types';
/** replace labels in a string. Used for loki+prometheus legend formats */
export function renderLegendFormat(aliasPattern: string, aliasData: Labels): string {

View File

@ -7,6 +7,7 @@ import {
LiveChannelAddress,
LiveChannelEvent,
LiveChannelPresenceStatus,
StreamingFrameOptions,
} from '@grafana/data';
/**
@ -16,27 +17,8 @@ export interface LiveDataFilter {
fields?: string[];
}
/**
* Indicate if the frame is appened or replace
*
* @alpha
*/
export enum StreamingFrameAction {
Append = 'append',
Replace = 'replace',
}
/**
* @alpha
*/
export interface StreamingFrameOptions {
maxLength: number; // 1000
maxDelta: number; // how long to keep things
action: StreamingFrameAction; // default will append
/** optionally format field names based on labels */
displayNameFormat?: string;
}
// StreamingFrameAction and StreamingFrameOptions are now in @grafana/data
export { StreamingFrameAction, type StreamingFrameOptions } from '@grafana/data';
/**
* @alpha

View File

@ -13,10 +13,10 @@ import {
LiveChannelLeaveEvent,
LiveChannelScope,
LoadingState,
StreamingDataFrame,
} from '@grafana/data';
import { StreamingFrameAction } from '@grafana/runtime';
import { StreamingDataFrame } from '../data/StreamingDataFrame';
import { isStreamingResponseData, StreamingResponseData, StreamingResponseDataType } from '../data/utils';
import { DataStreamHandlerDeps, LiveDataStream } from './LiveDataStream';

View File

@ -10,11 +10,12 @@ import {
LiveChannelEvent,
LiveChannelId,
LoadingState,
StreamingDataFrame,
} from '@grafana/data';
import { getStreamingFrameOptions } from '@grafana/data/src/dataframe/StreamingDataFrame';
import { LiveDataStreamOptions, StreamingFrameAction, StreamingFrameOptions } from '@grafana/runtime/src/services/live';
import { toDataQueryError } from '@grafana/runtime/src/utils/toDataQueryError';
import { getStreamingFrameOptions, StreamingDataFrame } from '../data/StreamingDataFrame';
import { StreamingResponseDataType } from '../data/utils';
import { DataStreamSubscriptionKey, StreamingDataQueryResponse } from './service';

View File

@ -1,4 +1,4 @@
import { closestIdx } from "./StreamingDataFrame";
import { closestIdx } from '@grafana/data/src/dataframe/StreamingDataFrame';
export type Table = [times: number[], ...values: any[][]];

View File

@ -1,6 +1,4 @@
import { DataQueryResponseData, isDataFrame } from '@grafana/data';
import { StreamingDataFrame } from './StreamingDataFrame';
import { DataQueryResponseData, isDataFrame, StreamingDataFrame } from '@grafana/data';
/**
* @alpha -- experimental

View File

@ -1,10 +1,9 @@
import { Subject } from 'rxjs';
import { DataQueryResponse, FieldType, LiveChannelScope } from '@grafana/data';
import { DataQueryResponse, FieldType, LiveChannelScope, StreamingDataFrame } from '@grafana/data';
import { BackendSrv } from '@grafana/runtime';
import { CentrifugeSrv, StreamingDataQueryResponse } from './centrifuge/service';
import { StreamingDataFrame } from './data/StreamingDataFrame';
import { StreamingResponseDataType } from './data/utils';
import { GrafanaLiveService } from './live';

View File

@ -1,6 +1,6 @@
import { from, map, of, switchMap } from 'rxjs';
import { DataFrame, toLiveChannelId } from '@grafana/data';
import { DataFrame, toLiveChannelId, StreamingDataFrame } from '@grafana/data';
import { BackendSrv, GrafanaLiveSrv, toDataQueryResponse } from '@grafana/runtime';
import {
standardStreamOptionsProvider,
@ -8,7 +8,6 @@ import {
} from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { CentrifugeSrv, StreamingDataQueryResponse } from './centrifuge/service';
import { StreamingDataFrame } from './data/StreamingDataFrame';
import { isStreamingResponseData, StreamingResponseDataType } from './data/utils';
type GrafanaLiveServiceDeps = {

View File

@ -27,10 +27,10 @@ import {
transformDataFrame,
preProcessPanelData,
ApplyFieldOverrideOptions,
StreamingDataFrame,
} from '@grafana/data';
import { getTemplateSrv, toDataQueryError } from '@grafana/runtime';
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame';
import { isStreamingDataFrame } from 'app/features/live/data/utils';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';

View File

@ -36,6 +36,7 @@ import {
DataSourceWithToggleableQueryFiltersSupport,
ToggleFilterAction,
QueryFilterOptions,
renderLegendFormat,
} from '@grafana/data';
import { BackendSrvRequest, config, DataSourceWithBackend, FetchError } from '@grafana/runtime';
import { DataQuery } from '@grafana/schema';
@ -46,7 +47,6 @@ import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_sr
import { serializeParams } from '../../../core/utils/fetch';
import { queryLogsSample, queryLogsVolume } from '../../../features/logs/logsModel';
import { getLogLevelFromKey } from '../../../features/logs/utils';
import { renderLegendFormat } from '../prometheus/legend';
import { replaceVariables, returnVariables } from '../prometheus/querybuilder/shared/parsingUtils';
import LanguageProvider from './LanguageProvider';

View File

@ -1,8 +1,14 @@
import { map, Observable, defer, mergeMap } from 'rxjs';
import { DataFrameJSON, DataQueryRequest, DataQueryResponse, LiveChannelScope, LoadingState } from '@grafana/data';
import {
DataFrameJSON,
DataQueryRequest,
DataQueryResponse,
LiveChannelScope,
LoadingState,
StreamingDataFrame,
} from '@grafana/data';
import { getGrafanaLiveSrv } from '@grafana/runtime';
import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame';
import { LokiDatasource } from './datasource';
import { LokiQuery } from './types';

View File

@ -23,6 +23,7 @@ import {
rangeUtil,
ScopedVars,
TimeRange,
renderLegendFormat,
} from '@grafana/data';
import {
BackendDataSourceResponse,
@ -52,7 +53,6 @@ import {
getPrometheusTime,
getRangeSnapInterval,
} from './language_utils';
import { renderLegendFormat } from './legend';
import PrometheusMetricFindQuery from './metric_find_query';
import { getInitHints, getQueryHints } from './query_hints';
import { QueryEditorMode } from './querybuilder/shared/types';

View File

@ -19,11 +19,11 @@ import {
ScopedVars,
TIME_SERIES_TIME_FIELD_NAME,
TIME_SERIES_VALUE_FIELD_NAME,
renderLegendFormat,
} from '@grafana/data';
import { calculateFieldDisplayName } from '@grafana/data/src/field/fieldState';
import { config, FetchResponse, getDataSourceSrv, getTemplateSrv } from '@grafana/runtime';
import { renderLegendFormat } from './legend';
import {
ExemplarTraceIdDestination,
isExemplarData,

View File

@ -11,9 +11,8 @@ import {
LoadingState,
DataFrameSchema,
DataFrameData,
StreamingDataFrame,
} from '@grafana/data';
// eslint-disable-next-line no-restricted-imports -- In the process from being removed
import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame';
import { getRandomLine } from './LogIpsum';
import { TestData, StreamingQuery } from './dataquery.gen';

View File

@ -16,10 +16,10 @@ import {
LoadingState,
applyFieldOverrides,
LiveChannelAddress,
StreamingDataFrame,
} from '@grafana/data';
import { config, getGrafanaLiveSrv } from '@grafana/runtime';
import { Alert, stylesFactory, Button, JSONFormatter, CustomScrollbar, CodeEditor } from '@grafana/ui';
import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame';
import { TablePanel } from '../table/TablePanel';

View File

@ -1,6 +1,7 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { CartesianCoords2D, DashboardCursorSync, DataFrame, FieldType, PanelProps } from '@grafana/data';
import { getLastStreamingDataFramePacket } from '@grafana/data/src/dataframe/StreamingDataFrame';
import {
Portal,
TooltipDisplayMode,
@ -18,7 +19,6 @@ import {
prepareTimelineLegendItems,
TimelineMode,
} from 'app/core/components/TimelineChart/utils';
import { getLastStreamingDataFramePacket } from 'app/features/live/data/StreamingDataFrame';
import { AnnotationEditorPlugin } from '../timeseries/plugins/AnnotationEditorPlugin';
import { AnnotationsPlugin } from '../timeseries/plugins/AnnotationsPlugin';