{"version":3,"file":"logs.mjs","sources":["../../../src/types/logs.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { DataQuery, LogsSortOrder } from '@grafana/schema';\n\nimport { BusEventWithPayload } from '../events/types';\n\nimport { ScopedVars } from './ScopedVars';\nimport { KeyValue, Labels } from './data';\nimport { DataFrame } from './dataFrame';\nimport { DataQueryRequest, DataQueryResponse, DataSourceApi, QueryFixAction, QueryFixType } from './datasource';\nimport { AbsoluteTimeRange } from './time';\nexport { LogsDedupStrategy, LogsSortOrder } from '@grafana/schema';\n\n/**\n * Mapping of log level abbreviation to canonical log level.\n * Supported levels are reduce to limit color variation.\n */\nexport enum LogLevel {\n  emerg = 'critical',\n  fatal = 'critical',\n  alert = 'critical',\n  crit = 'critical',\n  critical = 'critical',\n  warn = 'warning',\n  warning = 'warning',\n  err = 'error',\n  eror = 'error',\n  error = 'error',\n  info = 'info',\n  information = 'info',\n  informational = 'info',\n  notice = 'info',\n  dbug = 'debug',\n  debug = 'debug',\n  trace = 'trace',\n  unknown = 'unknown',\n}\n\n/**\n * Mapping of log level abbreviation to canonical log level.\n * Supported levels are reduce to limit color variation.\n */\nexport const NumericLogLevel: Record<string, LogLevel> = {\n  '0': LogLevel.critical,\n  '1': LogLevel.critical,\n  '2': LogLevel.critical,\n  '3': LogLevel.error,\n  '4': LogLevel.warning,\n  '5': LogLevel.info,\n  '6': LogLevel.info,\n  '7': LogLevel.debug,\n};\n\n// Used for meta information such as common labels or returned log rows in logs view in Explore\nexport enum LogsMetaKind {\n  Number,\n  String,\n  LabelsMap,\n  Error,\n}\n\nexport interface LogsMetaItem {\n  label: string;\n  value: string | number | Labels;\n  kind: LogsMetaKind;\n}\n\nexport interface LogRowModel {\n  // Index of the field from which the entry has been created so that we do not show it later in log row details.\n  entryFieldIndex: number;\n\n  // Index of the row in the dataframe. As log rows can be stitched from multiple dataFrames, this does not have to be\n  // the same as rows final index when rendered.\n  rowIndex: number;\n\n  // The value of the dataframe's id field, if it exists\n  rowId?: string;\n\n  // Full DataFrame from which we parsed this log.\n  // TODO: refactor this so we do not need to pass whole dataframes in addition to also parsed data.\n  dataFrame: DataFrame;\n  duplicates?: number;\n\n  // Actual log line\n  entry: string;\n  hasAnsi: boolean;\n  hasUnescapedContent: boolean;\n  labels: Labels;\n  logLevel: LogLevel;\n  raw: string;\n  searchWords?: string[];\n  timeFromNow: string;\n  timeEpochMs: number;\n  // timeEpochNs stores time with nanosecond-level precision,\n  // as millisecond-level precision is usually not enough for proper sorting of logs\n  timeEpochNs: string;\n  timeLocal: string;\n  timeUtc: string;\n  uid: string;\n  uniqueLabels?: Labels;\n  datasourceType?: string;\n  datasourceUid?: string;\n}\n\nexport interface LogsModel {\n  hasUniqueLabels: boolean;\n  meta?: LogsMetaItem[];\n  rows: LogRowModel[];\n  series?: DataFrame[];\n  // visibleRange is time range for histogram created from log results\n  visibleRange?: AbsoluteTimeRange;\n  queries?: DataQuery[];\n  bucketSize?: number;\n}\n\nexport interface LogSearchMatch {\n  start: number;\n  length: number;\n  text: string;\n}\n\nexport interface LogLabelStatsModel {\n  active?: boolean;\n  count: number;\n  proportion: number;\n  value: string;\n}\n\nexport enum LogsDedupDescription {\n  none = 'No de-duplication',\n  exact = 'De-duplication of successive lines that are identical, ignoring ISO datetimes.',\n  numbers = 'De-duplication of successive lines that are identical when ignoring numbers, e.g., IP addresses, latencies.',\n  signature = 'De-duplication of successive lines that have identical punctuation and whitespace.',\n}\n\nexport interface LogRowContextOptions {\n  direction?: LogRowContextQueryDirection;\n  limit?: number;\n  scopedVars?: ScopedVars;\n  // Optional. Size of the time window to get logs before of after the referenced entry.\n  timeWindowMs?: number;\n}\n\nexport enum LogRowContextQueryDirection {\n  Backward = 'BACKWARD',\n  Forward = 'FORWARD',\n}\n\n/**\n * Data sources that allow showing context rows around the provided LowRowModel should implement this method.\n * This will enable \"context\" button in Logs Panel.\n */\nexport interface DataSourceWithLogsContextSupport<TQuery extends DataQuery = DataQuery> {\n  /**\n   * Retrieve context for a given log row\n   */\n  getLogRowContext: (row: LogRowModel, options?: LogRowContextOptions, query?: TQuery) => Promise<DataQueryResponse>;\n\n  /**\n   * Retrieve the context query object for a given log row. This is currently used to open LogContext queries in a split view and in a new browser tab.\n   * The `cacheFilters` parameter can be used to force a refetch of the cached applied filters. Default value `true`.\n   */\n  getLogRowContextQuery?: (\n    row: LogRowModel,\n    options?: LogRowContextOptions,\n    query?: TQuery,\n    cacheFilters?: boolean\n  ) => Promise<TQuery | null>;\n\n  /**\n   * @deprecated Deprecated since 10.3. To display the context option and support the feature implement DataSourceWithLogsContextSupport interface instead.\n   */\n  showContextToggle?(row?: LogRowModel): boolean;\n\n  /**\n   * This method can be used to display a custom UI in the context view.\n   * @alpha\n   * @internal\n   */\n  getLogRowContextUi?(\n    row: LogRowModel,\n    runContextQuery?: () => void,\n    origQuery?: TQuery,\n    scopedVars?: ScopedVars\n  ): React.ReactNode;\n\n  // Does the datasource support the user adjusting the time range in the logs context window? https://github.com/grafana/grafana/pull/109901\n  supportsAdjustableWindow?: boolean;\n}\n\nexport const hasLogsContextSupport = (datasource: unknown): datasource is DataSourceWithLogsContextSupport => {\n  if (!datasource || typeof datasource !== 'object') {\n    return false;\n  }\n\n  return 'getLogRowContext' in datasource;\n};\n\nexport const hasLogsLabelTypesSupport = (datasource: unknown): datasource is DataSourceWithLogsLabelTypesSupport => {\n  if (!datasource || typeof datasource !== 'object') {\n    return false;\n  }\n  return 'getLabelDisplayTypeFromFrame' in datasource;\n};\n\n/**\n * Types of supplementary queries that can be run in Explore.\n * @internal\n */\nexport enum SupplementaryQueryType {\n  LogsVolume = 'LogsVolume',\n  LogsSample = 'LogsSample',\n}\n\n/**\n * @internal\n */\nexport type SupplementaryQueryOptions = LogsVolumeOption | LogsSampleOptions;\n\n/**\n * @internal\n */\nexport type LogsVolumeOption = {\n  type: SupplementaryQueryType.LogsVolume;\n  field?: string;\n};\n\n/**\n * @internal\n */\nexport type LogsSampleOptions = {\n  type: SupplementaryQueryType.LogsSample;\n  limit?: number;\n};\n\n/**\n * Types of logs volume responses. A data source may return full range histogram (based on selected range)\n * or limited (based on returned results). This information is attached to DataFrame.meta.custom object.\n * @internal\n */\nexport enum LogsVolumeType {\n  FullRange = 'FullRange',\n  Limited = 'Limited',\n}\n\n/**\n * Custom meta information required by Logs Volume responses\n */\nexport type LogsVolumeCustomMetaData = {\n  absoluteRange: AbsoluteTimeRange;\n  logsVolumeType: LogsVolumeType;\n  datasourceName: string;\n  sourceQuery: DataQuery;\n};\n\n/**\n * Data sources that support supplementary queries in Explore.\n * This will enable users to see additional data when running original queries.\n * Supported supplementary queries are defined in SupplementaryQueryType enum.\n */\nexport interface DataSourceWithSupplementaryQueriesSupport<TQuery extends DataQuery> {\n  /**\n   * Returns an observable that will be used to fetch supplementary data based on the provided\n   * supplementary query type and original request.\n   * @deprecated Use getSupplementaryQueryRequest() instead\n   */\n  getDataProvider?(\n    type: SupplementaryQueryType,\n    request: DataQueryRequest<TQuery>\n  ): Observable<DataQueryResponse> | undefined;\n  /**\n   * Receives a SupplementaryQueryType and a DataQueryRequest and returns a new DataQueryRequest to fetch supplementary data.\n   * If provided type or request is not suitable for a supplementary data request, returns undefined.\n   */\n  getSupplementaryRequest?(\n    type: SupplementaryQueryType,\n    request: DataQueryRequest<TQuery>,\n    options?: SupplementaryQueryOptions\n  ): DataQueryRequest<TQuery> | undefined;\n  /**\n   * Returns supplementary query types that data source supports.\n   */\n  getSupportedSupplementaryQueryTypes(dsRequest?: DataQueryRequest<DataQuery>): SupplementaryQueryType[];\n  /**\n   * Returns a supplementary query to be used to fetch supplementary data based on the provided type and original query.\n   * If the provided query is not suitable for the provided supplementary query type, undefined should be returned.\n   */\n  getSupplementaryQuery(options: SupplementaryQueryOptions, originalQuery: TQuery): TQuery | undefined;\n}\n\nexport const hasSupplementaryQuerySupport = <TQuery extends DataQuery>(\n  datasource: DataSourceApi | (DataSourceApi & DataSourceWithSupplementaryQueriesSupport<TQuery>),\n  type: SupplementaryQueryType,\n  dsRequest?: DataQueryRequest<DataQuery>\n): datasource is DataSourceApi & DataSourceWithSupplementaryQueriesSupport<TQuery> => {\n  if (!datasource) {\n    return false;\n  }\n\n  return (\n    ('getDataProvider' in datasource || 'getSupplementaryRequest' in datasource) &&\n    'getSupplementaryQuery' in datasource &&\n    'getSupportedSupplementaryQueryTypes' in datasource &&\n    datasource.getSupportedSupplementaryQueryTypes(dsRequest).includes(type)\n  );\n};\n\nexport const hasLogsContextUiSupport = (datasource: unknown): datasource is DataSourceWithLogsContextSupport => {\n  if (!datasource || typeof datasource !== 'object') {\n    return false;\n  }\n\n  return 'getLogRowContextUi' in datasource;\n};\n\nexport interface QueryFilterOptions extends KeyValue<string> {}\nexport interface ToggleFilterAction {\n  type: 'FILTER_FOR' | 'FILTER_OUT';\n  options: QueryFilterOptions;\n  frame?: DataFrame;\n}\n/**\n * Data sources that support toggleable filters through `toggleQueryFilter`, and displaying the active\n * state of filters through `queryHasFilter`, in the Log Details component in Explore.\n * @internal\n * @alpha\n */\nexport interface DataSourceWithToggleableQueryFiltersSupport<TQuery extends DataQuery> {\n  /**\n   * Toggle filters on and off from query.\n   * If the filter is already present, it should be removed.\n   * If the opposite filter is present, it should be replaced.\n   */\n  toggleQueryFilter(query: TQuery, filter: ToggleFilterAction): TQuery;\n\n  /**\n   * Given a query, determine if it has a filter that matches the options.\n   */\n  queryHasFilter(query: TQuery, filter: QueryFilterOptions): boolean;\n}\n\n/**\n * @internal\n */\nexport const hasToggleableQueryFiltersSupport = <TQuery extends DataQuery>(\n  datasource: unknown\n): datasource is DataSourceWithToggleableQueryFiltersSupport<TQuery> => {\n  return (\n    datasource != null &&\n    typeof datasource === 'object' &&\n    'toggleQueryFilter' in datasource &&\n    'queryHasFilter' in datasource\n  );\n};\n\n/**\n * Data sources that support query modification actions from Log Details (ADD_FILTER, ADD_FILTER_OUT),\n * and Popover Menu (ADD_STRING_FILTER, ADD_STRING_FILTER_OUT) in Explore.\n * @internal\n * @alpha\n */\nexport interface DataSourceWithQueryModificationSupport<TQuery extends DataQuery> {\n  /**\n   * Given a query, applies a query modification `action`, returning the updated query.\n   * Explore currently supports the following action types:\n   * - ADD_FILTER: adds a <key, value> filter to the query.\n   * - ADD_FILTER_OUT: adds a negative <key, value> filter to the query.\n   * - ADD_STRING_FILTER: adds a string filter to the query.\n   * - ADD_STRING_FILTER_OUT: adds a negative string filter to the query.\n   */\n  modifyQuery(query: TQuery, action: QueryFixAction): TQuery;\n\n  /**\n   * Returns a list of supported action types for `modifyQuery()`.\n   */\n  getSupportedQueryModifications(): Array<QueryFixType | string>;\n}\n\n/**\n * Logs data sources that support custom field groupings within logs details in the Logs Panel.\n * If this method is defined, the return value will be used to group fields in the Logs Panel.\n */\nexport interface DataSourceWithLogsLabelTypesSupport {\n  getLabelDisplayTypeFromFrame(labelKey: string, frame: DataFrame | undefined, index: number | null): null | string;\n}\n\n/**\n * @internal\n */\nexport const hasQueryModificationSupport = <TQuery extends DataQuery>(\n  datasource: unknown\n): datasource is DataSourceWithQueryModificationSupport<TQuery> => {\n  return (\n    datasource != null &&\n    typeof datasource === 'object' &&\n    'modifyQuery' in datasource &&\n    'getSupportedQueryModifications' in datasource\n  );\n};\n\nexport interface LogSortOrderChangePayload {\n  order: LogsSortOrder;\n}\n\nexport class LogSortOrderChangeEvent extends BusEventWithPayload<LogSortOrderChangePayload> {\n  static type = 'logs-sort-order-change';\n}\n"],"names":["LogLevel","LogsMetaKind","LogsDedupDescription","LogRowContextQueryDirection","SupplementaryQueryType","LogsVolumeType"],"mappings":";;;;AAiBO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AACL,EAAAA,UAAA,OAAA,CAAA,GAAQ,UAAA;AACR,EAAAA,UAAA,OAAA,CAAA,GAAQ,UAAA;AACR,EAAAA,UAAA,OAAA,CAAA,GAAQ,UAAA;AACR,EAAAA,UAAA,MAAA,CAAA,GAAO,UAAA;AACP,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AACX,EAAAA,UAAA,MAAA,C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