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:
Ivana Huckova 2024-04-18 10:57:18 +02:00 committed by GitHub
parent 1d513f66b8
commit f3fd2de9dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 46 deletions

View File

@ -205,7 +205,7 @@ describe('LokiDatasource', () => {
it('should report query interaction', async () => { it('should report query interaction', async () => {
await runTest(80, '40', 80, CoreApp.Explore); await runTest(80, '40', 80, CoreApp.Explore);
expect(reportInteraction).toHaveBeenCalledWith( expect(reportInteraction).toHaveBeenCalledWith(
'grafana_loki_query_executed', 'grafana_explore_loki_query_executed',
expect.objectContaining({ expect.objectContaining({
query_type: 'logs', query_type: 'logs',
line_limit: 80, line_limit: 80,
@ -219,16 +219,9 @@ describe('LokiDatasource', () => {
expect(reportInteraction).not.toBeCalled(); expect(reportInteraction).not.toBeCalled();
}); });
it('should not report query interaction for panel edit query', async () => { it('should not report query interaction for unknown app query', async () => {
await runTest(80, '40', 80, CoreApp.PanelEditor); await runTest(80, '40', 80, CoreApp.Unknown);
expect(reportInteraction).toHaveBeenCalledWith( expect(reportInteraction).not.toBeCalled();
'grafana_loki_query_executed',
expect.objectContaining({
query_type: 'logs',
line_limit: 80,
obfuscated_query: '{Identifier=String}',
})
);
}); });
}); });

View File

@ -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 { QueryEditorMode } from '@grafana/experimental';
import { reportInteraction } from '@grafana/runtime'; import { reportInteraction } from '@grafana/runtime';
@ -31,7 +31,7 @@ const originalRequest = {
{ expr: 'count_over_time({hidden="true"}[1m])', refId: 'C', ...baseTarget, hide: true }, { expr: 'count_over_time({hidden="true"}[1m])', refId: 'C', ...baseTarget, hide: true },
], ],
range, range,
app: 'explore', app: CoreApp.Explore,
} as DataQueryRequest<LokiQuery>; } as DataQueryRequest<LokiQuery>;
const requests: LokiGroupedRequest[] = [ const requests: LokiGroupedRequest[] = [
@ -64,37 +64,46 @@ beforeEach(() => {
jest.mocked(reportInteraction).mockClear(); jest.mocked(reportInteraction).mockClear();
}); });
test('Tracks queries', () => { describe('Tracks queries', () => {
trackQuery({ data: [] }, originalRequest, new Date()); 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', { it('should not track queries if app is not Explore', () => {
app: 'explore', trackQuery({ data: [] }, { ...originalRequest, app: CoreApp.PanelViewer }, new Date());
bytes_processed: 0, expect(reportInteraction).not.toHaveBeenCalled();
editor_mode: 'builder', });
grafana_version: '1.0',
has_data: false, it('should not track queries if no app', () => {
has_error: false, trackQuery({ data: [] }, { ...originalRequest, app: '' }, new Date());
is_split: false, expect(reportInteraction).not.toHaveBeenCalled();
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',
}); });
}); });
test('Tracks predefined operations', () => { test('Tracks predefined operations', () => {
trackQuery({ data: [] }, originalRequest, new Date(), { predefinedOperations: 'count_over_time' }); trackQuery({ data: [] }, originalRequest, new Date(), { predefinedOperations: 'count_over_time' });
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', { expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
app: 'explore',
bytes_processed: 0, bytes_processed: 0,
editor_mode: 'builder', editor_mode: 'builder',
grafana_version: '1.0', grafana_version: '1.0',
@ -119,8 +128,7 @@ test('Tracks predefined operations', () => {
test('Tracks grouped queries', () => { test('Tracks grouped queries', () => {
trackGroupedQueries({ data: [] }, requests, originalRequest, new Date()); trackGroupedQueries({ data: [] }, requests, originalRequest, new Date());
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', { expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
app: 'explore',
bytes_processed: 0, bytes_processed: 0,
editor_mode: 'builder', editor_mode: 'builder',
grafana_version: '1.0', grafana_version: '1.0',
@ -145,8 +153,7 @@ test('Tracks grouped queries', () => {
predefined_operations_applied: 'n/a', predefined_operations_applied: 'n/a',
}); });
expect(reportInteraction).toHaveBeenCalledWith('grafana_loki_query_executed', { expect(reportInteraction).toHaveBeenCalledWith('grafana_explore_loki_query_executed', {
app: 'explore',
bytes_processed: 0, bytes_processed: 0,
editor_mode: 'builder', editor_mode: 'builder',
grafana_version: '1.0', grafana_version: '1.0',

View File

@ -7,6 +7,7 @@ import {
REF_ID_DATA_SAMPLES, REF_ID_DATA_SAMPLES,
REF_ID_STARTER_LOG_ROW_CONTEXT, REF_ID_STARTER_LOG_ROW_CONTEXT,
REF_ID_STARTER_LOG_VOLUME, REF_ID_STARTER_LOG_VOLUME,
REF_ID_STARTER_LOG_SAMPLE,
} from './datasource'; } from './datasource';
import pluginJson from './plugin.json'; import pluginJson from './plugin.json';
import { getNormalizedLokiQuery, isLogsQuery, obfuscate } from './queryUtils'; import { getNormalizedLokiQuery, isLogsQuery, obfuscate } from './queryUtils';
@ -127,9 +128,15 @@ const isQueryWithChangedLegend = (query: LokiQuery): boolean => {
}; };
const shouldNotReportBasedOnRefId = (refId: string): 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 true;
} }
return false; return false;
@ -157,7 +164,7 @@ export function trackQuery(
// We only want to track usage for these specific apps // We only want to track usage for these specific apps
const { app, targets: queries } = request; const { app, targets: queries } = request;
if (app === CoreApp.Dashboard || app === CoreApp.PanelViewer) { if (app !== CoreApp.Explore) {
return; return;
} }
@ -168,8 +175,7 @@ export function trackQuery(
return; return;
} }
reportInteraction('grafana_loki_query_executed', { reportInteraction('grafana_explore_loki_query_executed', {
app,
grafana_version: config.buildInfo.version, grafana_version: config.buildInfo.version,
editor_mode: query.editorMode, editor_mode: query.editorMode,
has_data: response.data.some((frame) => frame.length > 0), has_data: response.data.some((frame) => frame.length > 0),