Skip to content

Commit 67dd523

Browse files
opensearch-trigger-bot[bot]github-actions[bot]Kishore Kumaar Natarajan
authored
[BUG FIX] Enable Correct Sorting for Metrics in Query Insights Dashboard (#173) (#174)
* Bug fix Sort and added cypress for them * Updated Snapshots --------- (cherry picked from commit 3843f4f) Signed-off-by: Kishore Kumaar Natarajan <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Kishore Kumaar Natarajan <[email protected]>
1 parent d2cc77d commit 67dd523

File tree

5 files changed

+169
-220
lines changed

5 files changed

+169
-220
lines changed

cypress/e2e/1_top_queries.cy.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,32 @@ describe('Query Insights Dashboard - Dynamic Columns with Stubbed Top Queries',
142142
cy.wait('@getTopQueries');
143143
});
144144

145+
const testMetricSorting = (columnLabel, columnIndex) => {
146+
cy.get('.euiTableHeaderCell').contains(columnLabel).click();
147+
cy.wait(1000);
148+
149+
cy.get('.euiTableRow').then(($rows) => {
150+
const values = [...$rows].map(($row) => {
151+
const rawText = Cypress.$($row).find('td').eq(columnIndex).text().trim();
152+
return parseFloat(rawText.replace(/[^\d.]/g, '')); // remove 'ms'/'B'
153+
});
154+
const sortedAsc = [...values].sort((a, b) => a - b);
155+
expect(values).to.deep.equal(sortedAsc);
156+
});
157+
158+
cy.get('.euiTableHeaderCell').contains(columnLabel).click();
159+
cy.wait(1000);
160+
161+
cy.get('.euiTableRow').then(($rows) => {
162+
const values = [...$rows].map(($row) => {
163+
const rawText = Cypress.$($row).find('td').eq(columnIndex).text().trim();
164+
return parseFloat(rawText.replace(/[^\d.]/g, ''));
165+
});
166+
const sortedDesc = [...values].sort((a, b) => b - a);
167+
expect(values).to.deep.equal(sortedDesc);
168+
});
169+
};
170+
145171
it('should render only individual query-related headers when NONE filter is applied', () => {
146172
cy.wait(1000);
147173
cy.get('.euiFilterButton').contains('Type').click();
@@ -161,12 +187,16 @@ describe('Query Insights Dashboard - Dynamic Columns with Stubbed Top Queries',
161187
'Total Shards',
162188
];
163189

164-
//cy.get('.euiTableHeaderCell').should('have.length', expectedHeaders.length);
190+
cy.get('.euiTableHeaderCell').should('have.length', expectedHeaders.length);
165191

166192
cy.get('.euiTableHeaderCell').should(($headers) => {
167193
const actualHeaders = $headers.map((index, el) => Cypress.$(el).text().trim()).get();
168194
expect(actualHeaders).to.deep.equal(expectedHeaders);
169195
});
196+
testMetricSorting('Timestamp', 2);
197+
testMetricSorting('Latency', 3);
198+
testMetricSorting('CPU Time', 4);
199+
testMetricSorting('Memory Usage', 5);
170200
});
171201

172202
it('should render only group-related headers in the correct order when SIMILARITY filter is applied', () => {
@@ -187,6 +217,10 @@ describe('Query Insights Dashboard - Dynamic Columns with Stubbed Top Queries',
187217
const actualHeaders = $headers.map((index, el) => Cypress.$(el).text().trim()).get();
188218
expect(actualHeaders).to.deep.equal(expectedHeaders);
189219
});
220+
testMetricSorting('Query Count', 2);
221+
testMetricSorting('Average Latency', 3);
222+
testMetricSorting('Average CPU Time', 4);
223+
testMetricSorting('Average Memory Usage', 5);
190224
});
191225
it('should display both query and group data with proper headers when both are selected', () => {
192226
cy.get('.euiFilterButton').contains('Type').click();
@@ -211,5 +245,10 @@ describe('Query Insights Dashboard - Dynamic Columns with Stubbed Top Queries',
211245
const actualHeaders = $headers.map((index, el) => Cypress.$(el).text().trim()).get();
212246
expect(actualHeaders).to.deep.equal(expectedGroupHeaders);
213247
});
248+
testMetricSorting('Query Count', 2);
249+
testMetricSorting('Timestamp', 3);
250+
testMetricSorting('Avg Latency / Latency', 4);
251+
testMetricSorting('Avg CPU Time / CPU Time', 5);
252+
testMetricSorting('Avg Memory Usage / Memory Usage', 6);
214253
});
215254
});

cypress/fixtures/stub_top_queries.json

Lines changed: 40 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -3,135 +3,77 @@
33
"response": {
44
"top_queries": [
55
{
6-
"timestamp": 1443852054000,
6+
"timestamp": 1713934974000,
77
"id": "a2e1c822-3e3c-4d1b-adb2-9f73af094b43",
88
"search_type": "query_then_fetch",
9-
"indices": [
10-
"my-index"
11-
],
9+
"indices": ["my-index"],
1210
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
1311
"group_by": "NONE",
1412
"total_shards": 1,
1513
"labels": {
1614
"X-Opaque-Id": "90eb5c3b-8448-4af3-84ce-a941eee9ed5f"
1715
},
1816
"measurements": {
19-
"cpu": {
20-
"number": 2921000,
21-
"count": 1,
22-
"aggregationType": "NONE"
23-
},
24-
"latency": {
25-
"number": 5,
26-
"count": 1,
27-
"aggregationType": "NONE"
28-
},
29-
"memory": {
30-
"number": 100840,
31-
"count": 1,
32-
"aggregationType": "NONE"
33-
}
17+
"cpu": { "number": 1340000, "count": 1, "aggregationType": "NONE" },
18+
"latency": { "number": 22, "count": 1, "aggregationType": "NONE" },
19+
"memory": { "number": 204800, "count": 1, "aggregationType": "NONE" }
3420
}
3521
},
3622
{
37-
"timestamp": 1443852054000,
23+
"timestamp": 1713934989000,
3824
"id": "130a5d36-615e-43e8-ad99-e1b90d527f44",
3925
"search_type": "query_then_fetch",
40-
"indices": [
41-
".kibana"
42-
],
26+
"indices": [".kibana"],
4327
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
4428
"group_by": "SIMILARITY",
4529
"total_shards": 1,
4630
"labels": {},
4731
"query_group_hashcode": "2219a4bb71bd0d262e6d0f5504b88537",
4832
"measurements": {
49-
"memory": {
50-
"number": 38024,
51-
"count": 1,
52-
"aggregationType": "AVERAGE"
53-
},
54-
"cpu": {
55-
"number": 2613000,
56-
"count": 1,
57-
"aggregationType": "AVERAGE"
58-
},
59-
"latency": {
60-
"number": 5,
61-
"count": 1,
62-
"aggregationType": "AVERAGE"
63-
}
33+
"memory": { "number": 58000, "count": 1, "aggregationType": "AVERAGE" },
34+
"cpu": { "number": 1780000, "count": 1, "aggregationType": "AVERAGE" },
35+
"latency": { "number": 10, "count": 1, "aggregationType": "AVERAGE" }
6436
}
6537
},
6638
{
67-
"timestamp": 1443852054000,
39+
"timestamp": 1713935004000,
6840
"id": "a2e1c822-3e3c-4d1b-adb2-9f73af094b43",
6941
"search_type": "query_then_fetch",
70-
"indices": [
71-
"my-index"
72-
],
42+
"indices": ["my-index"],
7343
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
7444
"group_by": "NONE",
7545
"total_shards": 1,
7646
"labels": {
7747
"X-Opaque-Id": "90eb5c3b-8448-4af3-84ce-a941eee9ed5f"
7848
},
7949
"measurements": {
80-
"memory": {
81-
"number": 100840,
82-
"count": 1,
83-
"aggregationType": "NONE"
84-
},
85-
"cpu": {
86-
"number": 2921000,
87-
"count": 1,
88-
"aggregationType": "NONE"
89-
},
90-
"latency": {
91-
"number": 5,
92-
"count": 1,
93-
"aggregationType": "NONE"
94-
}
50+
"memory": { "number": 170320, "count": 1, "aggregationType": "NONE" },
51+
"cpu": { "number": 2100000, "count": 1, "aggregationType": "NONE" },
52+
"latency": { "number": 13, "count": 1, "aggregationType": "NONE" }
9553
}
9654
},
9755
{
98-
"timestamp": 1443852054000,
56+
"timestamp": 1713935019000,
9957
"id": "7cd4c7f1-3803-4c5e-a41c-258e04f96f78",
10058
"search_type": "query_then_fetch",
101-
"indices": [
102-
"my-index"
103-
],
59+
"indices": ["my-index"],
10460
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
10561
"group_by": "NONE",
10662
"total_shards": 1,
10763
"labels": {
10864
"X-Opaque-Id": "8a936346-8d19-409c-9fe6-8b890eca1f7c"
10965
},
11066
"measurements": {
111-
"cpu": {
112-
"number": 1831000,
113-
"count": 1,
114-
"aggregationType": "NONE"
115-
},
116-
"latency": {
117-
"number": 4,
118-
"count": 1,
119-
"aggregationType": "NONE"
120-
},
121-
"memory": {
122-
"number": 65760,
123-
"count": 1,
124-
"aggregationType": "NONE"
125-
}
67+
"cpu": { "number": 990000, "count": 1, "aggregationType": "NONE" },
68+
"latency": { "number": 18, "count": 1, "aggregationType": "NONE" },
69+
"memory": { "number": 81200, "count": 1, "aggregationType": "NONE" }
12670
}
12771
},
12872
{
129-
"timestamp": 1443852054000,
73+
"timestamp": 1713935033000,
13074
"id": "76f5e51f-33f6-480c-8b20-8003abb93d19",
13175
"search_type": "query_then_fetch",
132-
"indices": [
133-
".kibana"
134-
],
76+
"indices": [".kibana"],
13577
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
13678
"group_by": "SIMILARITY",
13779
"total_shards": 1,
@@ -140,111 +82,57 @@
14082
},
14183
"query_group_hashcode": "a336f9580d5d980f7403f6d179f454eb",
14284
"measurements": {
143-
"memory": {
144-
"number": 77784,
145-
"count": 1,
146-
"aggregationType": "AVERAGE"
147-
},
148-
"cpu": {
149-
"number": 1589000,
150-
"count": 1,
151-
"aggregationType": "AVERAGE"
152-
},
153-
"latency": {
154-
"number": 2,
155-
"count": 1,
156-
"aggregationType": "AVERAGE"
157-
}
85+
"memory": { "number": 133600, "count": 1, "aggregationType": "AVERAGE" },
86+
"cpu": { "number": 990000, "count": 1, "aggregationType": "AVERAGE" },
87+
"latency": { "number": 9, "count": 1, "aggregationType": "AVERAGE" }
15888
}
15989
},
16090
{
161-
"timestamp": 1443852054000,
91+
"timestamp": 1713935048000,
16292
"id": "37d633a7-20e6-41a1-96e9-cd4806511dbf",
16393
"search_type": "query_then_fetch",
164-
"indices": [
165-
".kibana"
166-
],
94+
"indices": [".kibana"],
16795
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
16896
"group_by": "SIMILARITY",
16997
"total_shards": 1,
17098
"labels": {},
17199
"query_group_hashcode": "7cef9a399c117a0278025a89e943eebc",
172100
"measurements": {
173-
"memory": {
174-
"number": 981144,
175-
"count": 4,
176-
"aggregationType": "AVERAGE"
177-
},
178-
"cpu": {
179-
"number": 6286000,
180-
"count": 4,
181-
"aggregationType": "AVERAGE"
182-
},
183-
"latency": {
184-
"number": 2,
185-
"count": 1,
186-
"aggregationType": "NONE"
187-
}
101+
"memory": { "number": 640320, "count": 3, "aggregationType": "AVERAGE" },
102+
"cpu": { "number": 3190000, "count": 3, "aggregationType": "AVERAGE" },
103+
"latency": { "number": 6, "count": 1, "aggregationType": "NONE" }
188104
}
189105
},
190106
{
191-
"timestamp": 1443852054000,
107+
"timestamp": 1713935062000,
192108
"id": "9982b7fc-0339-47d8-b77f-8de1bda76b72",
193109
"search_type": "query_then_fetch",
194-
"indices": [
195-
".kibana"
196-
],
110+
"indices": [".kibana"],
197111
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
198112
"group_by": "SIMILARITY",
199113
"total_shards": 1,
200114
"labels": {},
201115
"query_group_hashcode": "7cef9a399c117a0278025a89e943eebc",
202116
"measurements": {
203-
"memory": {
204-
"number": 1001464,
205-
"count": 4,
206-
"aggregationType": "AVERAGE"
207-
},
208-
"cpu": {
209-
"number": 5562000,
210-
"count": 4,
211-
"aggregationType": "AVERAGE"
212-
},
213-
"latency": {
214-
"number": 7,
215-
"count": 4,
216-
"aggregationType": "AVERAGE"
217-
}
117+
"memory": { "number": 812400, "count": 4, "aggregationType": "AVERAGE" },
118+
"cpu": { "number": 2280000, "count": 4, "aggregationType": "AVERAGE" },
119+
"latency": { "number": 4, "count": 4, "aggregationType": "AVERAGE" }
218120
}
219121
},
220122
{
221-
"timestamp": 1443852054000,
123+
"timestamp": 1713935078000,
222124
"id": "d8dccf54-8dcb-4411-9fd6-977844be8fb3",
223125
"search_type": "query_then_fetch",
224-
"indices": [
225-
".kibana"
226-
],
126+
"indices": [".kibana"],
227127
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
228128
"group_by": "SIMILARITY",
229129
"total_shards": 1,
230130
"labels": {},
231131
"query_group_hashcode": "2219a4bb71bd0d262e6d0f5504b88537",
232132
"measurements": {
233-
"memory": {
234-
"number": 38024,
235-
"count": 1,
236-
"aggregationType": "AVERAGE"
237-
},
238-
"cpu": {
239-
"number": 840000,
240-
"count": 1,
241-
"aggregationType": "AVERAGE"
242-
},
243-
"latency": {
244-
"number": 1,
245-
"count": 1,
246-
"aggregationType": "NONE"
247-
}
133+
"memory": { "number": 59000, "count": 1, "aggregationType": "AVERAGE" },
134+
"cpu": { "number": 1720000, "count": 1, "aggregationType": "AVERAGE" },
135+
"latency": { "number": 11, "count": 1, "aggregationType": "NONE" }
248136
}
249137
}
250138
]

0 commit comments

Comments
 (0)