mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prettier: Upgrade to 2 (#30387)
* Updated package json but not updated source files * Update eslint plugin * updated files
This commit is contained in:
@@ -55,12 +55,12 @@ export default class LokiCheatSheet extends PureComponent<QueryEditorHelpProps,
|
||||
const provider: LokiLanguageProvider = this.props.datasource?.languageProvider;
|
||||
if (provider.started) {
|
||||
const labels = provider.getLabelKeys() || [];
|
||||
const preferredLabel = PREFERRED_LABELS.find(l => labels.includes(l));
|
||||
const preferredLabel = PREFERRED_LABELS.find((l) => labels.includes(l));
|
||||
if (preferredLabel) {
|
||||
const values = await provider.getLabelValues(preferredLabel);
|
||||
const userExamples = shuffle(values)
|
||||
.slice(0, EXAMPLES_LIMIT)
|
||||
.map(value => `{${preferredLabel}="${value}"}`);
|
||||
.map((value) => `{${preferredLabel}="${value}"}`);
|
||||
this.setState({ userExamples });
|
||||
}
|
||||
} else {
|
||||
@@ -75,7 +75,7 @@ export default class LokiCheatSheet extends PureComponent<QueryEditorHelpProps,
|
||||
<div
|
||||
className="cheat-sheet-item__example"
|
||||
key={expr}
|
||||
onClick={e => onClickExample({ refId: 'A', expr } as DataQuery)}
|
||||
onClick={(e) => onClickExample({ refId: 'A', expr } as DataQuery)}
|
||||
>
|
||||
<code>{expr}</code>
|
||||
</div>
|
||||
@@ -98,7 +98,7 @@ export default class LokiCheatSheet extends PureComponent<QueryEditorHelpProps,
|
||||
{userExamples !== DEFAULT_EXAMPLES && userExamples.length > 0 ? (
|
||||
<div>
|
||||
<div className="cheat-sheet-item__label">Here are some example streams from your logs:</div>
|
||||
{userExamples.map(example => this.renderExpression(example))}
|
||||
{userExamples.map((example) => this.renderExpression(example))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -120,7 +120,7 @@ export default class LokiCheatSheet extends PureComponent<QueryEditorHelpProps,
|
||||
supports exact and regular expression filters.
|
||||
</div>
|
||||
</div>
|
||||
{LOGQL_EXAMPLES.map(item => (
|
||||
{LOGQL_EXAMPLES.map((item) => (
|
||||
<div className="cheat-sheet-item" key={item.expression}>
|
||||
<div className="cheat-sheet-item__title">{item.title}</div>
|
||||
{this.renderExpression(item.expression)}
|
||||
|
||||
@@ -8,7 +8,7 @@ type LokiQueryFieldProps = Omit<
|
||||
'labelsLoaded' | 'onLoadOptions' | 'onLabelsRefresh' | 'logLabelOptions' | 'absoluteRange'
|
||||
>;
|
||||
|
||||
export const LokiQueryField: FunctionComponent<LokiQueryFieldProps> = props => {
|
||||
export const LokiQueryField: FunctionComponent<LokiQueryFieldProps> = (props) => {
|
||||
const { datasource, range, ...otherProps } = props;
|
||||
const absoluteTimeRange = { from: range!.from!.valueOf(), to: range!.to!.valueOf() }; // Range here is never optional
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ export class LokiQueryFieldForm extends React.PureComponent<LokiQueryFieldFormPr
|
||||
disabled={buttonDisabled}
|
||||
onChange={this.onChangeLogLabels}
|
||||
loadData={onLoadOptions}
|
||||
onPopupVisibleChange={isVisible => isVisible && onLabelsRefresh && onLabelsRefresh()}
|
||||
onPopupVisibleChange={(isVisible) => isVisible && onLabelsRefresh && onLabelsRefresh()}
|
||||
>
|
||||
{chooserText}
|
||||
</ButtonCascader>
|
||||
|
||||
@@ -40,7 +40,7 @@ export const ConfigEditor = (props: Props) => {
|
||||
<div className="gf-form">
|
||||
<MaxLinesField
|
||||
value={options.jsonData.maxLines || ''}
|
||||
onChange={value => onOptionsChange(setMaxLines(options, value))}
|
||||
onChange={(value) => onOptionsChange(setMaxLines(options, value))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@ export const ConfigEditor = (props: Props) => {
|
||||
|
||||
<DerivedFields
|
||||
value={options.jsonData.derivedFields}
|
||||
onChange={value => onOptionsChange(setDerivedFields(options, value))}
|
||||
onChange={(value) => onOptionsChange(setDerivedFields(options, value))}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -66,11 +66,6 @@ describe('DebugSection', () => {
|
||||
expect(wrapper.find('table').length).toBe(1);
|
||||
// 3 rows + one header
|
||||
expect(wrapper.find('tr').length).toBe(4);
|
||||
expect(
|
||||
wrapper
|
||||
.find('tr')
|
||||
.at(1)
|
||||
.contains('http://localhost/trace/1234')
|
||||
).toBeTruthy();
|
||||
expect(wrapper.find('tr').at(1).contains('http://localhost/trace/1234')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ export const DebugSection = (props: Props) => {
|
||||
`
|
||||
)}
|
||||
value={debugText}
|
||||
onChange={event => setDebugText(event.currentTarget.value)}
|
||||
onChange={(event) => setDebugText(event.currentTarget.value)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
@@ -58,7 +58,7 @@ const DebugFields = ({ fields }: DebugFieldItemProps) => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{fields.map(field => {
|
||||
{fields.map((field) => {
|
||||
let value: any = field.value;
|
||||
if (field.error) {
|
||||
value = field.error.message;
|
||||
@@ -87,8 +87,8 @@ type DebugField = {
|
||||
|
||||
function makeDebugFields(derivedFields: DerivedFieldConfig[], debugText: string): DebugField[] {
|
||||
return derivedFields
|
||||
.filter(field => field.name && field.matcherRegex)
|
||||
.map(field => {
|
||||
.filter((field) => field.name && field.matcherRegex)
|
||||
.map((field) => {
|
||||
try {
|
||||
const testMatch = debugText.match(field.matcherRegex);
|
||||
const value = testMatch && testMatch[1];
|
||||
|
||||
@@ -79,7 +79,7 @@ export const DerivedField = (props: Props) => {
|
||||
variant="destructive"
|
||||
title="Remove field"
|
||||
icon="times"
|
||||
onClick={event => {
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
onDelete();
|
||||
}}
|
||||
@@ -96,7 +96,7 @@ export const DerivedField = (props: Props) => {
|
||||
<DataLinkInput
|
||||
placeholder={showInternalLink ? '${__value.raw}' : 'http://example.com/${__value.raw}'}
|
||||
value={value.url || ''}
|
||||
onChange={newValue =>
|
||||
onChange={(newValue) =>
|
||||
onChange({
|
||||
...value,
|
||||
url: newValue,
|
||||
@@ -128,7 +128,7 @@ export const DerivedField = (props: Props) => {
|
||||
{showInternalLink && (
|
||||
<DataSourcePicker
|
||||
tracing={true}
|
||||
onChange={ds =>
|
||||
onChange={(ds) =>
|
||||
onChange({
|
||||
...value,
|
||||
datasourceUid: ds.uid,
|
||||
|
||||
@@ -60,10 +60,7 @@ describe('DerivedFields', () => {
|
||||
await act(async () => {
|
||||
wrapper = await mount(<DerivedFields value={testValue} onChange={onChangeMock} />);
|
||||
});
|
||||
const removeButton = wrapper
|
||||
.find(DerivedField)
|
||||
.at(0)
|
||||
.find(Button);
|
||||
const removeButton = wrapper.find(DerivedField).at(0).find(Button);
|
||||
removeButton.simulate('click');
|
||||
const newValue = onChangeMock.mock.calls[0][0];
|
||||
expect(newValue.length).toBe(1);
|
||||
|
||||
@@ -44,7 +44,7 @@ export const DerivedFields = (props: Props) => {
|
||||
className={styles.derivedField}
|
||||
key={index}
|
||||
value={field}
|
||||
onChange={newField => {
|
||||
onChange={(newField) => {
|
||||
const newDerivedFields = [...value];
|
||||
newDerivedFields.splice(index, 1, newField);
|
||||
onChange(newDerivedFields);
|
||||
@@ -72,7 +72,7 @@ export const DerivedFields = (props: Props) => {
|
||||
margin-right: 10px;
|
||||
`}
|
||||
icon="plus"
|
||||
onClick={event => {
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
const newDerivedFields = [...(value || []), { name: '', matcherRegex: '' }];
|
||||
onChange(newDerivedFields);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const MaxLinesField = (props: Props) => {
|
||||
type="number"
|
||||
className="gf-form-input width-8 gf-form-input--has-help-icon"
|
||||
value={value}
|
||||
onChange={event => onChange(event.currentTarget.value)}
|
||||
onChange={(event) => onChange(event.currentTarget.value)}
|
||||
spellCheck={false}
|
||||
placeholder="1000"
|
||||
/>
|
||||
|
||||
@@ -270,7 +270,7 @@ describe('LokiDatasource', () => {
|
||||
|
||||
fetchMock.mockImplementation(() => of(testMetricsResponse));
|
||||
|
||||
await expect(ds.query(options)).toEmitValuesWith(received => {
|
||||
await expect(ds.query(options)).toEmitValuesWith((received) => {
|
||||
const result = received[0];
|
||||
const timeSeries = result.data[0] as TimeSeries;
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('LokiDatasource', () => {
|
||||
|
||||
fetchMock.mockImplementation(() => of(testLogsResponse));
|
||||
|
||||
await expect(ds.query(options)).toEmitValuesWith(received => {
|
||||
await expect(ds.query(options)).toEmitValuesWith((received) => {
|
||||
const result = received[0];
|
||||
const dataFrame = result.data[0] as DataFrame;
|
||||
const fieldCache = new FieldCache(dataFrame);
|
||||
@@ -315,7 +315,7 @@ describe('LokiDatasource', () => {
|
||||
})
|
||||
);
|
||||
|
||||
await expect(ds.query(options)).toEmitValuesWith(received => {
|
||||
await expect(ds.query(options)).toEmitValuesWith((received) => {
|
||||
const err: any = received[0];
|
||||
expect(err.data.message).toBe(
|
||||
'Error: parse error at line 1, col 6: invalid char escape. Make sure that all special characters are escaped with \\. For more information on escaping of special characters visit LogQL documentation at https://grafana.com/docs/loki/latest/logql/.'
|
||||
|
||||
@@ -96,8 +96,8 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
query(options: DataQueryRequest<LokiQuery>): Observable<DataQueryResponse> {
|
||||
const subQueries: Array<Observable<DataQueryResponse>> = [];
|
||||
const filteredTargets = options.targets
|
||||
.filter(target => target.expr && !target.hide)
|
||||
.map(target => ({
|
||||
.filter((target) => target.expr && !target.hide)
|
||||
.map((target) => ({
|
||||
...target,
|
||||
expr: this.templateSrv.replace(target.expr, options.scopedVars, this.interpolateQueryExpr),
|
||||
}));
|
||||
@@ -259,7 +259,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
const liveTarget = this.createLiveTarget(target, maxDataPoints);
|
||||
|
||||
return this.streams.getStream(liveTarget).pipe(
|
||||
map(data => ({
|
||||
map((data) => ({
|
||||
data: data || [],
|
||||
key: `loki-${liveTarget.refId}`,
|
||||
state: LoadingState.Streaming,
|
||||
@@ -270,7 +270,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
interpolateVariablesInQueries(queries: LokiQuery[], scopedVars: ScopedVars): LokiQuery[] {
|
||||
let expandedQueries = queries;
|
||||
if (queries && queries.length) {
|
||||
expandedQueries = queries.map(query => ({
|
||||
expandedQueries = queries.map((query) => ({
|
||||
...query,
|
||||
datasource: this.name,
|
||||
expr: this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr),
|
||||
@@ -400,7 +400,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
}),
|
||||
switchMap((res: { data: LokiStreamResponse; status: number }) =>
|
||||
of({
|
||||
data: res.data ? res.data.data.result.map(stream => lokiStreamResultToDataFrame(stream, reverse)) : [],
|
||||
data: res.data ? res.data.data.result.map((stream) => lokiStreamResultToDataFrame(stream, reverse)) : [],
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -409,7 +409,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
|
||||
prepareLogRowContextQueryTarget = (row: LogRowModel, limit: number, direction: 'BACKWARD' | 'FORWARD') => {
|
||||
const query = Object.keys(row.labels)
|
||||
.map(label => `${label}="${row.labels[label].replace(/\\/g, '\\\\')}"`) // escape backslashes in label as users can't escape them by themselves
|
||||
.map((label) => `${label}="${row.labels[label].replace(/\\/g, '\\\\')}"`) // escape backslashes in label as users can't escape them by themselves
|
||||
.join(',');
|
||||
|
||||
const contextTimeBuffer = 2 * 60 * 60 * 1000; // 2h buffer
|
||||
@@ -451,7 +451,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
const start = `${startMs}000000`; // API expects nanoseconds
|
||||
return this._request(`${LOKI_ENDPOINT}/label`, { start })
|
||||
.pipe(
|
||||
map(res => {
|
||||
map((res) => {
|
||||
const values: any[] = res?.data?.data || res?.data?.values || [];
|
||||
const testResult =
|
||||
values.length > 0
|
||||
@@ -505,7 +505,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
}
|
||||
const view = new DataFrameView<{ ts: string; line: string }>(frame);
|
||||
|
||||
view.forEach(row => {
|
||||
view.forEach((row) => {
|
||||
annotations.push({
|
||||
time: new Date(row.ts).valueOf(),
|
||||
text: row.line,
|
||||
@@ -569,7 +569,7 @@ export function lokiSpecialRegexEscape(value: any) {
|
||||
*/
|
||||
function isMetricsQuery(query: string): boolean {
|
||||
const tokens = Prism.tokenize(query, syntax);
|
||||
return tokens.some(t => {
|
||||
return tokens.some((t) => {
|
||||
// Not sure in which cases it can be string maybe if nothing matched which means it should not be a function
|
||||
return typeof t !== 'string' && t.type === 'function';
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ type TypeaheadContext = {
|
||||
|
||||
export function addHistoryMetadata(item: CompletionItem, history: LokiHistoryItem[]): CompletionItem {
|
||||
const cutoffTs = Date.now() - HISTORY_COUNT_CUTOFF;
|
||||
const historyForItem = history.filter(h => h.ts > cutoffTs && h.query.expr === item.label);
|
||||
const historyForItem = history.filter((h) => h.ts > cutoffTs && h.query.expr === item.label);
|
||||
let hint = `Queried ${historyForItem.length} times in the last 24h.`;
|
||||
const recent = historyForItem[0];
|
||||
|
||||
@@ -193,12 +193,12 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
|
||||
if (history?.length) {
|
||||
const historyItems = _.chain(history)
|
||||
.map(h => h.query.expr)
|
||||
.map((h) => h.query.expr)
|
||||
.filter()
|
||||
.uniq()
|
||||
.take(HISTORY_ITEM_COUNT)
|
||||
.map(wrapLabel)
|
||||
.map(item => addHistoryMetadata(item, history))
|
||||
.map((item) => addHistoryMetadata(item, history))
|
||||
.value();
|
||||
|
||||
suggestions.push({
|
||||
@@ -218,7 +218,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
suggestions.push({
|
||||
prefixMatch: true,
|
||||
label: 'Functions',
|
||||
items: FUNCTIONS.map(suggestion => ({ ...suggestion, kind: 'function' })),
|
||||
items: FUNCTIONS.map((suggestion) => ({ ...suggestion, kind: 'function' })),
|
||||
});
|
||||
|
||||
return { suggestions };
|
||||
@@ -229,12 +229,12 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
|
||||
suggestions.push({
|
||||
label: 'Operators',
|
||||
items: PIPE_OPERATORS.map(suggestion => ({ ...suggestion, kind: 'operators' })),
|
||||
items: PIPE_OPERATORS.map((suggestion) => ({ ...suggestion, kind: 'operators' })),
|
||||
});
|
||||
|
||||
suggestions.push({
|
||||
label: 'Parsers',
|
||||
items: PIPE_PARSERS.map(suggestion => ({ ...suggestion, kind: 'parsers' })),
|
||||
items: PIPE_PARSERS.map((suggestion) => ({ ...suggestion, kind: 'parsers' })),
|
||||
});
|
||||
|
||||
return { suggestions };
|
||||
@@ -316,7 +316,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
if (labelKeys) {
|
||||
const possibleKeys = _.difference(labelKeys, existingKeys);
|
||||
if (possibleKeys.length) {
|
||||
const newItems = possibleKeys.map(key => ({ label: key }));
|
||||
const newItems = possibleKeys.map((key) => ({ label: key }));
|
||||
const newSuggestion: CompletionItemGroup = { label: `Labels`, items: newItems };
|
||||
suggestions.push(newSuggestion);
|
||||
}
|
||||
@@ -329,7 +329,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
async importQueries(queries: LokiQuery[], datasourceType: string): Promise<LokiQuery[]> {
|
||||
if (datasourceType === 'prometheus') {
|
||||
return Promise.all(
|
||||
queries.map(async query => {
|
||||
queries.map(async (query) => {
|
||||
const expr = await this.importPrometheusQuery(query.expr);
|
||||
const { ...rest } = query as PromQuery;
|
||||
return {
|
||||
@@ -340,7 +340,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
);
|
||||
}
|
||||
// Return a cleaned LokiQuery
|
||||
return queries.map(query => ({
|
||||
return queries.map((query) => ({
|
||||
refId: query.refId,
|
||||
expr: '',
|
||||
}));
|
||||
@@ -383,7 +383,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
|
||||
const labelKeys = Object.keys(labelsToKeep).sort();
|
||||
const cleanSelector = labelKeys
|
||||
.map(key => `${key}${labelsToKeep[key].operator}${labelsToKeep[key].value}`)
|
||||
.map((key) => `${key}${labelsToKeep[key].operator}${labelsToKeep[key].value}`)
|
||||
.join(',');
|
||||
|
||||
return ['{', cleanSelector, '}'].join('');
|
||||
@@ -497,11 +497,11 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
}
|
||||
|
||||
private addLabelValuesToOptions = (labelKey: string, values: string[]) => {
|
||||
return this.logLabelOptions.map(keyOption =>
|
||||
return this.logLabelOptions.map((keyOption) =>
|
||||
keyOption.value === labelKey
|
||||
? {
|
||||
...keyOption,
|
||||
children: values.map(value => ({ label: value, value })),
|
||||
children: values.map((value) => ({ label: value, value })),
|
||||
}
|
||||
: keyOption
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('Live Stream Tests', () => {
|
||||
dropped_entries: null,
|
||||
};
|
||||
|
||||
it('reads the values into the buffer', done => {
|
||||
it('reads the values into the buffer', (done) => {
|
||||
fakeSocket = new Subject<any>();
|
||||
const labels: Labels = { job: 'varlogs' };
|
||||
const target = makeTarget('fake', labels);
|
||||
@@ -55,7 +55,7 @@ describe('Live Stream Tests', () => {
|
||||
},
|
||||
];
|
||||
stream.subscribe({
|
||||
next: val => {
|
||||
next: (val) => {
|
||||
const test = tests.shift();
|
||||
test!(val);
|
||||
},
|
||||
@@ -140,7 +140,7 @@ describe('Live Stream Tests', () => {
|
||||
})
|
||||
) as any;
|
||||
const liveStreams = new LiveStreams();
|
||||
await expect(liveStreams.getStream(makeTarget('url_to_match'), 100)).toEmitValuesWith(received => {
|
||||
await expect(liveStreams.getStream(makeTarget('url_to_match'), 100)).toEmitValuesWith((received) => {
|
||||
const data = received[0];
|
||||
const view = new DataFrameView(data[0]);
|
||||
const firstLog = { ...view.get(0) };
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('loki result transformer', () => {
|
||||
|
||||
describe('lokiStreamResultToDataFrame', () => {
|
||||
it('converts streams to series', () => {
|
||||
const data = streamResult.map(stream => ResultTransformer.lokiStreamResultToDataFrame(stream));
|
||||
const data = streamResult.map((stream) => ResultTransformer.lokiStreamResultToDataFrame(stream));
|
||||
|
||||
expect(data.length).toBe(2);
|
||||
expect(data[0].fields[1].labels!['foo']).toEqual('bar');
|
||||
@@ -101,7 +101,7 @@ describe('loki result transformer', () => {
|
||||
},
|
||||
];
|
||||
|
||||
const data = streamResultWithDuplicateLogs.map(stream => ResultTransformer.lokiStreamResultToDataFrame(stream));
|
||||
const data = streamResultWithDuplicateLogs.map((stream) => ResultTransformer.lokiStreamResultToDataFrame(stream));
|
||||
|
||||
expect(data[0].fields[2].values.get(0)).toEqual('65cee200875f58ee1430d8bd2e8b74e7');
|
||||
expect(data[0].fields[2].values.get(1)).toEqual('65cee200875f58ee1430d8bd2e8b74e7_1');
|
||||
@@ -125,9 +125,9 @@ describe('loki result transformer', () => {
|
||||
});
|
||||
|
||||
expect(ResultTransformer.enhanceDataFrame).toBeCalled();
|
||||
dataFrames.forEach(frame => {
|
||||
dataFrames.forEach((frame) => {
|
||||
expect(
|
||||
frame.fields.filter(field => field.name === 'test' && field.type === 'string').length
|
||||
frame.fields.filter((field) => field.name === 'test' && field.type === 'string').length
|
||||
).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -240,12 +240,12 @@ export function lokiResultsToTableModel(
|
||||
table.meta = meta;
|
||||
table.columns = [
|
||||
{ text: 'Time', type: FieldType.time },
|
||||
...sortedLabels.map(label => ({ text: label, filterable: true, type: FieldType.string })),
|
||||
...sortedLabels.map((label) => ({ text: label, filterable: true, type: FieldType.string })),
|
||||
{ text: resultCount > 1 || valueWithRefId ? `Value #${refId}` : 'Value', type: FieldType.number },
|
||||
];
|
||||
|
||||
// Populate rows, set value to empty string when label not present.
|
||||
lokiResults.forEach(series => {
|
||||
lokiResults.forEach((series) => {
|
||||
const newSeries: LokiMatrixResult = {
|
||||
metric: series.metric,
|
||||
values: (series as LokiVectorResult).value
|
||||
@@ -263,7 +263,7 @@ export function lokiResultsToTableModel(
|
||||
table.rows.push(
|
||||
...newSeries.values.map(([a, b]) => [
|
||||
a * 1000,
|
||||
...sortedLabels.map(label => newSeries.metric[label] || ''),
|
||||
...sortedLabels.map((label) => newSeries.metric[label] || ''),
|
||||
parseFloat(b),
|
||||
])
|
||||
);
|
||||
@@ -294,13 +294,13 @@ function getOriginalMetricName(labelData: { [key: string]: string }) {
|
||||
const metricName = labelData.__name__ || '';
|
||||
delete labelData.__name__;
|
||||
const labelPart = Object.entries(labelData)
|
||||
.map(label => `${label[0]}="${label[1]}"`)
|
||||
.map((label) => `${label[0]}="${label[1]}"`)
|
||||
.join(',');
|
||||
return `${metricName}{${labelPart}}`;
|
||||
}
|
||||
|
||||
export function decamelize(s: string): string {
|
||||
return s.replace(/[A-Z]/g, m => ` ${m.toLowerCase()}`);
|
||||
return s.replace(/[A-Z]/g, (m) => ` ${m.toLowerCase()}`);
|
||||
}
|
||||
|
||||
// Turn loki stats { metric: value } into meta stat { title: metric, value: value }
|
||||
@@ -353,11 +353,11 @@ export function lokiStreamsToDataFrames(
|
||||
preferredVisualisationType: 'logs',
|
||||
};
|
||||
|
||||
const series: DataFrame[] = data.map(stream => {
|
||||
const series: DataFrame[] = data.map((stream) => {
|
||||
const dataFrame = lokiStreamResultToDataFrame(stream, reverse);
|
||||
enhanceDataFrame(dataFrame, config);
|
||||
|
||||
if (meta.custom && dataFrame.fields.some(f => f.labels && Object.keys(f.labels).some(l => l === '__error__'))) {
|
||||
if (meta.custom && dataFrame.fields.some((f) => f.labels && Object.keys(f.labels).some((l) => l === '__error__'))) {
|
||||
meta.custom.error = 'Error when parsing some of the logs';
|
||||
}
|
||||
|
||||
@@ -480,11 +480,11 @@ export function rangeQueryResponseToTimeSeries(
|
||||
|
||||
switch (response.data.resultType) {
|
||||
case LokiResultType.Vector:
|
||||
return response.data.result.map(vecResult =>
|
||||
return response.data.result.map((vecResult) =>
|
||||
lokiMatrixToTimeSeries({ metric: vecResult.metric, values: [vecResult.value] }, transformerOptions)
|
||||
);
|
||||
case LokiResultType.Matrix:
|
||||
return response.data.result.map(matrixResult => lokiMatrixToTimeSeries(matrixResult, transformerOptions));
|
||||
return response.data.result.map((matrixResult) => lokiMatrixToTimeSeries(matrixResult, transformerOptions));
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -205,12 +205,12 @@ const tokenizer: Grammar = {
|
||||
alias: 'operator',
|
||||
},
|
||||
'pipe-operations': {
|
||||
pattern: new RegExp(`${[...PIPE_PARSERS, ...PIPE_OPERATORS].map(f => f.label).join('|')}`, 'i'),
|
||||
pattern: new RegExp(`${[...PIPE_PARSERS, ...PIPE_OPERATORS].map((f) => f.label).join('|')}`, 'i'),
|
||||
alias: 'keyword',
|
||||
},
|
||||
},
|
||||
},
|
||||
function: new RegExp(`\\b(?:${FUNCTIONS.map(f => f.label).join('|')})(?=\\s*\\()`, 'i'),
|
||||
function: new RegExp(`\\b(?:${FUNCTIONS.map((f) => f.label).join('|')})(?=\\s*\\()`, 'i'),
|
||||
'context-range': [
|
||||
{
|
||||
pattern: /\[[^\]]*(?=\])/, // [1m]
|
||||
|
||||
Reference in New Issue
Block a user