[8.8] [SLO] Correctly wait for licensing promise to resolve on server (#157384) (#157399)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[SLO] Correctly wait for licensing promise to resolve on server
(#157384)](https://github.com/elastic/kibana/pull/157384)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Coen
Warmer","email":"coen.warmer@gmail.com"},"sourceCommit":{"committedDate":"2023-05-11T14:39:11Z","message":"[SLO]
Correctly wait for licensing promise to resolve on server
(#157384)","sha":"44a62f84a2582ba2e6f6b693c476b6ed7ac71547","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","v8.8.0","v8.9.0"],"number":157384,"url":"https://github.com/elastic/kibana/pull/157384","mergeCommit":{"message":"[SLO]
Correctly wait for licensing promise to resolve on server
(#157384)","sha":"44a62f84a2582ba2e6f6b693c476b6ed7ac71547"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157384","number":157384,"mergeCommit":{"message":"[SLO]
Correctly wait for licensing promise to resolve on server
(#157384)","sha":"44a62f84a2582ba2e6f6b693c476b6ed7ac71547"}}]}]
BACKPORT-->

Co-authored-by: Coen Warmer <coen.warmer@gmail.com>
This commit is contained in:
Kibana Machine 2023-05-11 11:46:18 -04:00 committed by GitHub
parent c77b43b78e
commit 31ff66e0d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,7 +48,8 @@ const transformGenerators: Record<IndicatorTypes, TransformGenerator> = {
};
const isLicenseAtLeastPlatinum = async (context: ObservabilityRequestHandlerContext) => {
return (await context.licensing).license.hasAtLeast('platinum');
const licensing = await context.licensing;
return licensing.license.hasAtLeast('platinum');
};
const createSLORoute = createObservabilityServerRoute({
@ -58,7 +59,9 @@ const createSLORoute = createObservabilityServerRoute({
},
params: createSLOParamsSchema,
handler: async ({ context, params, logger }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -83,7 +86,9 @@ const updateSLORoute = createObservabilityServerRoute({
},
params: updateSLOParamsSchema,
handler: async ({ context, params, logger }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -113,7 +118,9 @@ const deleteSLORoute = createObservabilityServerRoute({
logger,
dependencies: { getRulesClientWithRequest },
}) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -137,7 +144,9 @@ const getSLORoute = createObservabilityServerRoute({
},
params: getSLOParamsSchema,
handler: async ({ context, params }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -160,7 +169,9 @@ const enableSLORoute = createObservabilityServerRoute({
},
params: manageSLOParamsSchema,
handler: async ({ context, params, logger }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -184,7 +195,9 @@ const disableSLORoute = createObservabilityServerRoute({
},
params: manageSLOParamsSchema,
handler: async ({ context, params, logger }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -208,7 +221,9 @@ const findSLORoute = createObservabilityServerRoute({
},
params: findSLOParamsSchema,
handler: async ({ context, params }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
@ -231,9 +246,12 @@ const fetchHistoricalSummary = createObservabilityServerRoute({
},
params: fetchHistoricalSummaryParamsSchema,
handler: async ({ context, params }) => {
if (!isLicenseAtLeastPlatinum(context)) {
const hasCorrectLicense = await isLicenseAtLeastPlatinum(context);
if (!hasCorrectLicense) {
throw badRequest('Platinum license or higher is needed to make use of this feature.');
}
const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const repository = new KibanaSavedObjectsSLORepository(soClient);