Skip to content

Commit 0d63cdb

Browse files
Add ML Controller APIs (#779)
* Added ML create, update, get, delete controller APIs. Signed-off-by: Nathalie Jonathan <[email protected]> * Added memory threshold settings in Controller API tests. Signed-off-by: Nathalie Jonathan <[email protected]> * Remove logs folder and add it to .gitignore. Signed-off-by: Nathalie Jonathan <[email protected]> --------- Signed-off-by: Nathalie Jonathan <[email protected]>
1 parent bf353a7 commit 0d63cdb

File tree

8 files changed

+446
-1
lines changed

8 files changed

+446
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ build/
1919
# coverage output
2020
/coverage/
2121

22+
# log files
23+
/logs/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4848
- Added `POST /_plugins/_ml/memory`, `POST /_plugins/_ml/memory/_search`, `{memory_id}/_search`, `{memory_id}/messages`, `PUT /_plugins/_ml/memory/{memory_id}`, `message/{message_id}`, `GET /_plugins/_ml/memory`, `GET /_plugins/_ml/memory/{memory_id}`, `_search`, `message/{message_id}`, `{memory_id}/messages`, `{memory_id}/_search`, `message/{message_id}/traces`, and `DELETE /_plugins/_ml/memory/{memory_id}` ([#771](https://github.com/opensearch-project/opensearch-api-specification/pull/771))
4949
- Added support for evaluating response payloads in prologues and epilogues ([#772](https://github.com/opensearch-project/opensearch-api-specification/pull/772))
5050
- Added `GET /_plugins/_ml/models/{model_id}`, `POST /_plugins/_ml/models/_search`, `POST /_plugins/_ml/models/_unload`, `_undeploy`, `_upload`, `meta`, `_register_meta`, `POST /_plugins/_ml/models/{model_id}/_load`, `_predict`, `_unload`, `chunk/{chunk_number}`, `upload_chunk/{chunk_number}`, and `PUT /_plugins/_ml/models/{model_id}` ([#733](https://github.com/opensearch-project/opensearch-api-specification/pull/733))
51+
- Added `GET`, `POST`, `PUT`, `DELETE /_plugins/_ml/controllers/{model_id}` ([#779](https://github.com/opensearch-project/opensearch-api-specification/pull/779))
5152

5253
### Removed
5354
- Removed unsupported `_common.mapping:SourceField`'s `mode` field and associated `_common.mapping:SourceFieldMode` enum ([#652](https://github.com/opensearch-project/opensearch-api-specification/pull/652))

spec/namespaces/ml.yaml

+117
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,51 @@ paths:
585585
responses:
586586
'200':
587587
$ref: '#/components/responses/ml.get_message_traces@200'
588+
/_plugins/_ml/controllers/{model_id}:
589+
get:
590+
operationId: ml.get_controller.0
591+
x-operation-group: ml.get_controller
592+
x-version-added: '2.12'
593+
description: Retrieves a controller.
594+
parameters:
595+
- $ref: '#/components/parameters/ml.get_controller::path.model_id'
596+
responses:
597+
'200':
598+
$ref: '#/components/responses/ml.get_controller@200'
599+
post:
600+
operationId: ml.create_controller.0
601+
x-operation-group: ml.create_controller
602+
x-version-added: '2.12'
603+
description: Creates a controller.
604+
requestBody:
605+
$ref: '#/components/requestBodies/ml.create_controller'
606+
parameters:
607+
- $ref: '#/components/parameters/ml.create_controller::path.model_id'
608+
responses:
609+
'200':
610+
$ref: '#/components/responses/ml.create_controller@200'
611+
put:
612+
operationId: ml.update_controller.0
613+
x-operation-group: ml.update_controller
614+
x-version-added: '2.12'
615+
description: Updates a controller.
616+
requestBody:
617+
$ref: '#/components/requestBodies/ml.update_controller'
618+
parameters:
619+
- $ref: '#/components/parameters/ml.update_controller::path.model_id'
620+
responses:
621+
'200':
622+
$ref: '#/components/responses/ml.update_controller@200'
623+
delete:
624+
operationId: ml.delete_controller.0
625+
x-operation-group: ml.delete_controller
626+
x-version-added: '2.12'
627+
description: Deletes a controller.
628+
parameters:
629+
- $ref: '#/components/parameters/ml.delete_controller::path.model_id'
630+
responses:
631+
'200':
632+
$ref: '#/components/responses/ml.delete_controller@200'
588633
components:
589634
requestBodies:
590635
ml.register_model_group:
@@ -1171,6 +1216,24 @@ components:
11711216
items:
11721217
$ref: '../schemas/ml._common.yaml#/components/schemas/SortMessage'
11731218
description: The sort order.
1219+
ml.create_controller:
1220+
content:
1221+
application/json:
1222+
schema:
1223+
type: object
1224+
properties:
1225+
user_rate_limiter:
1226+
$ref: '../schemas/ml._common.yaml#/components/schemas/UserRateLimiter'
1227+
ml.update_controller:
1228+
content:
1229+
application/json:
1230+
schema:
1231+
type: object
1232+
properties:
1233+
user_rate_limiter:
1234+
$ref: '../schemas/ml._common.yaml#/components/schemas/UserRateLimiter'
1235+
model_id:
1236+
$ref: '../schemas/_common.yaml#/components/schemas/Name'
11741237
responses:
11751238
ml.register_model_group@200:
11761239
content:
@@ -1478,6 +1541,36 @@ components:
14781541
application/json:
14791542
schema:
14801543
$ref: '../schemas/ml._common.yaml#/components/schemas/GetMessageTracesResponse'
1544+
ml.get_controller@200:
1545+
content:
1546+
application/json:
1547+
schema:
1548+
type: object
1549+
properties:
1550+
user_rate_limiter:
1551+
$ref: '../schemas/ml._common.yaml#/components/schemas/UserRateLimiter'
1552+
model_id:
1553+
$ref: '../schemas/_common.yaml#/components/schemas/Name'
1554+
ml.create_controller@200:
1555+
content:
1556+
application/json:
1557+
schema:
1558+
type: object
1559+
properties:
1560+
model_id:
1561+
$ref: '../schemas/_common.yaml#/components/schemas/Name'
1562+
status:
1563+
$ref: '../schemas/ml._common.yaml#/components/schemas/Status'
1564+
ml.update_controller@200:
1565+
content:
1566+
application/json:
1567+
schema:
1568+
$ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase'
1569+
ml.delete_controller@200:
1570+
content:
1571+
application/json:
1572+
schema:
1573+
$ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase'
14811574
parameters:
14821575
ml.get_model_group::path.model_group_id:
14831576
name: model_group_id
@@ -1683,5 +1776,29 @@ components:
16831776
name: message_id
16841777
in: path
16851778
required: true
1779+
schema:
1780+
type: string
1781+
ml.get_controller::path.model_id:
1782+
name: model_id
1783+
in: path
1784+
required: true
1785+
schema:
1786+
type: string
1787+
ml.create_controller::path.model_id:
1788+
name: model_id
1789+
in: path
1790+
required: true
1791+
schema:
1792+
type: string
1793+
ml.update_controller::path.model_id:
1794+
name: model_id
1795+
in: path
1796+
required: true
1797+
schema:
1798+
type: string
1799+
ml.delete_controller::path.model_id:
1800+
name: model_id
1801+
in: path
1802+
required: true
16861803
schema:
16871804
type: string

spec/schemas/ml._common.yaml

+24-1
Original file line numberDiff line numberDiff line change
@@ -1233,4 +1233,27 @@ components:
12331233
traces:
12341234
type: array
12351235
items:
1236-
$ref: '#/components/schemas/Message'
1236+
$ref: '#/components/schemas/Message'
1237+
UserRateLimiter:
1238+
type: object
1239+
properties:
1240+
user1:
1241+
$ref: '#/components/schemas/User'
1242+
additionalProperties: true
1243+
User:
1244+
type: object
1245+
properties:
1246+
limit:
1247+
type: [integer, string]
1248+
description: Max Predict API calls per user per time unit.
1249+
unit:
1250+
type: string
1251+
description: The unit of time.
1252+
enum:
1253+
- DAYS
1254+
- HOURS
1255+
- MICROSECONDS
1256+
- MILLISECONDS
1257+
- MINUTES
1258+
- NANOSECONDS
1259+
- SECONDS
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
$schema: ../../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test the creation of a controller.
4+
version: '>= 2.12'
5+
prologues:
6+
- path: /_cluster/settings
7+
method: PUT
8+
request:
9+
payload:
10+
persistent:
11+
plugins.ml_commons.native_memory_threshold: 100
12+
- path: /_plugins/_ml/models/_register
13+
id: register_model
14+
method: POST
15+
request:
16+
payload:
17+
name: huggingface/sentence-transformers/msmarco-distilbert-base-tas-b
18+
version: 1.0.1
19+
model_format: TORCH_SCRIPT
20+
output:
21+
task_id: payload.task_id
22+
- path: /_plugins/_ml/tasks/{task_id}
23+
id: get_completed_task
24+
method: GET
25+
parameters:
26+
task_id: ${register_model.task_id}
27+
retry:
28+
count: 3
29+
wait: 10000
30+
response:
31+
status: 200
32+
payload:
33+
state: COMPLETED
34+
output:
35+
model_id: payload.model_id
36+
epilogues:
37+
- path: /_plugins/_ml/controllers/{model_id}
38+
parameters:
39+
model_id: ${create_controller.model_id}
40+
method: DELETE
41+
status: [200, 404]
42+
- path: /_plugins/_ml/models/{model_id}
43+
parameters:
44+
model_id: ${get_completed_task.model_id}
45+
method: DELETE
46+
status: [200, 404]
47+
- path: /_plugins/_ml/tasks/{task_id}
48+
parameters:
49+
task_id: ${register_model.task_id}
50+
method: DELETE
51+
status: [200, 404]
52+
chapters:
53+
- synopsis: Create a controller.
54+
id: create_controller
55+
path: /_plugins/_ml/controllers/{model_id}
56+
method: POST
57+
parameters:
58+
model_id: ${get_completed_task.model_id}
59+
request:
60+
payload:
61+
user_rate_limiter:
62+
user1:
63+
limit: 4
64+
unit: MINUTES
65+
user2:
66+
limit: 4
67+
unit: MINUTES
68+
response:
69+
status: 200
70+
output:
71+
model_id: payload.model_id
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
$schema: ../../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test the deletion of a controller.
4+
version: '>= 2.12'
5+
prologues:
6+
- path: /_cluster/settings
7+
method: PUT
8+
request:
9+
payload:
10+
persistent:
11+
plugins.ml_commons.native_memory_threshold: 100
12+
- path: /_plugins/_ml/models/_register
13+
id: register_model
14+
method: POST
15+
request:
16+
payload:
17+
name: huggingface/sentence-transformers/msmarco-distilbert-base-tas-b
18+
version: 1.0.1
19+
model_format: TORCH_SCRIPT
20+
output:
21+
task_id: payload.task_id
22+
- path: /_plugins/_ml/tasks/{task_id}
23+
id: get_completed_task
24+
method: GET
25+
parameters:
26+
task_id: ${register_model.task_id}
27+
retry:
28+
count: 3
29+
wait: 10000
30+
response:
31+
status: 200
32+
payload:
33+
state: COMPLETED
34+
output:
35+
model_id: payload.model_id
36+
- path: /_plugins/_ml/controllers/{model_id}
37+
id: create_controller
38+
method: POST
39+
parameters:
40+
model_id: ${get_completed_task.model_id}
41+
request:
42+
payload:
43+
user_rate_limiter:
44+
user1:
45+
limit: 4
46+
unit: MINUTES
47+
user2:
48+
limit: 4
49+
unit: MINUTES
50+
output:
51+
model_id: payload.model_id
52+
epilogues:
53+
- path: /_plugins/_ml/controllers/{model_id}
54+
parameters:
55+
model_id: ${create_controller.model_id}
56+
method: DELETE
57+
status: [200, 404]
58+
- path: /_plugins/_ml/models/{model_id}
59+
parameters:
60+
model_id: ${get_completed_task.model_id}
61+
method: DELETE
62+
status: [200, 404]
63+
- path: /_plugins/_ml/tasks/{task_id}
64+
parameters:
65+
task_id: ${register_model.task_id}
66+
method: DELETE
67+
status: [200, 404]
68+
chapters:
69+
- synopsis: Delete a controller.
70+
path: /_plugins/_ml/controllers/{model_id}
71+
method: DELETE
72+
parameters:
73+
model_id: ${create_controller.model_id}
74+
response:
75+
status: 200

0 commit comments

Comments
 (0)