Skip to content

Commit d5e1376

Browse files
authored
Update query insights cypress tests (#1806)
Signed-off-by: Siddhant Deshmukh <[email protected]>
1 parent 9454ed8 commit d5e1376

File tree

7 files changed

+483
-14
lines changed

7 files changed

+483
-14
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"ok": true,
3+
"response": {
4+
"top_queries": [
5+
{
6+
"timestamp": 1713934974000,
7+
"id": "a2e1c822-3e3c-4d1b-adb2-9f73af094b43",
8+
"search_type": "query_then_fetch",
9+
"indices": ["my-index"],
10+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
11+
"group_by": "NONE",
12+
"total_shards": 1,
13+
"labels": {
14+
"X-Opaque-Id": "90eb5c3b-8448-4af3-84ce-a941eee9ed5f"
15+
},
16+
"measurements": {
17+
"cpu": { "number": 1340000, "count": 1, "aggregationType": "NONE" },
18+
"latency": { "number": 22, "count": 1, "aggregationType": "NONE" },
19+
"memory": { "number": 204800, "count": 1, "aggregationType": "NONE" }
20+
}
21+
},
22+
{
23+
"timestamp": 1713934989000,
24+
"id": "130a5d36-615e-43e8-ad99-e1b90d527f44",
25+
"search_type": "query_then_fetch",
26+
"indices": [".kibana"],
27+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
28+
"group_by": "SIMILARITY",
29+
"total_shards": 1,
30+
"labels": {},
31+
"query_group_hashcode": "2219a4bb71bd0d262e6d0f5504b88537",
32+
"measurements": {
33+
"memory": { "number": 58000, "count": 1, "aggregationType": "AVERAGE" },
34+
"cpu": { "number": 1780000, "count": 1, "aggregationType": "AVERAGE" },
35+
"latency": { "number": 10, "count": 1, "aggregationType": "AVERAGE" }
36+
}
37+
},
38+
{
39+
"timestamp": 1713935004000,
40+
"id": "a2e1c822-3e3c-4d1b-adb2-9f73af094b43",
41+
"search_type": "query_then_fetch",
42+
"indices": ["my-index"],
43+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
44+
"group_by": "NONE",
45+
"total_shards": 1,
46+
"labels": {
47+
"X-Opaque-Id": "90eb5c3b-8448-4af3-84ce-a941eee9ed5f"
48+
},
49+
"measurements": {
50+
"memory": { "number": 170320, "count": 1, "aggregationType": "NONE" },
51+
"cpu": { "number": 2100000, "count": 1, "aggregationType": "NONE" },
52+
"latency": { "number": 13, "count": 1, "aggregationType": "NONE" }
53+
}
54+
},
55+
{
56+
"timestamp": 1713935019000,
57+
"id": "7cd4c7f1-3803-4c5e-a41c-258e04f96f78",
58+
"search_type": "query_then_fetch",
59+
"indices": ["my-index"],
60+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
61+
"group_by": "NONE",
62+
"total_shards": 1,
63+
"labels": {
64+
"X-Opaque-Id": "8a936346-8d19-409c-9fe6-8b890eca1f7c"
65+
},
66+
"measurements": {
67+
"cpu": { "number": 990000, "count": 1, "aggregationType": "NONE" },
68+
"latency": { "number": 18, "count": 1, "aggregationType": "NONE" },
69+
"memory": { "number": 81200, "count": 1, "aggregationType": "NONE" }
70+
}
71+
},
72+
{
73+
"timestamp": 1713935033000,
74+
"id": "76f5e51f-33f6-480c-8b20-8003abb93d19",
75+
"search_type": "query_then_fetch",
76+
"indices": [".kibana"],
77+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
78+
"group_by": "SIMILARITY",
79+
"total_shards": 1,
80+
"labels": {
81+
"X-Opaque-Id": "660baeb1-077b-4884-8bae-890cfe30e776"
82+
},
83+
"query_group_hashcode": "a336f9580d5d980f7403f6d179f454eb",
84+
"measurements": {
85+
"memory": { "number": 133600, "count": 1, "aggregationType": "AVERAGE" },
86+
"cpu": { "number": 990000, "count": 1, "aggregationType": "AVERAGE" },
87+
"latency": { "number": 9, "count": 1, "aggregationType": "AVERAGE" }
88+
}
89+
},
90+
{
91+
"timestamp": 1713935048000,
92+
"id": "37d633a7-20e6-41a1-96e9-cd4806511dbf",
93+
"search_type": "query_then_fetch",
94+
"indices": [".kibana"],
95+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
96+
"group_by": "SIMILARITY",
97+
"total_shards": 1,
98+
"labels": {},
99+
"query_group_hashcode": "7cef9a399c117a0278025a89e943eebc",
100+
"measurements": {
101+
"memory": { "number": 640320, "count": 3, "aggregationType": "AVERAGE" },
102+
"cpu": { "number": 3190000, "count": 3, "aggregationType": "AVERAGE" },
103+
"latency": { "number": 6, "count": 1, "aggregationType": "NONE" }
104+
}
105+
},
106+
{
107+
"timestamp": 1713935062000,
108+
"id": "9982b7fc-0339-47d8-b77f-8de1bda76b72",
109+
"search_type": "query_then_fetch",
110+
"indices": [".kibana"],
111+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
112+
"group_by": "SIMILARITY",
113+
"total_shards": 1,
114+
"labels": {},
115+
"query_group_hashcode": "7cef9a399c117a0278025a89e943eebc",
116+
"measurements": {
117+
"memory": { "number": 812400, "count": 4, "aggregationType": "AVERAGE" },
118+
"cpu": { "number": 2280000, "count": 4, "aggregationType": "AVERAGE" },
119+
"latency": { "number": 4, "count": 4, "aggregationType": "AVERAGE" }
120+
}
121+
},
122+
{
123+
"timestamp": 1713935078000,
124+
"id": "d8dccf54-8dcb-4411-9fd6-977844be8fb3",
125+
"search_type": "query_then_fetch",
126+
"indices": [".kibana"],
127+
"node_id": "UYKFun8PSAeJvkkt9cWf0w",
128+
"group_by": "SIMILARITY",
129+
"total_shards": 1,
130+
"labels": {},
131+
"query_group_hashcode": "2219a4bb71bd0d262e6d0f5504b88537",
132+
"measurements": {
133+
"memory": { "number": 59000, "count": 1, "aggregationType": "AVERAGE" },
134+
"cpu": { "number": 1720000, "count": 1, "aggregationType": "AVERAGE" },
135+
"latency": { "number": 11, "count": 1, "aggregationType": "NONE" }
136+
}
137+
}
138+
]
139+
}
140+
}

cypress/integration/plugins/query-insights-dashboards/1_top_queries.cy.js

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import { QUERY_INSIGHTS_METRICS } from '../../../utils/constants';
1010
const indexName = 'sample_index';
1111

1212
/**
13-
Helper function to clean up the environment:
14-
- Deletes the test index.
15-
- Disables the top queries features.
13+
Helper function to clean up the environment:
14+
- Deletes the test index.
15+
- Disables the top queries features.
1616
*/
1717
const clearAll = () => {
1818
cy.deleteIndexByName(indexName);
1919
cy.disableTopQueries(QUERY_INSIGHTS_METRICS.LATENCY);
2020
cy.disableTopQueries(QUERY_INSIGHTS_METRICS.CPU);
2121
cy.disableTopQueries(QUERY_INSIGHTS_METRICS.MEMORY);
22+
cy.disableGrouping();
2223
};
2324

2425
describe('Query Insights Dashboard', () => {
@@ -44,17 +45,44 @@ describe('Query Insights Dashboard', () => {
4445
* Validate the main overview page loads correctly
4546
*/
4647
it('should display the main overview page', () => {
47-
cy.get('.euiBasicTable').should('be.visible');
48-
cy.contains('Query insights - Top N queries');
48+
// Verify the page title is visible (already loaded by waitForQueryInsightsPlugin)
49+
cy.contains('Query insights - Top N queries').should('be.visible');
50+
51+
// Verify the URL is correct
4952
cy.url().should('include', '/queryInsights');
5053

51-
// should display the query table on the overview page
54+
// Verify the table is visible and has content
5255
cy.get('.euiBasicTable').should('be.visible');
5356
cy.get('.euiTableHeaderCell').should('have.length.greaterThan', 0);
54-
// should have top n queries displayed on the table
57+
58+
// Verify there are query rows in the table
5559
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
5660
});
5761

62+
/**
63+
* Validate sorting by the "Timestamp" column works correctly
64+
*/
65+
it('should sort the table by the Timestamp column', () => {
66+
// waiting for the query insights queue to drain
67+
cy.wait(10000);
68+
cy.navigateToOverview();
69+
// Click the Timestamp column header to sort
70+
cy.get('.euiTableHeaderCell').contains('Timestamp').click();
71+
cy.get('.euiTableRow')
72+
.first()
73+
.invoke('text')
74+
.then((firstRowAfterSort) => {
75+
const firstTimestamp = firstRowAfterSort.trim();
76+
cy.get('.euiTableHeaderCell').contains('Timestamp').click();
77+
cy.get('.euiTableRow')
78+
.first()
79+
.invoke('text')
80+
.then((firstRowAfterSecondSort) => {
81+
expect(firstRowAfterSecondSort.trim()).to.not.equal(firstTimestamp);
82+
});
83+
});
84+
});
85+
5886
it('should switch between tabs', () => {
5987
// Click Configuration tab
6088
cy.getElementByText('.euiTab', 'Configuration').click({ force: true });
@@ -77,16 +105,90 @@ describe('Query Insights Dashboard', () => {
77105
cy.get('.euiFieldSearch').type('random_string');
78106
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
79107
cy.get('.euiFieldSearch').clear();
80-
cy.get('.euiTableRow').should('have.length.greaterThan', 0); // Validate reset
108+
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
81109
});
82110

83111
it('should display a message when no top queries are found', () => {
84-
clearAll(); // disable top n queries
85-
// waiting for the query insights queue to drain
112+
clearAll();
86113
cy.wait(10000);
87114
cy.reload();
88115
cy.contains('No items found');
89116
});
90117

91-
after(() => clearAll());
118+
it('should paginate the query table', () => {
119+
for (let i = 0; i < 20; i++) {
120+
cy.searchOnIndex(indexName);
121+
}
122+
cy.wait(10000);
123+
cy.reload();
124+
cy.get('.euiPagination').should('be.visible');
125+
cy.get('.euiPagination__item').contains('2').click();
126+
// Verify rows on the second page
127+
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
128+
});
129+
130+
it('should get minimal details of the query using verbose=false', () => {
131+
const to = new Date().toISOString();
132+
const from = new Date(Date.now() - 60 * 60 * 1000).toISOString();
133+
134+
return cy
135+
.request({
136+
method: 'GET',
137+
url: `/api/top_queries/latency`,
138+
qs: {
139+
from: from,
140+
to: to,
141+
verbose: false,
142+
},
143+
})
144+
.then((response) => {
145+
expect(response.status).to.eq(200);
146+
expect(response.body).to.have.property('ok', true);
147+
148+
const responseData = response.body.response;
149+
expect(responseData).to.have.property('top_queries');
150+
expect(responseData.top_queries).to.be.an('array');
151+
expect(responseData.top_queries.length).to.be.greaterThan(0);
152+
153+
const firstQuery = responseData.top_queries[0];
154+
const requiredFields = [
155+
'group_by',
156+
'id',
157+
'indices',
158+
'labels',
159+
'measurements',
160+
'node_id',
161+
'search_type',
162+
'timestamp',
163+
'total_shards',
164+
];
165+
166+
expect(firstQuery).to.include.all.keys(requiredFields);
167+
const typeValidations = {
168+
group_by: 'string',
169+
id: 'string',
170+
indices: 'array',
171+
labels: 'object',
172+
measurements: 'object',
173+
node_id: 'string',
174+
search_type: 'string',
175+
timestamp: 'number',
176+
total_shards: 'number',
177+
};
178+
Object.entries(typeValidations).forEach(([field, type]) => {
179+
expect(firstQuery[field]).to.be.a(
180+
type,
181+
`${field} should be a ${type}`
182+
);
183+
});
184+
expect(firstQuery.measurements).to.have.all.keys([
185+
'cpu',
186+
'latency',
187+
'memory',
188+
]);
189+
['cpu', 'latency', 'memory'].forEach((metric) => {
190+
expect(firstQuery.measurements[metric]).to.be.an('object');
191+
});
192+
});
193+
});
92194
});

cypress/integration/plugins/query-insights-dashboards/2_query_details.cy.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,56 @@ describe('Top Queries Details Page', () => {
144144
cy.get('#latency').trigger('mousemove', { clientX: 100, clientY: 100 });
145145
});
146146

147+
it('should get complete details of the query using verbose=true for query type', () => {
148+
const to = new Date().toISOString();
149+
const from = new Date(Date.now() - 60 * 60 * 1000).toISOString();
150+
151+
return cy
152+
.request({
153+
method: 'GET',
154+
url: `/api/top_queries/latency`,
155+
qs: {
156+
from: from,
157+
to: to,
158+
verbose: true,
159+
},
160+
})
161+
.then((response) => {
162+
expect(response.status).to.eq(200);
163+
expect(response.body).to.have.property('ok', true);
164+
165+
cy.log('Response structure:', JSON.stringify(response.body, null, 2));
166+
167+
const responseData = response.body.response;
168+
expect(responseData).to.have.property('top_queries');
169+
expect(responseData.top_queries).to.be.an('array');
170+
expect(responseData.top_queries.length).to.be.greaterThan(0);
171+
172+
const firstQuery = responseData.top_queries[0];
173+
expect(firstQuery).to.include.all.keys([
174+
'group_by',
175+
'id',
176+
'indices',
177+
'labels',
178+
'measurements',
179+
'node_id',
180+
'phase_latency_map',
181+
'search_type',
182+
'source',
183+
'task_resource_usages',
184+
'timestamp',
185+
'total_shards',
186+
]);
187+
188+
expect(firstQuery.group_by).to.equal('NONE');
189+
expect(firstQuery.indices).to.be.an('array');
190+
expect(firstQuery.measurements).to.have.all.keys([
191+
'cpu',
192+
'latency',
193+
'memory',
194+
]);
195+
});
196+
});
197+
147198
after(() => clearAll());
148199
});

0 commit comments

Comments
 (0)