-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Console] Filter autocomplete endpoints by availability (#161781)
Closes #160160 ## Summary This PR adds functionality to the new autocomplete generation script for creating an `availability` property in the spec files that is used for filtering out endpoints that are not available in the current environment (e.g. `serverless` or `stack`). It also adds a config setting in the console plugin that specifies the current environment. This setting is also configured accordingly for serverless. **How to test** 1. Checkout the [ES specification repo](https://github.com/elastic/elasticsearch-specification) 2. Run the command with `node scripts/generate_console_definitions.js --source <ES_SPECIFICATION_REPO> --emptyDest` where `<ES_SPECIFICATION_REPO>` is the absolute path to the root of the ES specification repo 3. Start the classic Kibana and verify that Console suggests only endpoints that are available in the `stack` environment. 4. Start Kibana in any of the serverless modes and verify that Console suggests only endpoints that are available in the `serverless` environment. Here are some example endpoints that can be used for testing: | Endpoint | Available in Stack | Available in Serverless | | ------------- | ------------- | ------------- | | [POST _bulk](https://github.com/elastic/elasticsearch-specification/blob/main/specification/_global/bulk/BulkRequest.ts) | Yes | Yes | | [DELETE _security/oauth2/token](https://github.com/elastic/elasticsearch-specification/blob/main/specification/security/invalidate_token/SecurityInvalidateTokenRequest.ts) | Yes | No |
- Loading branch information
1 parent
efdc760
commit 6bc2ee2
Showing
10 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
packages/kbn-generate-console-definitions/src/generate_availability.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { SpecificationTypes } from './types'; | ||
import { generateAvailability } from './generate_availability'; | ||
|
||
describe('generateAvailability', () => { | ||
const mockEndpoint: SpecificationTypes.Endpoint = { | ||
name: 'test-endpoint', | ||
description: 'test-endpoint', | ||
docUrl: 'test-endpoint', | ||
availability: {}, | ||
request: null, | ||
requestBodyRequired: false, | ||
response: null, | ||
urls: [], | ||
}; | ||
|
||
it('converts empty availability to true', () => { | ||
const endpoint = mockEndpoint; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: true, | ||
}); | ||
}); | ||
|
||
describe('converts correctly stack visibility', function () { | ||
it('public visibility to true', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
stack: { | ||
visibility: SpecificationTypes.Visibility.public, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: true, | ||
}); | ||
}); | ||
|
||
it('private visibility to false', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
stack: { | ||
visibility: SpecificationTypes.Visibility.private, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: false, | ||
serverless: true, | ||
}); | ||
}); | ||
|
||
it('feature_flag visibility to false', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
stack: { | ||
visibility: SpecificationTypes.Visibility.feature_flag, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: false, | ||
serverless: true, | ||
}); | ||
}); | ||
|
||
it('missing visibility to true', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
stack: {}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('converts correctly serverless visibility', function () { | ||
it('public visibility to true', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
serverless: { | ||
visibility: SpecificationTypes.Visibility.public, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: true, | ||
}); | ||
}); | ||
|
||
it('private visibility to false', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
serverless: { | ||
visibility: SpecificationTypes.Visibility.private, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: false, | ||
}); | ||
}); | ||
|
||
it('feature_flag visibility to false', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
serverless: { | ||
visibility: SpecificationTypes.Visibility.feature_flag, | ||
}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: false, | ||
}); | ||
}); | ||
|
||
it('missing visibility to true', () => { | ||
const endpoint = { | ||
...mockEndpoint, | ||
availability: { | ||
serverless: {}, | ||
}, | ||
}; | ||
|
||
const availability = generateAvailability(endpoint); | ||
expect(availability).toEqual({ | ||
stack: true, | ||
serverless: true, | ||
}); | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/kbn-generate-console-definitions/src/generate_availability.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { AutocompleteAvailability } from './types'; | ||
import type { SpecificationTypes } from './types'; | ||
|
||
const DEFAULT_ENDPOINT_AVAILABILITY = true; | ||
|
||
export const generateAvailability = ( | ||
endpoint: SpecificationTypes.Endpoint | ||
): AutocompleteAvailability => { | ||
const availability: AutocompleteAvailability = { | ||
stack: DEFAULT_ENDPOINT_AVAILABILITY, | ||
serverless: DEFAULT_ENDPOINT_AVAILABILITY, | ||
}; | ||
if (endpoint.availability.stack?.visibility) { | ||
availability.stack = endpoint.availability.stack?.visibility === 'public'; | ||
} | ||
if (endpoint.availability.serverless?.visibility) { | ||
availability.serverless = endpoint.availability.serverless?.visibility === 'public'; | ||
} | ||
return availability; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters