mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Visualize logs in Explore (#17605)
* explore: try to use existing mode when switching datasource * elasticsearch: initial explore logs support * Elasticsearch: Adds ElasticsearchOptions type Updates tests accordingly * Elasticsearch: Adds typing to query method * Elasticsearch: Makes maxConcurrentShardRequests optional * Explore: Allows empty query for elasticsearch datasource * Elasticsearch: Unifies ElasticsearchQuery interface definition Removes check for context === 'explore' * Elasticsearch: Removes context property from ElasticsearchQuery interface Adds field property Removes metricAggs property Adds typing to metrics property * Elasticsearch: Runs default 'empty' query when 'clear all' button is pressed * Elasticsearch: Removes index property from ElasticsearchOptions interface * Elasticsearch: Removes commented code from ElasticsearchQueryField.tsx * Elasticsearch: Adds comment warning usage of for...in to elastic_response.ts * Elasticsearch: adds tests related to log queries
This commit is contained in:
committed by
kay delaney
parent
2fb45eeec8
commit
eecd8d1064
@@ -784,4 +784,94 @@ describe('ElasticResponse', () => {
|
||||
expect(result.data[2].datapoints[1][0]).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe('simple logs query and count', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
metrics: [{ type: 'count', id: '1' }],
|
||||
bucketAggs: [{ type: 'date_histogram', settings: { interval: 'auto' }, id: '2' }],
|
||||
context: 'explore',
|
||||
interval: '10s',
|
||||
isLogsQuery: true,
|
||||
key: 'Q-1561369883389-0.7611823271062786-0',
|
||||
live: false,
|
||||
maxDataPoints: 1620,
|
||||
query: '',
|
||||
timeField: '@timestamp',
|
||||
},
|
||||
];
|
||||
response = {
|
||||
responses: [
|
||||
{
|
||||
aggregations: {
|
||||
'2': {
|
||||
buckets: [
|
||||
{
|
||||
doc_count: 10,
|
||||
key: 1000,
|
||||
},
|
||||
{
|
||||
doc_count: 15,
|
||||
key: 2000,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
hits: {
|
||||
hits: [
|
||||
{
|
||||
_id: 'fdsfs',
|
||||
_type: '_doc',
|
||||
_index: 'mock-index',
|
||||
_source: {
|
||||
'@timestamp': '2019-06-24T09:51:19.765Z',
|
||||
host: 'djisaodjsoad',
|
||||
message: 'hello, i am a message',
|
||||
},
|
||||
fields: {
|
||||
'@timestamp': ['2019-06-24T09:51:19.765Z'],
|
||||
},
|
||||
},
|
||||
{
|
||||
_id: 'kdospaidopa',
|
||||
_type: '_doc',
|
||||
_index: 'mock-index',
|
||||
_source: {
|
||||
'@timestamp': '2019-06-24T09:52:19.765Z',
|
||||
host: 'dsalkdakdop',
|
||||
message: 'hello, i am also message',
|
||||
},
|
||||
fields: {
|
||||
'@timestamp': ['2019-06-24T09:52:19.765Z'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
result = new ElasticResponse(targets, response).getLogs();
|
||||
});
|
||||
|
||||
it('should return histogram aggregation and documents', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].fields).toContainEqual({ name: '@timestamp', type: 'time' });
|
||||
expect(result.data[0].fields).toContainEqual({ name: 'host', type: 'string' });
|
||||
expect(result.data[0].fields).toContainEqual({ name: 'message', type: 'string' });
|
||||
result.data[0].rows.forEach((row, i) => {
|
||||
expect(row).toContain(response.responses[0].hits.hits[i]._id);
|
||||
expect(row).toContain(response.responses[0].hits.hits[i]._type);
|
||||
expect(row).toContain(response.responses[0].hits.hits[i]._index);
|
||||
expect(row).toContain(JSON.stringify(response.responses[0].hits.hits[i]._source, undefined, 2));
|
||||
});
|
||||
|
||||
expect(result.data[1]).toHaveProperty('name', 'Count');
|
||||
response.responses[0].aggregations['2'].buckets.forEach(bucket => {
|
||||
expect(result.data[1].rows).toContainEqual([bucket.doc_count, bucket.key]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user