Add get alerts API and fix some tests (#77)
* update and sync swagger * fix
This commit is contained in:
Родитель
f91e92fedd
Коммит
a23bac9c6e
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { IPAICluster, IPAIClusterInfo } from '@api/v2';
|
||||
import { Util } from '@pai/commom/util';
|
||||
|
||||
import { OpenPAIBaseClient } from './baseClient';
|
||||
|
||||
/**
|
||||
* OpenPAI Api client.
|
||||
*/
|
||||
export class AlertClient extends OpenPAIBaseClient {
|
||||
constructor(cluster: IPAICluster) {
|
||||
super(cluster);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get OpenPAI cluster info.
|
||||
*/
|
||||
public async getAlerts(): Promise<IPAIClusterInfo> {
|
||||
const url: string = Util.fixUrl(
|
||||
`${this.cluster.rest_server_uri}/api/v2/alerts`,
|
||||
this.cluster.https
|
||||
);
|
||||
return await this.httpClient.get(url);
|
||||
}
|
||||
}
|
|
@ -13,10 +13,13 @@ info:
|
|||
Version 2.2.0: add get task status api; add jobAttempId filter to job status api and extend job detail schema
|
||||
Version 2.2.1: a user can add/delete tags to/from his/her own jobs
|
||||
version 2.2.2: add get task logs api
|
||||
version 2.2.3: set .jobStatus.appId nullable in get jobAttempt schema
|
||||
version 2.2.4: support sorting by completionTime in get the list of jobs
|
||||
version 2.2.5: add alert related api
|
||||
license:
|
||||
name: MIT License
|
||||
url: "https://github.com/microsoft/pai/blob/master/LICENSE"
|
||||
version: 2.2.0
|
||||
version: 2.2.5
|
||||
externalDocs:
|
||||
description: Find out more about OpenPAI
|
||||
url: "https://github.com/microsoft/pai"
|
||||
|
@ -39,6 +42,8 @@ tags:
|
|||
description: API endpoint for storage
|
||||
- name: job history
|
||||
description: API endpoint for job history
|
||||
- name: alert
|
||||
description: API endpoint for alert
|
||||
- name: kubernetes
|
||||
description: API endpoint for kubernetes info
|
||||
paths:
|
||||
|
@ -515,7 +520,6 @@ paths:
|
|||
summary: Get a user's data.
|
||||
description: >-
|
||||
Get a user's data.
|
||||
Only allowed in basic mode
|
||||
operationId: getUser
|
||||
security:
|
||||
- bearerAuth: []
|
||||
|
@ -725,6 +729,8 @@ paths:
|
|||
description: description
|
||||
externalName: externalName
|
||||
extension: {}
|
||||
"401":
|
||||
$ref: "#/components/responses/UnauthorizedUserError"
|
||||
"500":
|
||||
$ref: "#/components/responses/UnknownError"
|
||||
post:
|
||||
|
@ -930,6 +936,8 @@ paths:
|
|||
clusterAdmin: false
|
||||
"401":
|
||||
$ref: "#/components/responses/UnauthorizedUserError"
|
||||
"403":
|
||||
$ref: "#/components/responses/ForbiddenUserError"
|
||||
"500":
|
||||
$ref: "#/components/responses/UnknownError"
|
||||
/api/v2/virtual-clusters:
|
||||
|
@ -1153,7 +1161,10 @@ paths:
|
|||
type: number
|
||||
- name: order
|
||||
in: query
|
||||
description: 'order of job list. It follows the format <field>,<ASC|DESC>, default value is "submissionTime,DESC". Available fields include: jobName, submissionTime, username, vc, retries, totalTaskNumber, totalGpuNumber, state'
|
||||
description: 'order of job list.
|
||||
It follows the format <field>,<ASC|DESC>, default value is "submissionTime,DESC".
|
||||
Available fields include: jobName, submissionTime, username, vc, retries, totalTaskNumber, totalGpuNumber, state, completionTime.
|
||||
CompletionTime maybe null for some jobs, these jobs will be returned at the end of the list when sorting by ASC order & at the beginning when sorting by DESC order.'
|
||||
schema:
|
||||
type: string
|
||||
- name: withTotalCount
|
||||
|
@ -1233,7 +1244,7 @@ paths:
|
|||
name: task role name
|
||||
taskStatuses:
|
||||
- taskIndex: 0
|
||||
taskUid: 421
|
||||
taskUid: e0235258-0c4b-11eb-b396-96ba8c8049b4
|
||||
taskState: SUCCEEDED
|
||||
attemptId: 0
|
||||
attemptState: SUCCEEDED
|
||||
|
@ -1288,7 +1299,7 @@ paths:
|
|||
name: task role name
|
||||
taskStatuses:
|
||||
- taskIndex: 0
|
||||
taskUid: 421
|
||||
taskUid: e0235258-0c4b-11eb-b396-96ba8c8049b4
|
||||
taskState: SUCCEEDED
|
||||
attemptId: 0
|
||||
attemptState: SUCCEEDED
|
||||
|
@ -1849,6 +1860,28 @@ paths:
|
|||
$ref: "#/components/responses/UnauthorizedUserError"
|
||||
"403":
|
||||
$ref: "#/components/responses/ForbiddenUserError"
|
||||
/api/v2/alerts:
|
||||
get:
|
||||
tags:
|
||||
- alert
|
||||
summary: Get related alerts.
|
||||
description: Get related alerts. For admin users, return all the firing alerts; Return only the alerts related to the user's jobs for normal users.
|
||||
operationId: getAlerts
|
||||
security:
|
||||
- bearerAuth: []
|
||||
responses:
|
||||
"200":
|
||||
description: Succeeded
|
||||
content:
|
||||
application/json:
|
||||
example:
|
||||
- Please refer to Prometheus Alerts API:
|
||||
- >-
|
||||
https://prometheus.io/docs/prometheus/latest/querying/api/#alerts
|
||||
"401":
|
||||
$ref: "#/components/responses/UnauthorizedUserError"
|
||||
"500":
|
||||
$ref: "#/components/responses/UnknownError"
|
||||
/api/v2/kubernetes/pods:
|
||||
get:
|
||||
tags:
|
||||
|
@ -2293,6 +2326,7 @@ components:
|
|||
type: string
|
||||
appId:
|
||||
type: string
|
||||
nullable: true
|
||||
description: unique id for the job
|
||||
appCreatedTime:
|
||||
type: integer
|
||||
|
@ -2426,7 +2460,7 @@ components:
|
|||
type: integer
|
||||
description: task index
|
||||
taskUid:
|
||||
type: integer
|
||||
type: string
|
||||
taskState:
|
||||
type: string
|
||||
description: task state
|
||||
|
|
|
@ -1078,6 +1078,15 @@ export const ApiDefaultTestCases: {[key: string]: IApiTestCase} = {
|
|||
}
|
||||
}],
|
||||
after: [ updateTestJobExecutionType('STOP') ]
|
||||
},
|
||||
'get /api/v2/alerts': {
|
||||
tests: [
|
||||
{
|
||||
// Skip the test temporarily because the alerts came from prometheus.
|
||||
description: 'Skip',
|
||||
customizedTest: 'skipTest'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1096,7 +1105,7 @@ class CustomizedTestsClass {
|
|||
): Promise<void> {
|
||||
const client: TokenClient = new TokenClient({
|
||||
token: unauthorizedToken,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1112,7 +1121,7 @@ class CustomizedTestsClass {
|
|||
): Promise<void> {
|
||||
const client: AuthnClient = new AuthnClient({
|
||||
token: operationResults!.beforeResults![0].token,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1125,7 +1134,7 @@ class CustomizedTestsClass {
|
|||
): Promise<void> {
|
||||
const client: AuthnClient = new AuthnClient({
|
||||
token: unauthorizedToken,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1250,7 +1259,7 @@ class CustomizedTestsClass {
|
|||
): Promise<void> {
|
||||
const client: UserClient = new UserClient({
|
||||
token: applicationToken,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1269,7 +1278,7 @@ class CustomizedTestsClass {
|
|||
|
||||
const client: UserClient = new UserClient({
|
||||
token: info.token,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1286,7 +1295,7 @@ class CustomizedTestsClass {
|
|||
private async createNonadminUserAndToken(): Promise<ILoginInfo> {
|
||||
const openPAIClient: OpenPAIClient = new OpenPAIClient({
|
||||
token: clustersJson[0].token,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
@ -1310,7 +1319,7 @@ class CustomizedTestsClass {
|
|||
private async deleteNonadminUserAndToken(info: ILoginInfo): Promise<void> {
|
||||
const openPAIClient: OpenPAIClient = new OpenPAIClient({
|
||||
token: clustersJson[0].token,
|
||||
https: true,
|
||||
https: clustersJson[0].https,
|
||||
rest_server_uri: clustersJson[0].rest_server_uri
|
||||
});
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ export class ApiTestRunner {
|
|||
const valid: boolean = this.ajvInstance.validate(operation.response.schema, res) as boolean;
|
||||
if (!valid) {
|
||||
console.log(this.ajvInstance.errors);
|
||||
console.log(JSON.stringify(res));
|
||||
}
|
||||
expect(valid, 'response should be valid.').to.be.true();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче