Skip to content

Commit

Permalink
Add update slo test for serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Oct 7, 2024
1 parent 02f277e commit eaaa689
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
54 changes: 29 additions & 25 deletions x-pack/test_serverless/api_integration/services/slo_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/

import {
CreateSLOInput,
fetchHistoricalSummaryParamsSchema,
FetchHistoricalSummaryResponse,
FindSLODefinitionsResponse,
findSloDefinitionsResponseSchema,
UpdateSLOInput,
} from '@kbn/slo-schema';
import * as t from 'io-ts';
import type { RoleCredentials } from '../../shared/services';
Expand Down Expand Up @@ -40,30 +44,6 @@ export interface SloBurnRateRuleParams {
dependencies?: Dependency[];
}

interface SloParams {
id?: string;
name: string;
description: string;
indicator: {
type: 'sli.kql.custom';
params: {
index: string;
good: string;
total: string;
timestampField: string;
};
};
timeWindow: {
duration: string;
type: string;
};
budgetingMethod: string;
objective: {
target: number;
};
groupBy: string;
}

type FetchHistoricalSummaryParams = t.OutputOf<
typeof fetchHistoricalSummaryParamsSchema.props.body
>;
Expand All @@ -77,7 +57,7 @@ export function SloApiProvider({ getService }: FtrProviderContext) {
const retryTimeout = 180 * 1000;

return {
async create(slo: SloParams, roleAuthc: RoleCredentials) {
async create(slo: CreateSLOInput, roleAuthc: RoleCredentials) {
const { body } = await supertest
.post(`/api/observability/slos`)
.set(svlCommonApi.getInternalRequestHeader())
Expand All @@ -87,6 +67,19 @@ export function SloApiProvider({ getService }: FtrProviderContext) {
return body;
},

async update(
{ sloId, slo }: { sloId: string; slo: UpdateSLOInput },
roleAuthc: RoleCredentials
) {
const { body } = await supertest
.put(`/api/observability/slos/${sloId}`)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send(slo);

return body;
},

async delete({ sloId, roleAuthc }: { sloId: string; roleAuthc: RoleCredentials }) {
const response = await supertest
.delete(`/api/observability/slos/${sloId}`)
Expand All @@ -95,6 +88,16 @@ export function SloApiProvider({ getService }: FtrProviderContext) {
return response;
},

async findDefinitions(): Promise<FindSLODefinitionsResponse> {
const response = await supertest
.get(`/api/observability/slos/_definitions`)
.set(svlCommonApi.getInternalRequestHeader())
.send()
.expect(200);

return findSloDefinitionsResponseSchema.encode(response as unknown as any);
},

async fetchHistoricalSummary(
params: FetchHistoricalSummaryParams,
roleAuthc: RoleCredentials
Expand Down Expand Up @@ -193,6 +196,7 @@ export function SloApiProvider({ getService }: FtrProviderContext) {
return response;
});
},

async deleteAllSLOs() {
const response = await supertest
.get(`/api/observability/slos/_definitions`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('SLOs', function () {
loadTestFile(require.resolve('./create_slo'));
loadTestFile(require.resolve('./update_slo'));
loadTestFile(require.resolve('./delete_slo'));
loadTestFile(require.resolve('./fetch_historical_summary'));
});
Expand Down

0 comments on commit eaaa689

Please sign in to comment.