forked from sirkjohannsen/grafana-datasource-datadog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_builder.js
85 lines (68 loc) · 1.93 KB
/
query_builder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
System.register(['lodash', './dfunc'], function (_export, _context) {
"use strict";
var _, dfunc;
function buildQuery(target, adhocFilters) {
var aggregation = target.aggregation,
metric = target.metric,
tags = target.tags,
functions = target.functions;
var query = aggregation + ':' + metric;
var functionInstances = getFunctionInstances(functions);
if (tags && tags.length || adhocFilters && adhocFilters.length) {
query += '{';
if (tags && tags.length) {
query += tags.join(',');
}
if (adhocFilters && adhocFilters.length) {
var adhocTags = buildAdHocFilterString(adhocFilters);
if (tags && tags.length) {
query += ',';
}
query += adhocTags;
}
query += '}';
} else {
query += '{*}';
}
if (target.as) {
query += '.' + target.as + '()';
}
var groupedFuncs = _.groupBy(functionInstances, function (func) {
if (func.def.append) {
return 'appends';
} else {
return 'wraps';
}
});
_.each(groupedFuncs.appends, function (func) {
query += '.' + func.render();
});
_.each(groupedFuncs.wraps, function (func) {
query = func.render(query);
});
return query;
}
_export('buildQuery', buildQuery);
function getFunctionInstances(functions) {
return _.map(functions, function (func) {
var f = dfunc.createFuncInstance(func.funcDef, { withDefaultParams: false });
f.params = func.params.slice();
return f;
});
}
function buildAdHocFilterString(adhocFilters) {
return adhocFilters.map(function (filter) {
return filter.key + ':' + filter.value;
}).join(',');
}
return {
setters: [function (_lodash) {
_ = _lodash.default;
}, function (_dfunc) {
dfunc = _dfunc.default;
}],
execute: function () {}
};
});
//# sourceMappingURL=query_builder.js.map