forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing the concept of ES capabilities (elastic#164850)
## Summary We recently got problems because some index creation settings are rejected by stateless ES, causing the whole system to fail and Kibana to terminate. We can't really use feature flags for this, given: 1. it doesn't really make sense to use manual flags for something that strictly depend on one of our dependency's capabilities 2. we're mixing the concept of "serverless" offering and "serverless" build. Atm we sometimes run "serverless" Kibana against traditional ES, meaning that the "serverless" info **cannot** be used to determine if we're connected against a default or serverless version of ES. This was something that was agreed a few weeks back, but never acted upon. ## Introducing ES capabilities This PR introduces the concept of elasticsearch "capabilities". Those capabilities are built exclusively from info coming from the ES cluster (and not by some config flag). This first implementation simply exposes a `serverless` flag, that is populated depending on the `build_flavor` field of the `info` API (`/` endpoint). The end goal would be to expose a real capabilities (e.g "what is supported") list instead. But ideally this would be provided by some ES API and not by us guessing what is supported depending on the build flavor, so for now, just exposing whether we're connected to a default of serverless ES will suffice. ### Using it to adapt some API calls during SO migration This PR also adapts the `createIndex` and `cloneIndex` migration action to use this information and change their request against ES accordingly (removing some index creation parameters that are not supported). --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
3c1e333
commit 53173f1
Showing
46 changed files
with
695 additions
and
68 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
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
58 changes: 58 additions & 0 deletions
58
packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_capabilities.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,58 @@ | ||
/* | ||
* 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 { getElasticsearchCapabilities } from './get_capabilities'; | ||
import type { ClusterInfo } from './get_cluster_info'; | ||
|
||
describe('getElasticsearchCapabilities', () => { | ||
const getClusterInfo = (parts: Partial<ClusterInfo>): ClusterInfo => ({ | ||
cluster_name: 'cluster_name', | ||
cluster_uuid: 'uuid', | ||
cluster_version: '13.42.9000', | ||
cluster_build_flavor: 'default', | ||
...parts, | ||
}); | ||
|
||
describe('capabilities.serverless', () => { | ||
it('is `true` when `build_flavor` is `serverless`', () => { | ||
expect( | ||
getElasticsearchCapabilities({ | ||
clusterInfo: getClusterInfo({ cluster_build_flavor: 'serverless' }), | ||
}) | ||
).toEqual( | ||
expect.objectContaining({ | ||
serverless: true, | ||
}) | ||
); | ||
}); | ||
|
||
it('is `false` when `build_flavor` is `default`', () => { | ||
expect( | ||
getElasticsearchCapabilities({ | ||
clusterInfo: getClusterInfo({ cluster_build_flavor: 'default' }), | ||
}) | ||
).toEqual( | ||
expect.objectContaining({ | ||
serverless: false, | ||
}) | ||
); | ||
}); | ||
|
||
it('is `false` when `build_flavor` is a random string', () => { | ||
expect( | ||
getElasticsearchCapabilities({ | ||
clusterInfo: getClusterInfo({ cluster_build_flavor: 'some totally random string' }), | ||
}) | ||
).toEqual( | ||
expect.objectContaining({ | ||
serverless: false, | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_capabilities.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,40 @@ | ||
/* | ||
* 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 { firstValueFrom } from 'rxjs'; | ||
import type { | ||
ElasticsearchCapabilities, | ||
ElasticsearchClient, | ||
} from '@kbn/core-elasticsearch-server'; | ||
import { type ClusterInfo, getClusterInfo$ } from './get_cluster_info'; | ||
|
||
const SERVERLESS_BUILD_FLAVOR = 'serverless'; | ||
|
||
export const getElasticsearchCapabilities = ({ | ||
clusterInfo, | ||
}: { | ||
clusterInfo: ClusterInfo; | ||
}): ElasticsearchCapabilities => { | ||
const buildFlavor = clusterInfo.cluster_build_flavor; | ||
|
||
return { | ||
serverless: buildFlavor === SERVERLESS_BUILD_FLAVOR, | ||
}; | ||
}; | ||
|
||
/** | ||
* Returns the capabilities for the ES cluster the provided client is connected to. | ||
* | ||
* @internal | ||
*/ | ||
export const getCapabilitiesFromClient = async ( | ||
client: ElasticsearchClient | ||
): Promise<ElasticsearchCapabilities> => { | ||
const clusterInfo = await firstValueFrom(getClusterInfo$(client)); | ||
return getElasticsearchCapabilities({ clusterInfo }); | ||
}; |
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
Oops, something went wrong.