in ambari-metrics-grafana/ambari-metrics/query_ctrl.ts [42:122]
constructor($scope, $injector) {
super($scope, $injector);
this.errors = this.validateTarget(this.target);
this.aggregators = ['none','avg', 'sum', 'min', 'max'];
this.precisions = ['default','seconds', 'minutes', 'hours', 'days'];
this.transforms = ['none','diff','rate'];
this.seriesAggregators = ['none', 'avg', 'sum', 'min', 'max'];
if (!this.target.aggregator) {
this.target.aggregator = 'avg';
}
this.precisionInit = function () {
if (typeof this.target.precision == 'undefined') {
this.target.precision = "default";
}
};
this.transform = function () {
if (typeof this.target.transform == 'undefined') {
this.target.transform = "none";
}
};
this.seriesAggregator = function () {
if (typeof $scope.target.seriesAggregator == 'undefined') {
this.target.seriesAggregator = "none";
}
};
$scope.$watch('target.app', function (newValue) {
if (newValue === '') {
this.target.metric = '';
this.target.hosts = '';
this.target.cluster = '';
}
});
if (!this.target.downsampleAggregator) {
this.target.downsampleAggregator = 'avg';
}
this.datasource.getAggregators().then(function(aggs) {
this.aggregators = aggs;
});
this.suggestApps = (query, callback) => {
this.datasource.suggestApps(query)
.then(this.getTextValues)
.then(callback);
};
this.suggestClusters = (query, callback) => {
this.datasource.suggestClusters(this.target.app)
.then(this.getTextValues)
.then(callback);
};
this.suggestHosts = (query, callback) => {
this.datasource.suggestHosts(this.target.app, this.target.cluster)
.then(this.getTextValues)
.then(callback);
};
this.suggestMetrics = (query, callback) => {
this.datasource.suggestMetrics(query, this.target.app)
.then(this.getTextValues)
.then(callback);
};
this.suggestTagKeys = (query, callback) => {
this.datasource.metricFindQuery('tag_names(' + this.target.metric + ')')
.then(this.getTextValues)
.then(callback);
};
this.suggestTagValues = (query, callback) => {
this.datasource.metricFindQuery('tag_values(' + this.target.metric + ',' + this.target.currentTagKey + ')')
.then(this.getTextValues)
.then(callback);
};
this.getTextValues = (metricFindResult) => {
return metricFindResult.map((value) => {return value.text });
}
}