mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Remove annotation, context and volume tracking (#59962)
* Loki: Remove annotation and context tracking * Implement log volume
This commit is contained in:
parent
955bf55c6a
commit
601df109af
@ -77,6 +77,9 @@ export type RangeQueryOptions = DataQueryRequest<LokiQuery> | AnnotationQueryReq
|
||||
export const DEFAULT_MAX_LINES = 1000;
|
||||
export const LOKI_ENDPOINT = '/loki/api/v1';
|
||||
export const REF_ID_DATA_SAMPLES = 'loki-data-samples';
|
||||
export const REF_ID_STARTER_ANNOTATION = 'annotation-';
|
||||
export const REF_ID_STARTER_LOG_ROW_CONTEXT = 'log-row-context-query-';
|
||||
export const REF_ID_STARTER_LOG_VOLUME = 'log-volume-';
|
||||
const NS_IN_MS = 1000000;
|
||||
|
||||
function makeRequest(
|
||||
@ -148,6 +151,7 @@ export class LokiDatasource
|
||||
const query = removeCommentsFromQuery(target.expr);
|
||||
return {
|
||||
...target,
|
||||
refId: `${REF_ID_STARTER_LOG_VOLUME}${target.refId}`,
|
||||
instant: false,
|
||||
volumeQuery: true,
|
||||
expr: `sum by (level) (count_over_time(${query}[$__interval]))`,
|
||||
@ -557,7 +561,7 @@ export class LokiDatasource
|
||||
const app = CoreApp.Explore;
|
||||
|
||||
return lastValueFrom(
|
||||
this.query(makeRequest(query, range, app, `log-row-context-query-${direction}`)).pipe(
|
||||
this.query(makeRequest(query, range, app, `${REF_ID_STARTER_LOG_ROW_CONTEXT}${direction}`)).pipe(
|
||||
catchError((err) => {
|
||||
const error: DataQueryError = {
|
||||
message: 'Error during context query. Please check JS console logs.',
|
||||
@ -598,7 +602,7 @@ export class LokiDatasource
|
||||
const query: LokiQuery = {
|
||||
expr: `{${expr}}`,
|
||||
queryType: LokiQueryType.Range,
|
||||
refId: row.dataFrame.refId ?? '',
|
||||
refId: `${REF_ID_STARTER_LOG_ROW_CONTEXT}${row.dataFrame.refId || ''}`,
|
||||
maxLines: limit,
|
||||
direction: queryDirection,
|
||||
};
|
||||
@ -676,7 +680,7 @@ export class LokiDatasource
|
||||
return [];
|
||||
}
|
||||
|
||||
const id = `annotation-${options.annotation.name}`;
|
||||
const id = `${REF_ID_STARTER_ANNOTATION}${options.annotation.name}`;
|
||||
|
||||
const query: LokiQuery = {
|
||||
refId: id,
|
||||
|
@ -4,7 +4,12 @@ import { variableRegex } from 'app/features/variables/utils';
|
||||
|
||||
import { QueryEditorMode } from '../prometheus/querybuilder/shared/types';
|
||||
|
||||
import { REF_ID_DATA_SAMPLES } from './datasource';
|
||||
import {
|
||||
REF_ID_STARTER_ANNOTATION,
|
||||
REF_ID_DATA_SAMPLES,
|
||||
REF_ID_STARTER_LOG_ROW_CONTEXT,
|
||||
REF_ID_STARTER_LOG_VOLUME,
|
||||
} from './datasource';
|
||||
import pluginJson from './plugin.json';
|
||||
import { getNormalizedLokiQuery, isLogsQuery, parseToNodeNamesArray } from './queryUtils';
|
||||
import { LokiQuery, LokiQueryType } from './types';
|
||||
@ -118,9 +123,18 @@ const isQueryWithChangedLegend = (query: LokiQuery): boolean => {
|
||||
return query.legendFormat !== '';
|
||||
};
|
||||
|
||||
const shouldNotReportBasedOnRefId = (refId: string): boolean => {
|
||||
const starters = [REF_ID_STARTER_ANNOTATION, REF_ID_STARTER_LOG_ROW_CONTEXT, REF_ID_STARTER_LOG_VOLUME];
|
||||
|
||||
if (refId === REF_ID_DATA_SAMPLES || starters.some((starter) => refId.startsWith(starter))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export function trackQuery(response: DataQueryResponse, queries: LokiQuery[], app: string): void {
|
||||
for (const query of queries) {
|
||||
if (query.refId === REF_ID_DATA_SAMPLES) {
|
||||
if (shouldNotReportBasedOnRefId(query.refId)) {
|
||||
return;
|
||||
}
|
||||
reportInteraction('grafana_loki_query_executed', {
|
||||
|
Loading…
Reference in New Issue
Block a user