|
1 | | -import { Query, URIRef } from '../korrel8r/types'; |
2 | 1 | import { MetricDomain } from '../korrel8r/metric'; |
| 2 | +import { Query, URIRef } from '../korrel8r/types'; |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Bad deployment is the suggested deployment from korrel8r to show its functionality within the |
6 | 6 | * logging plugin. https://korrel8r.github.io/korrel8r/#troubleshooting-no-related-logs |
7 | 7 | * |
8 | 8 | */ |
9 | | -describe('Test MetricNode Parsing', () => { |
10 | | - it('Query => URL => Query', () => { |
11 | | - const query = |
12 | | - 'metric:metric:max_over_time(kube_pod_container_status_waiting_reason{job="kube-state-metrics",namespace=~"(openshift-.*|kube-.*|default)",reason="CrashLoopBackOff"}[5m]) <= 1'; |
13 | | - const expectedKorrel8rURL = |
14 | | - 'monitoring/query-browser?query0=max_over_time(kube_pod_container_status_waiting_reason{job="kube-state-metrics",namespace=~"(openshift-.*|kube-.*|default)",reason="CrashLoopBackOff"}[5m]) <= 1'; |
15 | | - const d = new MetricDomain(); |
16 | | - const actualKorrel8rURL = d.queryToLink(Query.parse(query)); |
17 | | - expect(actualKorrel8rURL).toEqual(expectedKorrel8rURL); |
18 | | - expect(d.linkToQuery(new URIRef(actualKorrel8rURL))).toEqual(Query.parse(query)); |
19 | | - }); |
| 9 | +describe('metric', () => { |
| 10 | + const metric = new MetricDomain() |
| 11 | + |
| 12 | + describe('query-link round trip', () => { |
| 13 | + it.each([ |
| 14 | + { |
| 15 | + query: 'metric:metric:max_over_time(kube_pod_container_status_waiting_reason{job="kube-state-metrics",namespace=~"(openshift-.*|kube-.*|default)",reason="CrashLoopBackOff"}[5m]) <= 1', |
| 16 | + link: 'monitoring/query-browser?query0=max_over_time%28kube_pod_container_status_waiting_reason%7Bjob%3D%22kube-state-metrics%22%2Cnamespace%3D%7E%22%28openshift-.*%7Ckube-.*%7Cdefault%29%22%2Creason%3D%22CrashLoopBackOff%22%7D%5B5m%5D%29+%3C%3D+1' |
| 17 | + }, |
| 18 | + { |
| 19 | + // Verify issue: https://github.com/openshift/troubleshooting-panel-console-plugin/issues/127 |
| 20 | + query: 'metric:metric:(1 - sum(node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes and on (instance) label_replace(kube_node_role{role="master"}, "instance", "$1", "node", "(.+)")) / sum(node_memory_MemTotal_bytes and on (instance) label_replace(kube_node_role{role="master"}, "instance", "$1", "node", "(.+)"))) * 100 > 60', |
| 21 | + link: 'monitoring/query-browser?query0=%281+-+sum%28node_memory_MemFree_bytes+%2B+node_memory_Buffers_bytes+%2B+node_memory_Cached_bytes+and+on+%28instance%29+label_replace%28kube_node_role%7Brole%3D%22master%22%7D%2C+%22instance%22%2C+%22%241%22%2C+%22node%22%2C+%22%28.%2B%29%22%29%29+%2F+sum%28node_memory_MemTotal_bytes+and+on+%28instance%29+label_replace%28kube_node_role%7Brole%3D%22master%22%7D%2C+%22instance%22%2C+%22%241%22%2C+%22node%22%2C+%22%28.%2B%29%22%29%29%29+*+100+%3E+60' |
| 22 | + }, |
| 23 | + ])('', ({ query, link }) => { |
| 24 | + const q = Query.parse(query) |
| 25 | + expect(metric.queryToLink(q).toString()).toEqual(link) |
| 26 | + expect(metric.linkToQuery(new URIRef(link))).toEqual(q); |
| 27 | + }) |
20 | 28 |
|
21 | | - it('URL => Query => URL', () => { |
22 | | - const url = |
23 | | - 'monitoring/query-browser?query0=max_over_time(kube_pod_container_status_waiting_reason{job="kube-state-metrics",namespace=~"(openshift-.*|kube-.*|default)",reason="CrashLoopBackOff"}[5m]) <= 1'; |
24 | | - const expectedQuery = |
25 | | - 'metric:metric:max_over_time(kube_pod_container_status_waiting_reason{job="kube-state-metrics",namespace=~"(openshift-.*|kube-.*|default)",reason="CrashLoopBackOff"}[5m]) <= 1'; |
26 | | - const d = new MetricDomain(); |
27 | | - const actualQuery = d.linkToQuery(new URIRef(url)); |
28 | | - expect(actualQuery).toEqual(Query.parse(expectedQuery)); |
29 | | - expect(d.queryToLink(Query.parse(expectedQuery))).toEqual(url); |
30 | 29 | }); |
31 | 30 |
|
32 | | - describe('Test url to query parsing with expected errors', () => { |
33 | | - [ |
| 31 | + describe('linkToQuery errors', () => { |
| 32 | + it.each([ |
34 | 33 | { |
35 | 34 | url: 'foobar', |
36 | | - expected: new TypeError('domain metric: invalid link: foobar'), |
| 35 | + error: new TypeError('domain metric: invalid link: foobar'), |
37 | 36 | }, |
38 | 37 | { |
39 | 38 | url: 'monitoring/query-browser', |
40 | | - expected: 'domain metric: invalid link: monitoring/query-browser', |
| 39 | + error: 'domain metric: invalid link: monitoring/query-browser', |
41 | 40 | }, |
42 | | - ].forEach(({ url, expected }) => { |
43 | | - it(`converts from ${url}`, () => { |
44 | | - expect(() => new MetricDomain().linkToQuery(new URIRef(url))).toThrow(expected); |
45 | | - }); |
| 41 | + ])('$url', ({ url, error }) => { |
| 42 | + expect(() => metric.linkToQuery(new URIRef(url))).toThrow(error); |
| 43 | + |
46 | 44 | }); |
47 | 45 | }); |
48 | 46 |
|
49 | | - it('Test query to url parsing with expected errors', () => { |
50 | | - [ |
| 47 | + describe('queryToLink errors', () => { |
| 48 | + it.each([ |
51 | 49 | { |
52 | 50 | query: 'wrongdomain:metric:foo', |
53 | | - expected: 'domain metric: invalid query, wrong domain: wrongdomain:metric:foo', |
| 51 | + error: 'domain metric: invalid query, wrong domain: wrongdomain:metric:foo', |
54 | 52 | }, |
55 | 53 | { |
56 | 54 | query: 'metric:badclass:foo', |
57 | | - expected: 'domain metric: invalid class: badclass', |
| 55 | + error: 'domain metric: invalid class: badclass', |
58 | 56 | }, |
59 | | - ].forEach(({ query, expected }) => { |
60 | | - expect(() => new MetricDomain().queryToLink(Query.parse(query))).toThrow(expected); |
| 57 | + ])('$query', ({ query, error }) => { |
| 58 | + expect(() => metric.queryToLink(Query.parse(query))).toThrow(error); |
61 | 59 | }); |
62 | 60 | }); |
63 | 61 | }); |
0 commit comments