mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Remove tracking grafana_loki_query_executed
and add grafana_explore_loki_query_executed
(#86484)
* Loki: Remove and add * Update public/app/plugins/datasource/loki/tracking.ts Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com> --------- Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
This commit is contained in:
parent
1d513f66b8
commit
f3fd2de9dd
@ -205,7 +205,7 @@ describe('LokiDatasource', () => {
|
||||
it('should report query interaction', async () => {
|
||||
await runTest(80, '40', 80, CoreApp.Explore);
|
||||
expect(reportInteraction).toHaveBeenCalledWith(
|
||||
'grafana_loki_query_executed',
|
||||
'grafana_explore_loki_query_executed',
|
||||
expect.objectContaining({
|
||||
query_type: 'logs',
|
||||
line_limit: 80,
|
||||
@ -219,16 +219,9 @@ describe('LokiDatasource', () => {
|
||||
expect(reportInteraction).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should not report query interaction for panel edit query', async () => {
|
||||
await runTest(80, '40', 80, CoreApp.PanelEditor);
|
||||
expect(reportInteraction).toHaveBeenCalledWith(
|
||||
'grafana_loki_query_executed',
|
||||
expect.objectContaining({
|
||||
query_type: 'logs',
|
||||
line_limit: 80,
|
||||
obfuscated_query: '{Identifier=String}',
|
||||
})
|
||||
);
|
||||
it('should not report query interaction for unknown app query', async () => {
|
||||
await runTest(80, '40', 80, CoreApp.Unknown);
|
||||
expect(reportInteraction).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DashboardLoadedEvent, DataQueryRequest, dateTime } from '@grafana/data';
|
||||
import { CoreApp, DashboardLoadedEvent, DataQueryRequest, dateTime } from '@grafana/data';
|
||||
import { QueryEditorMode } from '@grafana/experimental';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
|
||||
@ -31,7 +31,7 @@ const originalRequest = {
|
||||
{ expr: 'count_over_time({hidden="true"}[1m])', refId: 'C', ...baseTarget, hide: true },
|
||||
],
|
||||
range,
|
||||
app: 'explore',
|
||||
app: CoreApp.Explore,
|
||||
} as DataQueryRequest<LokiQuery>;
|
||||
|
||||
const requests: LokiGroupedRequest[] = [
|
||||
@ -64,37 +64,46 @@ beforeEach(() => {
|
||||
jest.mocked(reportInteraction).mockClear();
|
||||
});
|
||||
|
||||
test('Tracks queries', () => {
|
||||
trackQuery({ data: [] }, originalRequest, new Date());
|
||||
describe('Tracks queries', () => {
|
||||
it('should track queries in Explore', () => {
|
||||
trackQuery({ data: [] }, originalRequest, new Date());
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
|
||||
bytes_processed: 0,
|
||||
editor_mode: 'builder',
|
||||
grafana_version: '1.0',
|
||||
has_data: false,
|
||||
has_error: false,
|
||||
is_split: false,
|
||||
legend: undefined,
|
||||
line_limit: undefined,
|
||||
obfuscated_query: 'count_over_time({Identifier=String}[1m])',
|
||||
query_type: 'metric',
|
||||
query_vector_type: undefined,
|
||||
resolution: 1,
|
||||
simultaneously_executed_query_count: 2,
|
||||
simultaneously_hidden_query_count: 1,
|
||||
time_range_from: '2023-02-08T05:00:00.000Z',
|
||||
time_range_to: '2023-02-10T06:00:00.000Z',
|
||||
time_taken: 0,
|
||||
predefined_operations_applied: 'n/a',
|
||||
});
|
||||
});
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', {
|
||||
app: 'explore',
|
||||
bytes_processed: 0,
|
||||
editor_mode: 'builder',
|
||||
grafana_version: '1.0',
|
||||
has_data: false,
|
||||
has_error: false,
|
||||
is_split: false,
|
||||
legend: undefined,
|
||||
line_limit: undefined,
|
||||
obfuscated_query: 'count_over_time({Identifier=String}[1m])',
|
||||
query_type: 'metric',
|
||||
query_vector_type: undefined,
|
||||
resolution: 1,
|
||||
simultaneously_executed_query_count: 2,
|
||||
simultaneously_hidden_query_count: 1,
|
||||
time_range_from: '2023-02-08T05:00:00.000Z',
|
||||
time_range_to: '2023-02-10T06:00:00.000Z',
|
||||
time_taken: 0,
|
||||
predefined_operations_applied: 'n/a',
|
||||
it('should not track queries if app is not Explore', () => {
|
||||
trackQuery({ data: [] }, { ...originalRequest, app: CoreApp.PanelViewer }, new Date());
|
||||
expect(reportInteraction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not track queries if no app', () => {
|
||||
trackQuery({ data: [] }, { ...originalRequest, app: '' }, new Date());
|
||||
expect(reportInteraction).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
test('Tracks predefined operations', () => {
|
||||
trackQuery({ data: [] }, originalRequest, new Date(), { predefinedOperations: 'count_over_time' });
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', {
|
||||
app: 'explore',
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
|
||||
bytes_processed: 0,
|
||||
editor_mode: 'builder',
|
||||
grafana_version: '1.0',
|
||||
@ -119,8 +128,7 @@ test('Tracks predefined operations', () => {
|
||||
test('Tracks grouped queries', () => {
|
||||
trackGroupedQueries({ data: [] }, requests, originalRequest, new Date());
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', {
|
||||
app: 'explore',
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
|
||||
bytes_processed: 0,
|
||||
editor_mode: 'builder',
|
||||
grafana_version: '1.0',
|
||||
@ -145,8 +153,7 @@ test('Tracks grouped queries', () => {
|
||||
predefined_operations_applied: 'n/a',
|
||||
});
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', {
|
||||
app: 'explore',
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
|
||||
bytes_processed: 0,
|
||||
editor_mode: 'builder',
|
||||
grafana_version: '1.0',
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
REF_ID_DATA_SAMPLES,
|
||||
REF_ID_STARTER_LOG_ROW_CONTEXT,
|
||||
REF_ID_STARTER_LOG_VOLUME,
|
||||
REF_ID_STARTER_LOG_SAMPLE,
|
||||
} from './datasource';
|
||||
import pluginJson from './plugin.json';
|
||||
import { getNormalizedLokiQuery, isLogsQuery, obfuscate } from './queryUtils';
|
||||
@ -127,9 +128,15 @@ const isQueryWithChangedLegend = (query: LokiQuery): boolean => {
|
||||
};
|
||||
|
||||
const shouldNotReportBasedOnRefId = (refId: string): boolean => {
|
||||
const starters = [REF_ID_STARTER_ANNOTATION, REF_ID_STARTER_LOG_ROW_CONTEXT, REF_ID_STARTER_LOG_VOLUME];
|
||||
const starters = [
|
||||
REF_ID_STARTER_ANNOTATION,
|
||||
REF_ID_STARTER_LOG_ROW_CONTEXT,
|
||||
REF_ID_STARTER_LOG_VOLUME,
|
||||
REF_ID_STARTER_LOG_SAMPLE,
|
||||
REF_ID_DATA_SAMPLES,
|
||||
];
|
||||
|
||||
if (refId === REF_ID_DATA_SAMPLES || starters.some((starter) => refId.startsWith(starter))) {
|
||||
if (starters.some((starter) => refId.startsWith(starter))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -157,7 +164,7 @@ export function trackQuery(
|
||||
// We only want to track usage for these specific apps
|
||||
const { app, targets: queries } = request;
|
||||
|
||||
if (app === CoreApp.Dashboard || app === CoreApp.PanelViewer) {
|
||||
if (app !== CoreApp.Explore) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -168,8 +175,7 @@ export function trackQuery(
|
||||
return;
|
||||
}
|
||||
|
||||
reportInteraction('grafana_loki_query_executed', {
|
||||
app,
|
||||
reportInteraction('grafana_explore_loki_query_executed', {
|
||||
grafana_version: config.buildInfo.version,
|
||||
editor_mode: query.editorMode,
|
||||
has_data: response.data.some((frame) => frame.length > 0),
|
||||
|
Loading…
Reference in New Issue
Block a user