Skip to content

Commit f0cfc91

Browse files
Merge branch 'master' into fix/searchprofiler-unmount
2 parents fffa6ab + d86b6c7 commit f0cfc91

File tree

7 files changed

+119
-73
lines changed

7 files changed

+119
-73
lines changed

src/plugins/data/public/query/filter_manager/filter_manager.test.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,15 @@ describe('filter_manager', () => {
184184
expect(updateListener.callCount).toBe(1);
185185
});
186186

187-
test('app state should accept array', async () => {
187+
test('app state should accept array and preserve order', async () => {
188188
const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
189189
const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'female');
190+
190191
filterManager.addFilters([f1]);
191192
filterManager.addFilters([f2]);
192193
const appFilters = filterManager.getAppFilters();
193194
expect(appFilters).toHaveLength(2);
194-
expect(appFilters).toEqual([f2, f1]);
195+
expect(appFilters).toEqual([f1, f2]);
195196
expect(filterManager.getGlobalFilters()).toHaveLength(0);
196197
});
197198

@@ -206,7 +207,7 @@ describe('filter_manager', () => {
206207
expect(updateListener.callCount).toBe(1);
207208
});
208209

209-
test('global state should be accept array', async () => {
210+
test('global state should be accept array and preserve order', async () => {
210211
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
211212
const f2 = getFilter(
212213
esFilters.FilterStateStore.GLOBAL_STATE,
@@ -215,11 +216,36 @@ describe('filter_manager', () => {
215216
'gender',
216217
'female'
217218
);
219+
218220
filterManager.addFilters([f1, f2]);
219221
expect(filterManager.getAppFilters()).toHaveLength(0);
220222
const globalFilters = filterManager.getGlobalFilters();
221223
expect(globalFilters).toHaveLength(2);
222-
expect(globalFilters).toEqual([f2, f1]);
224+
expect(globalFilters).toEqual([f1, f2]);
225+
});
226+
227+
test('mixed filters: global filters should stay in the beginning', async () => {
228+
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
229+
const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'female');
230+
filterManager.addFilters([f1, f2]);
231+
const filters = filterManager.getFilters();
232+
expect(filters).toHaveLength(2);
233+
expect(filters).toEqual([f1, f2]);
234+
});
235+
236+
test('mixed filters: global filters should move to the beginning', async () => {
237+
const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
238+
const f2 = getFilter(
239+
esFilters.FilterStateStore.GLOBAL_STATE,
240+
false,
241+
false,
242+
'gender',
243+
'female'
244+
);
245+
filterManager.addFilters([f1, f2]);
246+
const filters = filterManager.getFilters();
247+
expect(filters).toHaveLength(2);
248+
expect(filters).toEqual([f2, f1]);
223249
});
224250

225251
test('add multiple filters at once', async () => {

src/plugins/data/public/query/filter_manager/filter_manager.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,16 @@ export class FilterManager {
7777

7878
private handleStateUpdate(newFilters: esFilters.Filter[]) {
7979
// global filters should always be first
80+
8081
newFilters.sort(({ $state: a }: esFilters.Filter, { $state: b }: esFilters.Filter): number => {
81-
return a!.store === esFilters.FilterStateStore.GLOBAL_STATE &&
82-
b!.store !== esFilters.FilterStateStore.GLOBAL_STATE
83-
? -1
84-
: 1;
82+
if (a!.store === b!.store) {
83+
return 0;
84+
} else {
85+
return a!.store === esFilters.FilterStateStore.GLOBAL_STATE &&
86+
b!.store !== esFilters.FilterStateStore.GLOBAL_STATE
87+
? -1
88+
: 1;
89+
}
8590
});
8691

8792
const filtersUpdated = !_.isEqual(this.filters, newFilters);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Useful Github Pull Request commands
2+
3+
The following commands can be executed by writing them as comments on a pull request:
4+
5+
- `@elasticmachine merge upstream`: Will merge the upstream (eg. master or 7.x) into the branch. This is useful if a bug has been fixed upstream and the fix is necessary to pass CI checks
6+
- `retest` Re-run the tests. This is useful if a flaky test caused the build to fail
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
### Visual Studio Code
2+
3+
When using [Visual Studio Code](https://code.visualstudio.com/) with APM it's best to set up a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces) and add the `x-pack/legacy/plugins/apm` directory, the `x-pack` directory, and the root of the Kibana repository to the workspace. This makes it so you can navigate and search within APM and use the wider workspace roots when you need to widen your search.
4+
5+
#### Using the Jest extension
6+
7+
The [vscode-jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest) is a good way to run your Jest tests inside the editor.
8+
9+
Some of the benefits of using the extension over just running it in a terminal are:
10+
11+
• It shows the pass/fail of a test inline in the test file
12+
• It shows the error message in the test file if it fails
13+
• You don’t have to have the terminal process running
14+
• It can automatically update your snapshots when they change
15+
• Coverage mapping
16+
17+
The extension doesn't really work well if you're trying to use it on all of Kibana or all of X-Pack, but it works well if you configure it to run only on the files in APM.
18+
19+
If you have a workspace configured as described above you should have:
20+
21+
```json
22+
"jest.disabledWorkspaceFolders": ["kibana", "x-pack"]
23+
```
24+
25+
in your Workspace settings, and:
26+
27+
```json
28+
"jest.pathToJest": "node scripts/jest.js --testPathPattern=legacy/plugins/apm",
29+
"jest.rootPath": "../../.."
30+
```
31+
32+
in the settings for the APM folder.
33+
34+
#### Jest debugging
35+
36+
To make the [VSCode debugger](https://vscode.readthedocs.io/en/latest/editor/debugging/) work with Jest (you can set breakpoints in the code and tests and use the VSCode debugger) you'll need the [Node Debug extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug2) installed and can set up a launch configuration like:
37+
38+
```json
39+
{
40+
"type": "node",
41+
"name": "APM Jest",
42+
"request": "launch",
43+
"args": ["--runInBand", "--testPathPattern=legacy/plugins/apm"],
44+
"cwd": "${workspaceFolder}/../../..",
45+
"console": "internalConsole",
46+
"internalConsoleOptions": "openOnSessionStart",
47+
"disableOptimisticBPs": true,
48+
"program": "${workspaceFolder}/../../../scripts/jest.js",
49+
"runtimeVersion": "10.15.2"
50+
}
51+
```
52+
53+
(you'll want `runtimeVersion` to match what's in the Kibana root .nvmrc. Depending on your setup, you might be able to remove this line.)

x-pack/legacy/plugins/apm/readme.md

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ cd apm-integration-testing/
2929

3030
_Docker Compose is required_
3131

32+
### Debugging Elasticsearch queries
33+
34+
All APM api endpoints accept `_debug=true` as a query param that will result in the underlying ES query being outputted in the Kibana backend process.
35+
36+
Example:
37+
`/api/apm/services/my_service?_debug=true`
38+
3239
### Unit testing
3340

3441
Note: Run the following commands from `kibana/x-pack`.
@@ -45,10 +52,6 @@ node scripts/jest.js plugins/apm --watch
4552
node scripts/jest.js plugins/apm --updateSnapshot
4653
```
4754

48-
### Cypress E2E tests
49-
50-
See the Cypress-specific [readme.md](cypress/README.md)
51-
5255
### Linting
5356

5457
_Note: Run the following commands from `kibana/`._
@@ -65,63 +68,8 @@ yarn prettier "./x-pack/legacy/plugins/apm/**/*.{tsx,ts,js}" --write
6568
yarn eslint ./x-pack/legacy/plugins/apm --fix
6669
```
6770

68-
### Useful Github Pull Request commands
69-
70-
The following commands can be executed by writing them as comments on a pull request:
71-
72-
- `@elasticmachine merge upstream`: Will merge the upstream (eg. master or 7.x) into the branch. This is useful if a bug has been fixed upstream and the fix is necessary to pass CI checks
73-
- `retest` Re-run the tests. This is useful if a flaky test caused the build to fail
74-
75-
### Visual Studio Code
76-
77-
When using [Visual Studio Code](https://code.visualstudio.com/) with APM it's best to set up a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces) and add the `x-pack/legacy/plugins/apm` directory, the `x-pack` directory, and the root of the Kibana repository to the workspace. This makes it so you can navigate and search within APM and use the wider workspace roots when you need to widen your search.
78-
79-
#### Using the Jest extension
80-
81-
The [vscode-jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest) is a good way to run your Jest tests inside the editor.
82-
83-
Some of the benefits of using the extension over just running it in a terminal are:
84-
85-
• It shows the pass/fail of a test inline in the test file
86-
• It shows the error message in the test file if it fails
87-
• You don’t have to have the terminal process running
88-
• It can automatically update your snapshots when they change
89-
• Coverage mapping
90-
91-
The extension doesn't really work well if you're trying to use it on all of Kibana or all of X-Pack, but it works well if you configure it to run only on the files in APM.
92-
93-
If you have a workspace configured as described above you should have:
94-
95-
```json
96-
"jest.disabledWorkspaceFolders": ["kibana", "x-pack"]
97-
```
98-
99-
in your Workspace settings, and:
100-
101-
```json
102-
"jest.pathToJest": "node scripts/jest.js --testPathPattern=legacy/plugins/apm",
103-
"jest.rootPath": "../../.."
104-
```
105-
106-
in the settings for the APM folder.
107-
108-
#### Jest debugging
109-
110-
To make the [VSCode debugger](https://vscode.readthedocs.io/en/latest/editor/debugging/) work with Jest (you can set breakpoints in the code and tests and use the VSCode debugger) you'll need the [Node Debug extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug2) installed and can set up a launch configuration like:
111-
112-
```json
113-
{
114-
"type": "node",
115-
"name": "APM Jest",
116-
"request": "launch",
117-
"args": ["--runInBand", "--testPathPattern=legacy/plugins/apm"],
118-
"cwd": "${workspaceFolder}/../../..",
119-
"console": "internalConsole",
120-
"internalConsoleOptions": "openOnSessionStart",
121-
"disableOptimisticBPs": true,
122-
"program": "${workspaceFolder}/../../../scripts/jest.js",
123-
"runtimeVersion": "10.15.2"
124-
}
125-
```
71+
#### Further resources
12672

127-
(you'll want `runtimeVersion` to match what's in the Kibana root .nvmrc. Depending on your setup, you might be able to remove this line.)
73+
- [Cypress integration tests](cypress/README.md)
74+
- [VSCode setup instructions](./dev_docs/vscode_setup.md)
75+
- [Github PR commands](./dev_docs/github_commands.md)

x-pack/scripts/functional_tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ require('@kbn/test').runTestsCli([
1313
require.resolve('../test/api_integration/config_security_basic.js'),
1414
require.resolve('../test/api_integration/config.js'),
1515
require.resolve('../test/alerting_api_integration/spaces_only/config.ts'),
16-
require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'),
16+
// FLAKY: https://github.com/elastic/kibana/issues/50079
17+
// FLAKY: https://github.com/elastic/kibana/issues/50074
18+
// FLAKY: https://github.com/elastic/kibana/issues/48709
19+
// FLAKY: https://github.com/elastic/kibana/issues/50078
20+
// require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'),
1721
require.resolve('../test/plugin_api_integration/config.js'),
1822
require.resolve('../test/kerberos_api_integration/config'),
1923
require.resolve('../test/kerberos_api_integration/anonymous_access.config'),

x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export default function alertingApiIntegrationTests({
1818
const spacesService: SpacesService = getService('spaces');
1919
const esArchiver = getService('esArchiver');
2020

21-
describe('alerting api integration security and spaces enabled', function() {
21+
// FLAKY: https://github.com/elastic/kibana/issues/50079
22+
// FLAKY: https://github.com/elastic/kibana/issues/50074
23+
// FLAKY: https://github.com/elastic/kibana/issues/48709
24+
// FLAKY: https://github.com/elastic/kibana/issues/50078
25+
describe.skip('alerting api integration security and spaces enabled', function() {
2226
this.tags('ciGroup1');
2327

2428
before(async () => {

0 commit comments

Comments
 (0)