mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(elasticsearch): time field selector now works, #1034
This commit is contained in:
parent
83930ec9d1
commit
9daa3997e9
@ -5,6 +5,9 @@
|
|||||||
<i class="fa fa-warning"></i>
|
<i class="fa fa-warning"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="tight-form-item small" ng-show="target.datasource">
|
||||||
|
<em>{{target.datasource}}</em>
|
||||||
|
</li>
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a class="pointer dropdown-toggle" data-toggle="dropdown" tabindex="1">
|
<a class="pointer dropdown-toggle" data-toggle="dropdown" tabindex="1">
|
||||||
@ -48,7 +51,7 @@
|
|||||||
Time field
|
Time field
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<metric-segment segment="timeSegment" get-alt-segments="getFields()" on-value-changed="timestampChanged()"></metric-segment>
|
<metric-segment segment="timeSegment" get-alt-segments="getTimeFields()" on-value-changed="timeFieldChanged()"></metric-segment>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -6,6 +6,12 @@ function (angular) {
|
|||||||
|
|
||||||
function ElasticQueryBuilder() { }
|
function ElasticQueryBuilder() { }
|
||||||
|
|
||||||
|
ElasticQueryBuilder.prototype.getRangeFilter = function(timeField) {
|
||||||
|
var filter = {};
|
||||||
|
filter[timeField] = {"gte": "$timeFrom", "lte": "$timeTo"};
|
||||||
|
return filter;
|
||||||
|
};
|
||||||
|
|
||||||
ElasticQueryBuilder.prototype.build = function(target) {
|
ElasticQueryBuilder.prototype.build = function(target) {
|
||||||
if (target.rawQuery) {
|
if (target.rawQuery) {
|
||||||
return angular.fromJson(target.rawQuery);
|
return angular.fromJson(target.rawQuery);
|
||||||
@ -23,19 +29,7 @@ function (angular) {
|
|||||||
},
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"bool": {
|
"bool": {
|
||||||
"must": [
|
"must": [{"range": this.getRangeFilter(target.timeField)}]
|
||||||
{
|
|
||||||
"range": {
|
|
||||||
"@timestamp": {
|
|
||||||
"gte": "$timeFrom",
|
|
||||||
"lte": "$timeTo"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"must_not": [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,8 @@ function (angular, _, ElasticQueryBuilder) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.getGroupByFields = function(segment) {
|
$scope.getGroupByFields = function(segment) {
|
||||||
return $scope.datasource.metricFindQuery('fields()').then($scope.transformToSegments(false))
|
return $scope.datasource.metricFindQuery('fields()')
|
||||||
|
.then($scope.transformToSegments(false))
|
||||||
.then(function(results) {
|
.then(function(results) {
|
||||||
if (segment.type !== 'plus-button') {
|
if (segment.type !== 'plus-button') {
|
||||||
results.splice(0, 0, angular.copy($scope.removeGroupBySegment));
|
results.splice(0, 0, angular.copy($scope.removeGroupBySegment));
|
||||||
@ -153,6 +154,17 @@ function (angular, _, ElasticQueryBuilder) {
|
|||||||
.then(null, $scope.handleQueryError);
|
.then(null, $scope.handleQueryError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.getTimeFields = function() {
|
||||||
|
return $scope.datasource.metricFindQuery('fields()')
|
||||||
|
.then($scope.transformToSegments(false))
|
||||||
|
.then(null, $scope.handleQueryError);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.timeFieldChanged = function() {
|
||||||
|
$scope.target.timeField = $scope.timeSegment.value;
|
||||||
|
$scope.queryUpdated();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.groupByChanged = function(segment, index) {
|
$scope.groupByChanged = function(segment, index) {
|
||||||
if (segment.value === $scope.removeGroupBySegment.value) {
|
if (segment.value === $scope.removeGroupBySegment.value) {
|
||||||
$scope.target.groupByFields.splice(index, 1);
|
$scope.target.groupByFields.splice(index, 1);
|
||||||
|
@ -49,24 +49,18 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<input type="text" class="tight-form-clear-input span10"
|
<input type="text" class="tight-form-clear-input span10" ng-model="target.target" give-focus="target.textEditor" spellcheck='false' ng-model-onblur ng-change="get_data()" ng-show="target.textEditor"></input>
|
||||||
ng-model="target.target"
|
|
||||||
give-focus="target.textEditor"
|
|
||||||
spellcheck='false'
|
|
||||||
ng-model-onblur ng-change="get_data()"
|
|
||||||
ng-show="target.textEditor" />
|
|
||||||
|
|
||||||
<ul class="tight-form-list" role="menu" ng-hide="target.textEditor">
|
<ul class="tight-form-list" role="menu" ng-hide="target.textEditor">
|
||||||
<li ng-repeat="segment in segments" role="menuitem">
|
<li ng-repeat="segment in segments" role="menuitem">
|
||||||
<metric-segment segment="segment" get-alt-segments="getAltSegments($index)" on-value-changed="segmentValueChanged(segment, $index)"></metric-segment>
|
<metric-segment segment="segment" get-alt-segments="getAltSegments($index)" on-value-changed="segmentValueChanged(segment, $index)"></metric-segment>
|
||||||
</li>
|
</li>
|
||||||
<li ng-repeat="func in functions">
|
<li ng-repeat="func in functions">
|
||||||
<span graphite-func-editor class="tight-form-item tight-form-func">
|
<span graphite-func-editor class="tight-form-item tight-form-func">
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li class="dropdown" graphite-add-func>
|
<li class="dropdown" graphite-add-func>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,6 +9,7 @@ define([
|
|||||||
var builder = new ElasticQueryBuilder();
|
var builder = new ElasticQueryBuilder();
|
||||||
|
|
||||||
var query = builder.build({
|
var query = builder.build({
|
||||||
|
timeField: '@timestamp',
|
||||||
select: [{agg: 'Count'}],
|
select: [{agg: 'Count'}],
|
||||||
groupByFields: [],
|
groupByFields: [],
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user