Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
26abce64
Commit
26abce64
authored
Dec 16, 2015
by
carl bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(elastic): isolate drop first and last logic
parent
d882af9f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
9 deletions
+71
-9
public/app/plugins/datasource/elasticsearch/elastic_response.js
+23
-9
public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts
+48
-0
No files found.
public/app/plugins/datasource/elasticsearch/elastic_response.js
View file @
26abce64
...
@@ -10,9 +10,8 @@ function (_, queryDef) {
...
@@ -10,9 +10,8 @@ function (_, queryDef) {
this
.
response
=
response
;
this
.
response
=
response
;
}
}
ElasticResponse
.
prototype
.
processMetrics
=
function
(
esAgg
,
target
,
seriesList
,
props
,
dropFirstLast
)
{
ElasticResponse
.
prototype
.
processMetrics
=
function
(
esAgg
,
target
,
seriesList
,
props
)
{
var
metric
,
y
,
i
,
newSeries
,
bucket
,
value
;
var
metric
,
y
,
i
,
newSeries
,
bucket
,
value
;
dropFirstLast
=
dropFirstLast
?
1
:
0
;
for
(
y
=
0
;
y
<
target
.
metrics
.
length
;
y
++
)
{
for
(
y
=
0
;
y
<
target
.
metrics
.
length
;
y
++
)
{
metric
=
target
.
metrics
[
y
];
metric
=
target
.
metrics
[
y
];
...
@@ -23,7 +22,7 @@ function (_, queryDef) {
...
@@ -23,7 +22,7 @@ function (_, queryDef) {
switch
(
metric
.
type
)
{
switch
(
metric
.
type
)
{
case
'count'
:
{
case
'count'
:
{
newSeries
=
{
datapoints
:
[],
metric
:
'count'
,
props
:
props
};
newSeries
=
{
datapoints
:
[],
metric
:
'count'
,
props
:
props
};
for
(
i
=
dropFirstLast
;
i
<
esAgg
.
buckets
.
length
-
dropFirstLast
;
i
++
)
{
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
bucket
=
esAgg
.
buckets
[
i
];
value
=
bucket
.
doc_count
;
value
=
bucket
.
doc_count
;
newSeries
.
datapoints
.
push
([
value
,
bucket
.
key
]);
newSeries
.
datapoints
.
push
([
value
,
bucket
.
key
]);
...
@@ -32,17 +31,17 @@ function (_, queryDef) {
...
@@ -32,17 +31,17 @@ function (_, queryDef) {
break
;
break
;
}
}
case
'percentiles'
:
{
case
'percentiles'
:
{
if
(
esAgg
.
buckets
.
length
-
dropFirstLast
*
2
<
=
0
)
{
if
(
esAgg
.
buckets
.
length
==
=
0
)
{
break
;
break
;
}
}
var
firstBucket
=
esAgg
.
buckets
[
dropFirstLast
];
var
firstBucket
=
esAgg
.
buckets
[
0
];
var
percentiles
=
firstBucket
[
metric
.
id
].
values
;
var
percentiles
=
firstBucket
[
metric
.
id
].
values
;
for
(
var
percentileName
in
percentiles
)
{
for
(
var
percentileName
in
percentiles
)
{
newSeries
=
{
datapoints
:
[],
metric
:
'p'
+
percentileName
,
props
:
props
,
field
:
metric
.
field
};
newSeries
=
{
datapoints
:
[],
metric
:
'p'
+
percentileName
,
props
:
props
,
field
:
metric
.
field
};
for
(
i
=
dropFirstLast
;
i
<
esAgg
.
buckets
.
length
-
dropFirstLast
;
i
++
)
{
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
bucket
=
esAgg
.
buckets
[
i
];
var
values
=
bucket
[
metric
.
id
].
values
;
var
values
=
bucket
[
metric
.
id
].
values
;
newSeries
.
datapoints
.
push
([
values
[
percentileName
],
bucket
.
key
]);
newSeries
.
datapoints
.
push
([
values
[
percentileName
],
bucket
.
key
]);
...
@@ -60,7 +59,7 @@ function (_, queryDef) {
...
@@ -60,7 +59,7 @@ function (_, queryDef) {
newSeries
=
{
datapoints
:
[],
metric
:
statName
,
props
:
props
,
field
:
metric
.
field
};
newSeries
=
{
datapoints
:
[],
metric
:
statName
,
props
:
props
,
field
:
metric
.
field
};
for
(
i
=
dropFirstLast
;
i
<
esAgg
.
buckets
.
length
-
dropFirstLast
;
i
++
)
{
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
bucket
=
esAgg
.
buckets
[
i
];
var
stats
=
bucket
[
metric
.
id
];
var
stats
=
bucket
[
metric
.
id
];
...
@@ -78,7 +77,7 @@ function (_, queryDef) {
...
@@ -78,7 +77,7 @@ function (_, queryDef) {
}
}
default
:
{
default
:
{
newSeries
=
{
datapoints
:
[],
metric
:
metric
.
type
,
field
:
metric
.
field
,
props
:
props
};
newSeries
=
{
datapoints
:
[],
metric
:
metric
.
type
,
field
:
metric
.
field
,
props
:
props
};
for
(
i
=
dropFirstLast
;
i
<
esAgg
.
buckets
.
length
-
dropFirstLast
;
i
++
)
{
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
bucket
=
esAgg
.
buckets
[
i
];
value
=
bucket
[
metric
.
id
];
value
=
bucket
[
metric
.
id
];
...
@@ -159,7 +158,7 @@ function (_, queryDef) {
...
@@ -159,7 +158,7 @@ function (_, queryDef) {
if
(
depth
===
maxDepth
)
{
if
(
depth
===
maxDepth
)
{
if
(
aggDef
.
type
===
'date_histogram'
)
{
if
(
aggDef
.
type
===
'date_histogram'
)
{
this
.
processMetrics
(
esAgg
,
target
,
seriesList
,
props
,
aggDef
.
settings
&&
aggDef
.
settings
.
dropFirstLast
);
this
.
processMetrics
(
esAgg
,
target
,
seriesList
,
props
);
}
else
{
}
else
{
this
.
processAggregationDocs
(
esAgg
,
aggDef
,
target
,
docs
,
props
);
this
.
processAggregationDocs
(
esAgg
,
aggDef
,
target
,
docs
,
props
);
}
}
...
@@ -270,6 +269,20 @@ function (_, queryDef) {
...
@@ -270,6 +269,20 @@ function (_, queryDef) {
seriesList
.
push
(
series
);
seriesList
.
push
(
series
);
};
};
ElasticResponse
.
prototype
.
dropFirstLast
=
function
(
aggregations
,
target
)
{
var
histogram
=
_
.
findWhere
(
target
.
bucketAggs
,
{
type
:
'date_histogram'
});
var
shouldDropFirstAndLast
=
histogram
&&
histogram
.
settings
&&
histogram
.
settings
.
dropFirstLast
;
if
(
shouldDropFirstAndLast
)
{
for
(
var
prop
in
aggregations
)
{
var
points
=
aggregations
[
prop
];
if
(
points
.
datapoints
.
length
>
2
)
{
points
.
datapoints
=
points
.
datapoints
.
slice
(
1
,
points
.
datapoints
.
length
-
1
);
}
}
}
};
ElasticResponse
.
prototype
.
getTimeSeries
=
function
()
{
ElasticResponse
.
prototype
.
getTimeSeries
=
function
()
{
var
seriesList
=
[];
var
seriesList
=
[];
...
@@ -290,6 +303,7 @@ function (_, queryDef) {
...
@@ -290,6 +303,7 @@ function (_, queryDef) {
var
docs
=
[];
var
docs
=
[];
this
.
processBuckets
(
aggregations
,
target
,
tmpSeriesList
,
docs
,
{},
0
);
this
.
processBuckets
(
aggregations
,
target
,
tmpSeriesList
,
docs
,
{},
0
);
this
.
dropFirstLast
(
tmpSeriesList
,
target
);
this
.
nameSeries
(
tmpSeriesList
,
target
);
this
.
nameSeries
(
tmpSeriesList
,
target
);
for
(
var
y
=
0
;
y
<
tmpSeriesList
.
length
;
y
++
)
{
for
(
var
y
=
0
;
y
<
tmpSeriesList
.
length
;
y
++
)
{
...
...
public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts
View file @
26abce64
...
@@ -411,6 +411,49 @@ describe('ElasticResponse', function() {
...
@@ -411,6 +411,49 @@ describe('ElasticResponse', function() {
});
});
});
});
describe
(
'with dropfirst and last aggregation'
,
function
()
{
beforeEach
(
function
()
{
targets
=
[{
refId
:
'A'
,
metrics
:
[{
type
:
'avg'
,
id
:
'1'
},
{
type
:
'count'
}],
bucketAggs
:
[{
id
:
'2'
,
type
:
'date_histogram'
,
field
:
'host'
,
settings
:
{
dropFirstLast
:
true
}
}],
}];
response
=
{
responses
:
[{
aggregations
:
{
"2"
:
{
buckets
:
[
{
"1"
:
{
value
:
1000
},
key
:
1
,
doc_count
:
369
,
},
{
"1"
:
{
value
:
2000
},
key
:
2
,
doc_count
:
200
,
},
{
"1"
:
{
value
:
2000
},
key
:
3
,
doc_count
:
200
,
},
]
}
}
}]
};
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
);
});
});
describe
(
'No group by time'
,
function
()
{
describe
(
'No group by time'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
targets
=
[{
targets
=
[{
...
@@ -456,6 +499,11 @@ describe('ElasticResponse', function() {
...
@@ -456,6 +499,11 @@ describe('ElasticResponse', function() {
});
});
});
});
describe
(
''
,
function
()
{
});
describe
(
'Raw documents query'
,
function
()
{
describe
(
'Raw documents query'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
targets
=
[{
refId
:
'A'
,
metrics
:
[{
type
:
'raw_document'
,
id
:
'1'
}],
bucketAggs
:
[]
}];
targets
=
[{
refId
:
'A'
,
metrics
:
[{
type
:
'raw_document'
,
id
:
'1'
}],
bucketAggs
:
[]
}];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment