mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Update the way Loki retrieve log context (#17204)
* Move log's typings into grafana/ui
* Update the way context is retrieved for Loki
Major changes:
1. getLogRowContext expects row to be of LogRowModel type
2. getLogRowContext accepts generic options object, specific to a datasource of interest. limit option has been removed, and now it's a part of Loki's context query options (see below)
3. LogRowContextProvider performs two queries now. Before, it was Loki ds that performed queries in both directions when getLogRowContext.
4. Loki's getLogRowContext accepts options object of a type:
interface LokiContextQueryOptions {
direction?: 'BACKWARD' | 'FORWARD';
limit?: number;
}
This will enable querying in either direction independently and also slightly simplifies the way query errors are handled.
LogRowContextProvider maps the results to a Loki specific context types, basically string[][], as raw log lines are displayed in first version.
This commit is contained in:
@@ -3,6 +3,7 @@ import { TimeRange } from './time';
|
||||
import { PluginMeta, GrafanaPlugin } from './plugin';
|
||||
import { TableData, TimeSeries, SeriesData, LoadingState } from './data';
|
||||
import { PanelData } from './panel';
|
||||
import { LogRowModel } from './logs';
|
||||
|
||||
// NOTE: this seems more general than just DataSource
|
||||
export interface DataSourcePluginOptionsEditorProps<TOptions> {
|
||||
@@ -187,7 +188,10 @@ export abstract class DataSourceApi<
|
||||
/**
|
||||
* Retrieve context for a given log row
|
||||
*/
|
||||
getLogRowContext?(row: any, limit?: number): Promise<DataQueryResponse>;
|
||||
getLogRowContext?: <TContextQueryOptions extends {}>(
|
||||
row: LogRowModel,
|
||||
options?: TContextQueryOptions
|
||||
) => Promise<DataQueryResponse>;
|
||||
|
||||
/**
|
||||
* Set after constructor call, as the data source instance is the most common thing to pass around
|
||||
@@ -299,10 +303,6 @@ export interface DataQueryResponse {
|
||||
data: DataQueryResponseData[];
|
||||
}
|
||||
|
||||
export interface LogRowContextQueryResponse {
|
||||
data: Array<Array<string | DataQueryError>>;
|
||||
}
|
||||
|
||||
export interface DataQuery {
|
||||
/**
|
||||
* A - Z
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Labels, TimeSeries } from './data';
|
||||
|
||||
/**
|
||||
* Mapping of log level abbreviation to canonical log level.
|
||||
* Supported levels are reduce to limit color variation.
|
||||
@@ -19,3 +21,85 @@ export enum LogLevel {
|
||||
trace = 'trace',
|
||||
unknown = 'unknown',
|
||||
}
|
||||
|
||||
export enum LogsMetaKind {
|
||||
Number,
|
||||
String,
|
||||
LabelsMap,
|
||||
}
|
||||
|
||||
export interface LogsMetaItem {
|
||||
label: string;
|
||||
value: string | number | Labels;
|
||||
kind: LogsMetaKind;
|
||||
}
|
||||
|
||||
export interface LogRowModel {
|
||||
duplicates?: number;
|
||||
entry: string;
|
||||
hasAnsi: boolean;
|
||||
labels: Labels;
|
||||
logLevel: LogLevel;
|
||||
raw: string;
|
||||
searchWords?: string[];
|
||||
timestamp: string; // ISO with nanosec precision
|
||||
timeFromNow: string;
|
||||
timeEpochMs: number;
|
||||
timeLocal: string;
|
||||
uniqueLabels?: Labels;
|
||||
}
|
||||
|
||||
export interface LogsModel {
|
||||
hasUniqueLabels: boolean;
|
||||
meta?: LogsMetaItem[];
|
||||
rows: LogRowModel[];
|
||||
series?: TimeSeries[];
|
||||
}
|
||||
|
||||
export interface LogSearchMatch {
|
||||
start: number;
|
||||
length: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface LogLabelStatsModel {
|
||||
active?: boolean;
|
||||
count: number;
|
||||
proportion: number;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export enum LogsDedupStrategy {
|
||||
none = 'none',
|
||||
exact = 'exact',
|
||||
numbers = 'numbers',
|
||||
signature = 'signature',
|
||||
}
|
||||
|
||||
export interface LogsParser {
|
||||
/**
|
||||
* Value-agnostic matcher for a field label.
|
||||
* Used to filter rows, and first capture group contains the value.
|
||||
*/
|
||||
buildMatcher: (label: string) => RegExp;
|
||||
|
||||
/**
|
||||
* Returns all parsable substrings from a line, used for highlighting
|
||||
*/
|
||||
getFields: (line: string) => string[];
|
||||
|
||||
/**
|
||||
* Gets the label name from a parsable substring of a line
|
||||
*/
|
||||
getLabelFromField: (field: string) => string;
|
||||
|
||||
/**
|
||||
* Gets the label value from a parsable substring of a line
|
||||
*/
|
||||
getValueFromField: (field: string) => string;
|
||||
/**
|
||||
* Function to verify if this is a valid parser for the given line.
|
||||
* The parser accepts the line unless it returns undefined.
|
||||
*/
|
||||
test: (line: string) => any;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user