-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.test.js
134 lines (112 loc) · 4.06 KB
/
index.test.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { p2l, prom2labels } = require('./index.js');
test('rate groupby', () => {
var promql = 'rate(foo{bar="baz"}[5m]) by (x,y)'
var result = 'rate({ __name__=\"foo\", bar=\"baz\"} | unwrap_value [300s]) by (x,y)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('sum rate groupby', () => {
var promql = 'sum(rate(foo{bar="baz"}[5m])) by (x,y)'
var result = 'sum(rate({__name__="foo", bar="baz"} | unwrap_value [300s])) by (x,y)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('rate not', () => {
var promql = 'rate({some="tag", some!="not"}[5m])'
var result = 'rate({ __name__!="", some="tag", some!="not"} | unwrap_value [300s])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('basic', () => {
var promql = 'just_some_name{}'
var result = 'first_over_time({__name__="just_some_name"} | unwrap_value [1m])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('le 300', () => {
var promql = '{le="300"}'
var result = 'first_over_time({__name__=~".*"le, ="300"} | unwrap_value [1m])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('sum rate func', () => {
var promql = 'sum(rate(traces_service_graph_request_failed_total{}[1m]))'
var result = 'sum(rate({__name__="traces_service_graph_request_failed_total"} | unwrap_value [60s])) by (__name__)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('avg sum groupby', () => {
var promql = 'avg(sum by(le) (rate(traces_service_graph_request_failed_total[1m])))'
var result = 'avg(sum(rate({__name__="traces_service_graph_request_failed_total"} | unwrap_value [60s]))) by (__name__)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('avg sum', () => {
var promql = 'avg(sum by(le) (rate(traces_service_graph_request_failed_total[1m])))'
var result = 'avg(sum(rate({__name__=\"traces_service_graph_request_failed_total\"} | unwrap_value [60s]))) by (__name__)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('histogram', () => {
var promql = 'histogram_quantile(0.95, sum(rate(traces_service_graph_request_server_seconds_bucket{}[1m])) by (le))'
var result = 'quantile_over_time(0.95, sum(rate({__name__="traces_service_graph_request_server_seconds_bucket"} | unwrap_value [60s])) by (le))'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('first_over_time', () => {
var promql = 'something{le="300"}'
var result = 'first_over_time({__name__="something", le="300"} | unwrap_value [1m])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('labels: simple', () => {
var promql = 'something'
var result = '{__name__="something"}'
var logql = prom2labels(promql)
expect(logql).toBe(result)
});
test('labels: any with tags', () => {
var promql = '{le="300", funk="ytown"}'
var result = '{__name__=~".*", le="300", funk="ytown"}'
var logql = prom2labels(promql)
expect(logql).toBe(result)
});
test('fix: absent_over_time', () => {
var promql = 'absent_over_time(cpu_percent_value [5s])'
var result = 'absent_over_time({ __name__="cpu_percent_value"} [5s])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('fix: count_over_time', () => {
var promql = 'count_over_time(cpu_percent_value[5s])'
var result = 'count_over_time({ __name__="cpu_percent_value"} [5s])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('fix: sum test, no range', () => {
var promql = 'sum(cpu_percent_value)'
var result = 'sum({ __name__="cpu_percent_value"} | unwrap_value [1m])'
var logql = p2l(promql)
expect(logql).toBe(result)
});
test('fix: sum group test, no range', () => {
var promql = 'sum by (http) (cpu_percent_value)'
var result = 'sum({ __name__="cpu_percent_value"} | unwrap_value [1m]) by (http)'
var logql = p2l(promql)
expect(logql).toBe(result)
});
/* Failing */
/*
test('fix: sum without', () => {
var promql = 'sum without (http) (cpu_percent_value)'
var result = ''
var logql = p2l(promql)
expect(logql).toBe(result)
});
*/
/* Dummy Ending */
test('test', () => {
var test = 'x'
var result = 'x'
expect(test).toBe(result)
});