mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12280 from dehrax/12224-elastic-response
karma to jest: 6 test files
This commit is contained in:
commit
56628996b7
@ -18,9 +18,9 @@ describe('ThresholdMapper', () => {
|
||||
};
|
||||
|
||||
var updated = ThresholdMapper.alertToGraphThresholds(panel);
|
||||
expect(updated).to.be(true);
|
||||
expect(panel.thresholds[0].op).to.be('gt');
|
||||
expect(panel.thresholds[0].value).to.be(100);
|
||||
expect(updated).toBe(true);
|
||||
expect(panel.thresholds[0].op).toBe('gt');
|
||||
expect(panel.thresholds[0].value).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
@ -39,12 +39,12 @@ describe('ThresholdMapper', () => {
|
||||
};
|
||||
|
||||
var updated = ThresholdMapper.alertToGraphThresholds(panel);
|
||||
expect(updated).to.be(true);
|
||||
expect(panel.thresholds[0].op).to.be('lt');
|
||||
expect(panel.thresholds[0].value).to.be(100);
|
||||
expect(updated).toBe(true);
|
||||
expect(panel.thresholds[0].op).toBe('lt');
|
||||
expect(panel.thresholds[0].value).toBe(100);
|
||||
|
||||
expect(panel.thresholds[1].op).to.be('gt');
|
||||
expect(panel.thresholds[1].value).to.be(200);
|
||||
expect(panel.thresholds[1].op).toBe('gt');
|
||||
expect(panel.thresholds[1].value).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
@ -63,12 +63,12 @@ describe('ThresholdMapper', () => {
|
||||
};
|
||||
|
||||
var updated = ThresholdMapper.alertToGraphThresholds(panel);
|
||||
expect(updated).to.be(true);
|
||||
expect(panel.thresholds[0].op).to.be('gt');
|
||||
expect(panel.thresholds[0].value).to.be(100);
|
||||
expect(updated).toBe(true);
|
||||
expect(panel.thresholds[0].op).toBe('gt');
|
||||
expect(panel.thresholds[0].value).toBe(100);
|
||||
|
||||
expect(panel.thresholds[1].op).to.be('lt');
|
||||
expect(panel.thresholds[1].value).to.be(200);
|
||||
expect(panel.thresholds[1].op).toBe('lt');
|
||||
expect(panel.thresholds[1].value).toBe(200);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,13 +1,12 @@
|
||||
import { describe, beforeEach, it, expect } from 'test/lib/common';
|
||||
import { ElasticResponse } from '../elastic_response';
|
||||
|
||||
describe('ElasticResponse', function() {
|
||||
describe('ElasticResponse', () => {
|
||||
var targets;
|
||||
var response;
|
||||
var result;
|
||||
|
||||
describe('simple query and count', function() {
|
||||
beforeEach(function() {
|
||||
describe('simple query and count', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -39,19 +38,19 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 1 series', function() {
|
||||
expect(result.data.length).to.be(1);
|
||||
expect(result.data[0].target).to.be('Count');
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].datapoints[0][0]).to.be(10);
|
||||
expect(result.data[0].datapoints[0][1]).to.be(1000);
|
||||
it('should return 1 series', () => {
|
||||
expect(result.data.length).toBe(1);
|
||||
expect(result.data[0].target).toBe('Count');
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].datapoints[0][0]).toBe(10);
|
||||
expect(result.data[0].datapoints[0][1]).toBe(1000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('simple query count & avg aggregation', function() {
|
||||
describe('simple query count & avg aggregation', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -85,22 +84,22 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(2);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].datapoints[0][0]).to.be(10);
|
||||
expect(result.data[0].datapoints[0][1]).to.be(1000);
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].datapoints[0][0]).toBe(10);
|
||||
expect(result.data[0].datapoints[0][1]).toBe(1000);
|
||||
|
||||
expect(result.data[1].target).to.be('Average value');
|
||||
expect(result.data[1].datapoints[0][0]).to.be(88);
|
||||
expect(result.data[1].datapoints[1][0]).to.be(99);
|
||||
expect(result.data[1].target).toBe('Average value');
|
||||
expect(result.data[1].datapoints[0][0]).toBe(88);
|
||||
expect(result.data[1].datapoints[1][0]).toBe(99);
|
||||
});
|
||||
});
|
||||
|
||||
describe('single group by query one metric', function() {
|
||||
describe('single group by query one metric', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -141,18 +140,18 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(2);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].target).to.be('server1');
|
||||
expect(result.data[1].target).to.be('server2');
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].target).toBe('server1');
|
||||
expect(result.data[1].target).toBe('server2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('single group by query two metrics', function() {
|
||||
describe('single group by query two metrics', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -199,20 +198,20 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(4);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].target).to.be('server1 Count');
|
||||
expect(result.data[1].target).to.be('server1 Average @value');
|
||||
expect(result.data[2].target).to.be('server2 Count');
|
||||
expect(result.data[3].target).to.be('server2 Average @value');
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(4);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].target).toBe('server1 Count');
|
||||
expect(result.data[1].target).toBe('server1 Average @value');
|
||||
expect(result.data[2].target).toBe('server2 Count');
|
||||
expect(result.data[3].target).toBe('server2 Average @value');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with percentiles ', function() {
|
||||
describe('with percentiles ', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -246,21 +245,21 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(2);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].target).to.be('p75');
|
||||
expect(result.data[1].target).to.be('p90');
|
||||
expect(result.data[0].datapoints[0][0]).to.be(3.3);
|
||||
expect(result.data[0].datapoints[0][1]).to.be(1000);
|
||||
expect(result.data[1].datapoints[1][0]).to.be(4.5);
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].target).toBe('p75');
|
||||
expect(result.data[1].target).toBe('p90');
|
||||
expect(result.data[0].datapoints[0][0]).toBe(3.3);
|
||||
expect(result.data[0].datapoints[0][1]).toBe(1000);
|
||||
expect(result.data[1].datapoints[1][0]).toBe(4.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with extended_stats', function() {
|
||||
describe('with extended_stats', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -322,21 +321,21 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 4 series', function() {
|
||||
expect(result.data.length).to.be(4);
|
||||
expect(result.data[0].datapoints.length).to.be(1);
|
||||
expect(result.data[0].target).to.be('server1 Max');
|
||||
expect(result.data[1].target).to.be('server1 Std Dev Upper');
|
||||
it('should return 4 series', () => {
|
||||
expect(result.data.length).toBe(4);
|
||||
expect(result.data[0].datapoints.length).toBe(1);
|
||||
expect(result.data[0].target).toBe('server1 Max');
|
||||
expect(result.data[1].target).toBe('server1 Std Dev Upper');
|
||||
|
||||
expect(result.data[0].datapoints[0][0]).to.be(10.2);
|
||||
expect(result.data[1].datapoints[0][0]).to.be(3);
|
||||
expect(result.data[0].datapoints[0][0]).toBe(10.2);
|
||||
expect(result.data[1].datapoints[0][0]).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('single group by with alias pattern', function() {
|
||||
describe('single group by with alias pattern', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -385,19 +384,19 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(3);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].target).to.be('server1 Count and {{not_exist}} server1');
|
||||
expect(result.data[1].target).to.be('server2 Count and {{not_exist}} server2');
|
||||
expect(result.data[2].target).to.be('0 Count and {{not_exist}} 0');
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(3);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].target).toBe('server1 Count and {{not_exist}} server1');
|
||||
expect(result.data[1].target).toBe('server2 Count and {{not_exist}} server2');
|
||||
expect(result.data[2].target).toBe('0 Count and {{not_exist}} 0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('histogram response', function() {
|
||||
describe('histogram response', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -420,16 +419,16 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return table with byte and count', function() {
|
||||
expect(result.data[0].rows.length).to.be(3);
|
||||
expect(result.data[0].columns).to.eql([{ text: 'bytes', filterable: true }, { text: 'Count' }]);
|
||||
it('should return table with byte and count', () => {
|
||||
expect(result.data[0].rows.length).toBe(3);
|
||||
expect(result.data[0].columns).toEqual([{ text: 'bytes', filterable: true }, { text: 'Count' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with two filters agg', function() {
|
||||
describe('with two filters agg', () => {
|
||||
var result;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -472,16 +471,16 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return 2 series', function() {
|
||||
expect(result.data.length).to.be(2);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].target).to.be('@metric:cpu');
|
||||
expect(result.data[1].target).to.be('@metric:logins.count');
|
||||
it('should return 2 series', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].target).toBe('@metric:cpu');
|
||||
expect(result.data[1].target).toBe('@metric:logins.count');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with dropfirst and last aggregation', function() {
|
||||
beforeEach(function() {
|
||||
describe('with dropfirst and last aggregation', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -528,14 +527,14 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should remove first and last value', function() {
|
||||
expect(result.data.length).to.be(2);
|
||||
expect(result.data[0].datapoints.length).to.be(1);
|
||||
it('should remove first and last value', () => {
|
||||
expect(result.data.length).toBe(2);
|
||||
expect(result.data[0].datapoints.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('No group by time', function() {
|
||||
beforeEach(function() {
|
||||
describe('No group by time', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -570,21 +569,21 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return table', function() {
|
||||
expect(result.data.length).to.be(1);
|
||||
expect(result.data[0].type).to.be('table');
|
||||
expect(result.data[0].rows.length).to.be(2);
|
||||
expect(result.data[0].rows[0][0]).to.be('server-1');
|
||||
expect(result.data[0].rows[0][1]).to.be(1000);
|
||||
expect(result.data[0].rows[0][2]).to.be(369);
|
||||
it('should return table', () => {
|
||||
expect(result.data.length).toBe(1);
|
||||
expect(result.data[0].type).toBe('table');
|
||||
expect(result.data[0].rows.length).toBe(2);
|
||||
expect(result.data[0].rows[0][0]).toBe('server-1');
|
||||
expect(result.data[0].rows[0][1]).toBe(1000);
|
||||
expect(result.data[0].rows[0][2]).toBe(369);
|
||||
|
||||
expect(result.data[0].rows[1][0]).to.be('server-2');
|
||||
expect(result.data[0].rows[1][1]).to.be(2000);
|
||||
expect(result.data[0].rows[1][0]).toBe('server-2');
|
||||
expect(result.data[0].rows[1][1]).toBe(2000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Multiple metrics of same type', function() {
|
||||
beforeEach(function() {
|
||||
describe('Multiple metrics of same type', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -615,15 +614,15 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should include field in metric name', function() {
|
||||
expect(result.data[0].type).to.be('table');
|
||||
expect(result.data[0].rows[0][1]).to.be(1000);
|
||||
expect(result.data[0].rows[0][2]).to.be(3000);
|
||||
it('should include field in metric name', () => {
|
||||
expect(result.data[0].type).toBe('table');
|
||||
expect(result.data[0].rows[0][1]).toBe(1000);
|
||||
expect(result.data[0].rows[0][2]).toBe(3000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Raw documents query', function() {
|
||||
beforeEach(function() {
|
||||
describe('Raw documents query', () => {
|
||||
beforeEach(() => {
|
||||
targets = [
|
||||
{
|
||||
refId: 'A',
|
||||
@ -657,13 +656,13 @@ describe('ElasticResponse', function() {
|
||||
result = new ElasticResponse(targets, response).getTimeSeries();
|
||||
});
|
||||
|
||||
it('should return docs', function() {
|
||||
expect(result.data.length).to.be(1);
|
||||
expect(result.data[0].type).to.be('docs');
|
||||
expect(result.data[0].total).to.be(100);
|
||||
expect(result.data[0].datapoints.length).to.be(2);
|
||||
expect(result.data[0].datapoints[0].sourceProp).to.be('asd');
|
||||
expect(result.data[0].datapoints[0].fieldProp).to.be('field');
|
||||
it('should return docs', () => {
|
||||
expect(result.data.length).toBe(1);
|
||||
expect(result.data[0].type).toBe('docs');
|
||||
expect(result.data[0].total).toBe(100);
|
||||
expect(result.data[0].datapoints.length).toBe(2);
|
||||
expect(result.data[0].datapoints[0].sourceProp).toBe('asd');
|
||||
expect(result.data[0].datapoints[0].fieldProp).toBe('field');
|
||||
});
|
||||
});
|
||||
});
|
@ -1,38 +1,37 @@
|
||||
///<amd-dependency path="test/specs/helpers" name="helpers" />
|
||||
|
||||
import { describe, it, expect } from 'test/lib/common';
|
||||
import moment from 'moment';
|
||||
import { IndexPattern } from '../index_pattern';
|
||||
|
||||
describe('IndexPattern', function() {
|
||||
describe('when getting index for today', function() {
|
||||
it('should return correct index name', function() {
|
||||
describe('IndexPattern', () => {
|
||||
describe('when getting index for today', () => {
|
||||
test('should return correct index name', () => {
|
||||
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
|
||||
var expected = 'asd-' + moment.utc().format('YYYY.MM.DD');
|
||||
|
||||
expect(pattern.getIndexForToday()).to.be(expected);
|
||||
expect(pattern.getIndexForToday()).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when getting index list for time range', function() {
|
||||
describe('no interval', function() {
|
||||
it('should return correct index', function() {
|
||||
describe('when getting index list for time range', () => {
|
||||
describe('no interval', () => {
|
||||
test('should return correct index', () => {
|
||||
var pattern = new IndexPattern('my-metrics', null);
|
||||
var from = new Date(2015, 4, 30, 1, 2, 3);
|
||||
var to = new Date(2015, 5, 1, 12, 5, 6);
|
||||
expect(pattern.getIndexList(from, to)).to.eql('my-metrics');
|
||||
expect(pattern.getIndexList(from, to)).toEqual('my-metrics');
|
||||
});
|
||||
});
|
||||
|
||||
describe('daily', function() {
|
||||
it('should return correct index list', function() {
|
||||
describe('daily', () => {
|
||||
test('should return correct index list', () => {
|
||||
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
|
||||
var from = new Date(1432940523000);
|
||||
var to = new Date(1433153106000);
|
||||
|
||||
var expected = ['asd-2015.05.29', 'asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01'];
|
||||
|
||||
expect(pattern.getIndexList(from, to)).to.eql(expected);
|
||||
expect(pattern.getIndexList(from, to)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,25 +1,24 @@
|
||||
import { describe, beforeEach, it, expect } from 'test/lib/common';
|
||||
import { ElasticQueryBuilder } from '../query_builder';
|
||||
|
||||
describe('ElasticQueryBuilder', function() {
|
||||
describe('ElasticQueryBuilder', () => {
|
||||
var builder;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
builder = new ElasticQueryBuilder({ timeField: '@timestamp' });
|
||||
});
|
||||
|
||||
it('with defaults', function() {
|
||||
it('with defaults', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ type: 'Count', id: '0' }],
|
||||
timeField: '@timestamp',
|
||||
bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
|
||||
});
|
||||
|
||||
expect(query.query.bool.filter[0].range['@timestamp'].gte).to.be('$timeFrom');
|
||||
expect(query.aggs['1'].date_histogram.extended_bounds.min).to.be('$timeFrom');
|
||||
expect(query.query.bool.filter[0].range['@timestamp'].gte).toBe('$timeFrom');
|
||||
expect(query.aggs['1'].date_histogram.extended_bounds.min).toBe('$timeFrom');
|
||||
});
|
||||
|
||||
it('with defaults on es5.x', function() {
|
||||
it('with defaults on es5.x', () => {
|
||||
var builder_5x = new ElasticQueryBuilder({
|
||||
timeField: '@timestamp',
|
||||
esVersion: 5,
|
||||
@ -31,11 +30,11 @@ describe('ElasticQueryBuilder', function() {
|
||||
bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
|
||||
});
|
||||
|
||||
expect(query.query.bool.filter[0].range['@timestamp'].gte).to.be('$timeFrom');
|
||||
expect(query.aggs['1'].date_histogram.extended_bounds.min).to.be('$timeFrom');
|
||||
expect(query.query.bool.filter[0].range['@timestamp'].gte).toBe('$timeFrom');
|
||||
expect(query.aggs['1'].date_histogram.extended_bounds.min).toBe('$timeFrom');
|
||||
});
|
||||
|
||||
it('with multiple bucket aggs', function() {
|
||||
it('with multiple bucket aggs', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ type: 'count', id: '1' }],
|
||||
timeField: '@timestamp',
|
||||
@ -45,11 +44,11 @@ describe('ElasticQueryBuilder', function() {
|
||||
],
|
||||
});
|
||||
|
||||
expect(query.aggs['2'].terms.field).to.be('@host');
|
||||
expect(query.aggs['2'].aggs['3'].date_histogram.field).to.be('@timestamp');
|
||||
expect(query.aggs['2'].terms.field).toBe('@host');
|
||||
expect(query.aggs['2'].aggs['3'].date_histogram.field).toBe('@timestamp');
|
||||
});
|
||||
|
||||
it('with select field', function() {
|
||||
it('with select field', () => {
|
||||
var query = builder.build(
|
||||
{
|
||||
metrics: [{ type: 'avg', field: '@value', id: '1' }],
|
||||
@ -60,10 +59,10 @@ describe('ElasticQueryBuilder', function() {
|
||||
);
|
||||
|
||||
var aggs = query.aggs['2'].aggs;
|
||||
expect(aggs['1'].avg.field).to.be('@value');
|
||||
expect(aggs['1'].avg.field).toBe('@value');
|
||||
});
|
||||
|
||||
it('with term agg and order by metric agg', function() {
|
||||
it('with term agg and order by metric agg', () => {
|
||||
var query = builder.build(
|
||||
{
|
||||
metrics: [{ type: 'count', id: '1' }, { type: 'avg', field: '@value', id: '5' }],
|
||||
@ -84,11 +83,11 @@ describe('ElasticQueryBuilder', function() {
|
||||
var firstLevel = query.aggs['2'];
|
||||
var secondLevel = firstLevel.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['5'].avg.field).to.be('@value');
|
||||
expect(secondLevel.aggs['5'].avg.field).to.be('@value');
|
||||
expect(firstLevel.aggs['5'].avg.field).toBe('@value');
|
||||
expect(secondLevel.aggs['5'].avg.field).toBe('@value');
|
||||
});
|
||||
|
||||
it('with metric percentiles', function() {
|
||||
it('with metric percentiles', () => {
|
||||
var query = builder.build(
|
||||
{
|
||||
metrics: [
|
||||
@ -109,11 +108,11 @@ describe('ElasticQueryBuilder', function() {
|
||||
|
||||
var firstLevel = query.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['1'].percentiles.field).to.be('@load_time');
|
||||
expect(firstLevel.aggs['1'].percentiles.percents).to.eql([1, 2, 3, 4]);
|
||||
expect(firstLevel.aggs['1'].percentiles.field).toBe('@load_time');
|
||||
expect(firstLevel.aggs['1'].percentiles.percents).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('with filters aggs', function() {
|
||||
it('with filters aggs', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ type: 'count', id: '1' }],
|
||||
timeField: '@timestamp',
|
||||
@ -129,12 +128,12 @@ describe('ElasticQueryBuilder', function() {
|
||||
],
|
||||
});
|
||||
|
||||
expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).to.be('@metric:cpu');
|
||||
expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).to.be('@metric:logins.count');
|
||||
expect(query.aggs['2'].aggs['4'].date_histogram.field).to.be('@timestamp');
|
||||
expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).toBe('@metric:cpu');
|
||||
expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).toBe('@metric:logins.count');
|
||||
expect(query.aggs['2'].aggs['4'].date_histogram.field).toBe('@timestamp');
|
||||
});
|
||||
|
||||
it('with filters aggs on es5.x', function() {
|
||||
it('with filters aggs on es5.x', () => {
|
||||
var builder_5x = new ElasticQueryBuilder({
|
||||
timeField: '@timestamp',
|
||||
esVersion: 5,
|
||||
@ -154,31 +153,31 @@ describe('ElasticQueryBuilder', function() {
|
||||
],
|
||||
});
|
||||
|
||||
expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).to.be('@metric:cpu');
|
||||
expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).to.be('@metric:logins.count');
|
||||
expect(query.aggs['2'].aggs['4'].date_histogram.field).to.be('@timestamp');
|
||||
expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).toBe('@metric:cpu');
|
||||
expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).toBe('@metric:logins.count');
|
||||
expect(query.aggs['2'].aggs['4'].date_histogram.field).toBe('@timestamp');
|
||||
});
|
||||
|
||||
it('with raw_document metric', function() {
|
||||
it('with raw_document metric', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ type: 'raw_document', id: '1', settings: {} }],
|
||||
timeField: '@timestamp',
|
||||
bucketAggs: [],
|
||||
});
|
||||
|
||||
expect(query.size).to.be(500);
|
||||
expect(query.size).toBe(500);
|
||||
});
|
||||
it('with raw_document metric size set', function() {
|
||||
it('with raw_document metric size set', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ type: 'raw_document', id: '1', settings: { size: 1337 } }],
|
||||
timeField: '@timestamp',
|
||||
bucketAggs: [],
|
||||
});
|
||||
|
||||
expect(query.size).to.be(1337);
|
||||
expect(query.size).toBe(1337);
|
||||
});
|
||||
|
||||
it('with moving average', function() {
|
||||
it('with moving average', () => {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
@ -198,12 +197,12 @@ describe('ElasticQueryBuilder', function() {
|
||||
|
||||
var firstLevel = query.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['2']).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg.buckets_path).to.be('3');
|
||||
expect(firstLevel.aggs['2']).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg.buckets_path).toBe('3');
|
||||
});
|
||||
|
||||
it('with broken moving average', function() {
|
||||
it('with broken moving average', () => {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
@ -227,13 +226,13 @@ describe('ElasticQueryBuilder', function() {
|
||||
|
||||
var firstLevel = query.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['2']).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg.buckets_path).to.be('3');
|
||||
expect(firstLevel.aggs['4']).to.be(undefined);
|
||||
expect(firstLevel.aggs['2']).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].moving_avg.buckets_path).toBe('3');
|
||||
expect(firstLevel.aggs['4']).toBe(undefined);
|
||||
});
|
||||
|
||||
it('with derivative', function() {
|
||||
it('with derivative', () => {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
@ -252,12 +251,12 @@ describe('ElasticQueryBuilder', function() {
|
||||
|
||||
var firstLevel = query.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['2']).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].derivative).not.to.be(undefined);
|
||||
expect(firstLevel.aggs['2'].derivative.buckets_path).to.be('3');
|
||||
expect(firstLevel.aggs['2']).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].derivative).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].derivative.buckets_path).toBe('3');
|
||||
});
|
||||
|
||||
it('with histogram', function() {
|
||||
it('with histogram', () => {
|
||||
var query = builder.build({
|
||||
metrics: [{ id: '1', type: 'count' }],
|
||||
bucketAggs: [
|
||||
@ -271,13 +270,13 @@ describe('ElasticQueryBuilder', function() {
|
||||
});
|
||||
|
||||
var firstLevel = query.aggs['3'];
|
||||
expect(firstLevel.histogram.field).to.be('bytes');
|
||||
expect(firstLevel.histogram.interval).to.be(10);
|
||||
expect(firstLevel.histogram.min_doc_count).to.be(2);
|
||||
expect(firstLevel.histogram.missing).to.be(5);
|
||||
expect(firstLevel.histogram.field).toBe('bytes');
|
||||
expect(firstLevel.histogram.interval).toBe(10);
|
||||
expect(firstLevel.histogram.min_doc_count).toBe(2);
|
||||
expect(firstLevel.histogram.missing).toBe(5);
|
||||
});
|
||||
|
||||
it('with adhoc filters', function() {
|
||||
it('with adhoc filters', () => {
|
||||
var query = builder.build(
|
||||
{
|
||||
metrics: [{ type: 'Count', id: '0' }],
|
||||
@ -295,12 +294,12 @@ describe('ElasticQueryBuilder', function() {
|
||||
]
|
||||
);
|
||||
|
||||
expect(query.query.bool.must[0].match_phrase['key1'].query).to.be('value1');
|
||||
expect(query.query.bool.must[1].match_phrase['key2'].query).to.be('value2');
|
||||
expect(query.query.bool.must_not[0].match_phrase['key2'].query).to.be('value2');
|
||||
expect(query.query.bool.filter[2].range['key3'].lt).to.be('value3');
|
||||
expect(query.query.bool.filter[3].range['key4'].gt).to.be('value4');
|
||||
expect(query.query.bool.filter[4].regexp['key5']).to.be('value5');
|
||||
expect(query.query.bool.filter[5].bool.must_not.regexp['key6']).to.be('value6');
|
||||
expect(query.query.bool.must[0].match_phrase['key1'].query).toBe('value1');
|
||||
expect(query.query.bool.must[1].match_phrase['key2'].query).toBe('value2');
|
||||
expect(query.query.bool.must_not[0].match_phrase['key2'].query).toBe('value2');
|
||||
expect(query.query.bool.filter[2].range['key3'].lt).toBe('value3');
|
||||
expect(query.query.bool.filter[3].range['key4'].gt).toBe('value4');
|
||||
expect(query.query.bool.filter[4].regexp['key5']).toBe('value5');
|
||||
expect(query.query.bool.filter[5].bool.must_not.regexp['key6']).toBe('value6');
|
||||
});
|
||||
});
|
@ -0,0 +1,93 @@
|
||||
import * as queryDef from '../query_def';
|
||||
|
||||
describe('ElasticQueryDef', () => {
|
||||
describe('getPipelineAggOptions', () => {
|
||||
describe('with zero targets', () => {
|
||||
var response = queryDef.getPipelineAggOptions([]);
|
||||
|
||||
test('should return zero', () => {
|
||||
expect(response.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and sum targets', () => {
|
||||
var targets = {
|
||||
metrics: [{ type: 'count', field: '@value' }, { type: 'sum', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
test('should return zero', () => {
|
||||
expect(response.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and moving average targets', () => {
|
||||
var targets = {
|
||||
metrics: [{ type: 'count', field: '@value' }, { type: 'moving_avg', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
test('should return one', () => {
|
||||
expect(response.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with derivatives targets', () => {
|
||||
var targets = {
|
||||
metrics: [{ type: 'derivative', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
test('should return zero', () => {
|
||||
expect(response.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPipelineMetric', () => {
|
||||
describe('moving_avg', () => {
|
||||
var result = queryDef.isPipelineAgg('moving_avg');
|
||||
|
||||
test('is pipe line metric', () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('count', () => {
|
||||
var result = queryDef.isPipelineAgg('count');
|
||||
|
||||
test('is not pipe line metric', () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pipeline aggs depending on esverison', () => {
|
||||
describe('using esversion undefined', () => {
|
||||
test('should not get pipeline aggs', () => {
|
||||
expect(queryDef.getMetricAggTypes(undefined).length).toBe(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 1', () => {
|
||||
test('should not get pipeline aggs', () => {
|
||||
expect(queryDef.getMetricAggTypes(1).length).toBe(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 2', () => {
|
||||
test('should get pipeline aggs', () => {
|
||||
expect(queryDef.getMetricAggTypes(2).length).toBe(11);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 5', () => {
|
||||
test('should get pipeline aggs', () => {
|
||||
expect(queryDef.getMetricAggTypes(5).length).toBe(11);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,95 +0,0 @@
|
||||
import { describe, it, expect } from 'test/lib/common';
|
||||
|
||||
import * as queryDef from '../query_def';
|
||||
|
||||
describe('ElasticQueryDef', function() {
|
||||
describe('getPipelineAggOptions', function() {
|
||||
describe('with zero targets', function() {
|
||||
var response = queryDef.getPipelineAggOptions([]);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and sum targets', function() {
|
||||
var targets = {
|
||||
metrics: [{ type: 'count', field: '@value' }, { type: 'sum', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and moving average targets', function() {
|
||||
var targets = {
|
||||
metrics: [{ type: 'count', field: '@value' }, { type: 'moving_avg', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
it('should return one', function() {
|
||||
expect(response.length).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with derivatives targets', function() {
|
||||
var targets = {
|
||||
metrics: [{ type: 'derivative', field: '@value' }],
|
||||
};
|
||||
|
||||
var response = queryDef.getPipelineAggOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPipelineMetric', function() {
|
||||
describe('moving_avg', function() {
|
||||
var result = queryDef.isPipelineAgg('moving_avg');
|
||||
|
||||
it('is pipe line metric', function() {
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('count', function() {
|
||||
var result = queryDef.isPipelineAgg('count');
|
||||
|
||||
it('is not pipe line metric', function() {
|
||||
expect(result).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pipeline aggs depending on esverison', function() {
|
||||
describe('using esversion undefined', function() {
|
||||
it('should not get pipeline aggs', function() {
|
||||
expect(queryDef.getMetricAggTypes(undefined).length).to.be(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 1', function() {
|
||||
it('should not get pipeline aggs', function() {
|
||||
expect(queryDef.getMetricAggTypes(1).length).to.be(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 2', function() {
|
||||
it('should get pipeline aggs', function() {
|
||||
expect(queryDef.getMetricAggTypes(2).length).to.be(11);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using esversion 5', function() {
|
||||
it('should get pipeline aggs', function() {
|
||||
expect(queryDef.getMetricAggTypes(5).length).to.be(11);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,4 +1,3 @@
|
||||
import { describe, it, expect } from 'test/lib/common';
|
||||
import { InfluxQueryBuilder } from '../query_builder';
|
||||
|
||||
describe('InfluxQueryBuilder', function() {
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { describe, it, expect } from '../../../../../test/lib/common';
|
||||
|
||||
import angular from 'angular';
|
||||
import TimeSeries from 'app/core/time_series2';
|
||||
import { ThresholdManager } from '../threshold_manager';
|
||||
@ -38,16 +36,16 @@ describe('ThresholdManager', function() {
|
||||
it('should add fill for threshold with fill: true', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
|
||||
expect(markings[0].yaxis.from).to.be(300);
|
||||
expect(markings[0].yaxis.to).to.be(Infinity);
|
||||
expect(markings[0].color).to.be('rgba(234, 112, 112, 0.12)');
|
||||
expect(markings[0].yaxis.from).toBe(300);
|
||||
expect(markings[0].yaxis.to).toBe(Infinity);
|
||||
expect(markings[0].color).toBe('rgba(234, 112, 112, 0.12)');
|
||||
});
|
||||
|
||||
it('should add line', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[1].yaxis.from).to.be(300);
|
||||
expect(markings[1].yaxis.to).to.be(300);
|
||||
expect(markings[1].color).to.be('rgba(237, 46, 24, 0.60)');
|
||||
expect(markings[1].yaxis.from).toBe(300);
|
||||
expect(markings[1].yaxis.to).toBe(300);
|
||||
expect(markings[1].color).toBe('rgba(237, 46, 24, 0.60)');
|
||||
});
|
||||
});
|
||||
|
||||
@ -59,14 +57,14 @@ describe('ThresholdManager', function() {
|
||||
|
||||
it('should add fill for first thresholds to next threshold', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[0].yaxis.from).to.be(200);
|
||||
expect(markings[0].yaxis.to).to.be(300);
|
||||
expect(markings[0].yaxis.from).toBe(200);
|
||||
expect(markings[0].yaxis.to).toBe(300);
|
||||
});
|
||||
|
||||
it('should add fill for last thresholds to infinity', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[1].yaxis.from).to.be(300);
|
||||
expect(markings[1].yaxis.to).to.be(Infinity);
|
||||
expect(markings[1].yaxis.from).toBe(300);
|
||||
expect(markings[1].yaxis.to).toBe(Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
@ -78,14 +76,14 @@ describe('ThresholdManager', function() {
|
||||
|
||||
it('should add fill for first thresholds to next threshold', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[0].yaxis.from).to.be(300);
|
||||
expect(markings[0].yaxis.to).to.be(200);
|
||||
expect(markings[0].yaxis.from).toBe(300);
|
||||
expect(markings[0].yaxis.to).toBe(200);
|
||||
});
|
||||
|
||||
it('should add fill for last thresholds to itself', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[1].yaxis.from).to.be(200);
|
||||
expect(markings[1].yaxis.to).to.be(200);
|
||||
expect(markings[1].yaxis.from).toBe(200);
|
||||
expect(markings[1].yaxis.to).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
@ -97,14 +95,14 @@ describe('ThresholdManager', function() {
|
||||
|
||||
it('should add fill for first thresholds to next threshold', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[0].yaxis.from).to.be(300);
|
||||
expect(markings[0].yaxis.to).to.be(Infinity);
|
||||
expect(markings[0].yaxis.from).toBe(300);
|
||||
expect(markings[0].yaxis.to).toBe(Infinity);
|
||||
});
|
||||
|
||||
it('should add fill for last thresholds to itself', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[1].yaxis.from).to.be(200);
|
||||
expect(markings[1].yaxis.to).to.be(-Infinity);
|
||||
expect(markings[1].yaxis.from).toBe(200);
|
||||
expect(markings[1].yaxis.to).toBe(-Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
@ -130,12 +128,12 @@ describe('ThresholdManager', function() {
|
||||
|
||||
it('should add first threshold for left axis', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[0].yaxis.from).to.be(100);
|
||||
expect(markings[0].yaxis.from).toBe(100);
|
||||
});
|
||||
|
||||
it('should add second threshold for right axis', function() {
|
||||
var markings = ctx.options.grid.markings;
|
||||
expect(markings[1].y2axis.from).to.be(200);
|
||||
expect(markings[1].y2axis.from).toBe(200);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user