mirror of
https://github.com/grafana/grafana.git
synced 2026-02-03 20:49:50 -05:00
Elasticsearch: add tracking events for query editor type (#117281)
* tracking event for query editor type * prettier
This commit is contained in:
parent
e34341472c
commit
24cb03c591
2 changed files with 90 additions and 2 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import { DashboardLoadedEvent } from '@grafana/data';
|
||||
import { CoreApp, DataQueryRequest, DataQueryResponse, DashboardLoadedEvent } from '@grafana/data';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
|
||||
import { ElasticsearchDataQuery } from './dataquery.gen';
|
||||
import pluginJson from './plugin.json';
|
||||
import { onDashboardLoadedHandler } from './tracking';
|
||||
import { onDashboardLoadedHandler, trackQuery } from './tracking';
|
||||
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
|
|
@ -61,3 +61,90 @@ describe('onDashboardLoadedHandler', () => {
|
|||
expect(console.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('trackQuery', () => {
|
||||
beforeEach(() => {
|
||||
jest.mocked(reportInteraction).mockClear();
|
||||
});
|
||||
|
||||
test('tracks editor_type for code editor queries', () => {
|
||||
const query: ElasticsearchDataQuery = {
|
||||
refId: 'A',
|
||||
editorType: 'code',
|
||||
metrics: [{ id: '1', type: 'count' }],
|
||||
bucketAggs: [],
|
||||
};
|
||||
|
||||
const request: DataQueryRequest<ElasticsearchDataQuery> & { targets: ElasticsearchDataQuery[] } = {
|
||||
app: CoreApp.Explore,
|
||||
targets: [query],
|
||||
} as DataQueryRequest<ElasticsearchDataQuery>;
|
||||
|
||||
const response: DataQueryResponse = {
|
||||
data: [{ length: 1 }],
|
||||
};
|
||||
|
||||
trackQuery(response, request, new Date());
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith(
|
||||
'grafana_elasticsearch_query_executed',
|
||||
expect.objectContaining({
|
||||
editor_type: 'code',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('tracks editor_type as builder for builder queries', () => {
|
||||
const query: ElasticsearchDataQuery = {
|
||||
refId: 'A',
|
||||
editorType: 'builder',
|
||||
metrics: [{ id: '1', type: 'count' }],
|
||||
bucketAggs: [],
|
||||
};
|
||||
|
||||
const request: DataQueryRequest<ElasticsearchDataQuery> & { targets: ElasticsearchDataQuery[] } = {
|
||||
app: CoreApp.Explore,
|
||||
targets: [query],
|
||||
} as DataQueryRequest<ElasticsearchDataQuery>;
|
||||
|
||||
const response: DataQueryResponse = {
|
||||
data: [{ length: 1 }],
|
||||
};
|
||||
|
||||
trackQuery(response, request, new Date());
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith(
|
||||
'grafana_elasticsearch_query_executed',
|
||||
expect.objectContaining({
|
||||
editor_type: 'builder',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('defaults to builder when editor_type is not specified', () => {
|
||||
const query: ElasticsearchDataQuery = {
|
||||
refId: 'A',
|
||||
query: 'test query',
|
||||
metrics: [{ id: '1', type: 'count' }],
|
||||
bucketAggs: [],
|
||||
};
|
||||
|
||||
const request: DataQueryRequest<ElasticsearchDataQuery> & { targets: ElasticsearchDataQuery[] } = {
|
||||
app: CoreApp.Explore,
|
||||
targets: [query],
|
||||
} as DataQueryRequest<ElasticsearchDataQuery>;
|
||||
|
||||
const response: DataQueryResponse = {
|
||||
data: [{ length: 1 }],
|
||||
};
|
||||
|
||||
trackQuery(response, request, new Date());
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith(
|
||||
'grafana_elasticsearch_query_executed',
|
||||
expect.objectContaining({
|
||||
editor_type: 'builder',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ export function trackQuery(
|
|||
time_range_from: request?.range?.from?.toISOString(),
|
||||
time_range_to: request?.range?.to?.toISOString(),
|
||||
time_taken: Date.now() - startTime.getTime(),
|
||||
editor_type: query.editorType || 'builder',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue