Skip to content

Commit

Permalink
fix: list models and model instances pagination (#304)
Browse files Browse the repository at this point in the history
Because

- there is a bug in the pagination API including list models, model
instances

This commit

- fix the bug when pagination
  • Loading branch information
Phelan164 committed Mar 13, 2023
1 parent 77f764a commit 1f19ed4
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 85 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,6 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230217111731-b78c700241b2 h1:TLK82ewEE54IgE71Er+rY5wq7kXVSS0pQd17C6hW+34=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230217111731-b78c700241b2/go.mod h1:7/Jj3ATVozPwB0WmKRM612o/k5UJF8K9oRCNKYH8iy0=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230307101000-a8348ab7c390 h1:x7wlV2IGhW8XzG/K8s9gsu1cGDEIug+eJmFvElmNxvk=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230307101000-a8348ab7c390/go.mod h1:7/Jj3ATVozPwB0WmKRM612o/k5UJF8K9oRCNKYH8iy0=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230308122400-51986736325a h1:pXAll60F53JR0Tyny5Glq8DQmWuU9BOqmoSMGl2oFf4=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230308122400-51986736325a/go.mod h1:7/Jj3ATVozPwB0WmKRM612o/k5UJF8K9oRCNKYH8iy0=
github.com/instill-ai/usage-client v0.2.2-alpha h1:EQyHpgzZ26TEIL9UoaqchTf+LnKaidUGhKlUEFR68I8=
Expand Down
114 changes: 102 additions & 12 deletions integration-test/rest_query_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export function ListModel() {
// Model Backend API: Get model list
{
group("Model Backend API: Get model list", function () {
let model_id = randomString(10)
let model_id_1 = randomString(10)
let createClsModelRes = http.request("POST", `${constant.apiHost}/v1alpha/models`, JSON.stringify({
"id": model_id,
"id": model_id_1,
"model_definition": "model-definitions/github",
"configuration": {
"repository": "instill-ai/model-dummy-cls"
Expand Down Expand Up @@ -154,23 +154,86 @@ export function ListModel() {
currentTime = new Date().getTime();
}

check(http.get(`${constant.apiHost}/v1alpha/models`, {
let model_id_2 = randomString(10)
createClsModelRes = http.request("POST", `${constant.apiHost}/v1alpha/models`, JSON.stringify({
"id": model_id_2,
"model_definition": "model-definitions/github",
"configuration": {
"repository": "instill-ai/model-dummy-cls"
}
}), {
headers: genHeader("application/json"),
})
check(createClsModelRes, {
"POST /v1alpha/models/multipart task cls response status": (r) =>
r.status === 201,
"POST /v1alpha/models/multipart task cls response operation.name": (r) =>
r.json().operation.name !== undefined,
});

// Check model creation finished
currentTime = new Date().getTime();
timeoutTime = new Date().getTime() + 120000;
while (timeoutTime > currentTime) {
let res = http.get(`${constant.apiHost}/v1alpha/${createClsModelRes.json().operation.name}`, {
headers: genHeader(`application/json`),
})
if (res.json().operation.done === true) {
break
}
sleep(1)
currentTime = new Date().getTime();
}
check(http.get(`${constant.apiHost}/v1alpha/models?page_size=1`, {
headers: genHeader(`application/json`),
}), {
[`GET /v1alpha/models task cls response status`]: (r) =>
r.status === 200,
[`GET /v1alpha/models task cls response total_size`]: (r) =>
r.json().total_size == 1,
r.json().total_size == 2,
[`GET /v1alpha/models task cls response next_page_token`]: (r) =>
r.json().next_page_token !== undefined,
[`GET /v1alpha/models task cls response models.length`]: (r) =>
r.json().models.length === 1,
[`GET /v1alpha/models task cls response models[0].name`]: (r) =>
r.json().models[0].name === `models/${model_id}`,
r.json().models[0].name === `models/${model_id_2}`,
[`GET /v1alpha/models task cls response models[0].uid`]: (r) =>
r.json().models[0].uid !== undefined,
[`GET /v1alpha/models task cls response models[0].id`]: (r) =>
r.json().models[0].id === model_id,
r.json().models[0].id === model_id_2,
[`GET /v1alpha/models task cls response models[0].description`]: (r) =>
r.json().models[0].description !== undefined,
[`GET /v1alpha/models task cls response models[0].model_definition`]: (r) =>
r.json().models[0].model_definition === "model-definitions/github",
[`GET /v1alpha/models task cls response models[0].configuration`]: (r) =>
r.json().models[0].configuration === null,
[`GET /v1alpha/models task cls response models[0].visibility`]: (r) =>
r.json().models[0].visibility === "VISIBILITY_PUBLIC",
[`GET /v1alpha/models task cls response models[0].owner`]: (r) =>
r.json().models[0].user === 'users/local-user',
[`GET /v1alpha/models task cls response models[0].create_time`]: (r) =>
r.json().models[0].create_time !== undefined,
[`GET /v1alpha/models task cls response models[0].update_time`]: (r) =>
r.json().models[0].update_time !== undefined,
});

check(http.get(`${constant.apiHost}/v1alpha/models?page_size=1&page_token=${resp.json().next_page_token}`, {
headers: genHeader(`application/json`),
}), {
[`GET /v1alpha/models task cls response status`]: (r) =>
r.status === 200,
[`GET /v1alpha/models task cls response total_size`]: (r) =>
r.json().total_size == 2,
[`GET /v1alpha/models task cls response next_page_token`]: (r) =>
r.json().next_page_token !== undefined,
[`GET /v1alpha/models task cls response models.length`]: (r) =>
r.json().models.length === 1,
[`GET /v1alpha/models task cls response models[0].name`]: (r) =>
r.json().models[0].name === `models/${model_id_1}`,
[`GET /v1alpha/models task cls response models[0].uid`]: (r) =>
r.json().models[0].uid !== undefined,
[`GET /v1alpha/models task cls response models[0].id`]: (r) =>
r.json().models[0].id === model_id_1,
[`GET /v1alpha/models task cls response models[0].description`]: (r) =>
r.json().models[0].description !== undefined,
[`GET /v1alpha/models task cls response models[0].model_definition`]: (r) =>
Expand All @@ -193,17 +256,17 @@ export function ListModel() {
[`GET /v1alpha/models?view=VIEW_FULL task cls response status`]: (r) =>
r.status === 200,
[`GET /v1alpha/models?view=VIEW_FULL task cls response total_size`]: (r) =>
r.json().total_size == 1,
r.json().total_size == 2,
[`GET /v1alpha/models?view=VIEW_FULL task cls response next_page_token`]: (r) =>
r.json().next_page_token !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models.length`]: (r) =>
r.json().models.length === 1,
r.json().models.length === 2,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].name`]: (r) =>
r.json().models[0].name === `models/${model_id}`,
r.json().models[0].name === `models/${model_id_2}`,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].uid`]: (r) =>
r.json().models[0].uid !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].id`]: (r) =>
r.json().models[0].id === model_id,
r.json().models[0].id === model_id_2,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].description`]: (r) =>
r.json().models[0].description !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].model_definition`]: (r) =>
Expand All @@ -220,16 +283,43 @@ export function ListModel() {
r.json().models[0].create_time !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[0].update_time`]: (r) =>
r.json().models[0].update_time !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].name`]: (r) =>
r.json().models[1].name === `models/${model_id_1}`,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].uid`]: (r) =>
r.json().models[1].uid !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].id`]: (r) =>
r.json().models[1].id === model_id_1,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].description`]: (r) =>
r.json().models[1].description !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].model_definition`]: (r) =>
r.json().models[1].model_definition === "model-definitions/github",
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].configuration.repository`]: (r) =>
r.json().models[1].configuration.repository === "instill-ai/model-dummy-cls",
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].configuration.html_url`]: (r) =>
r.json().models[1].configuration.html_url === "https://github.com/instill-ai/model-dummy-cls",
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].visibility`]: (r) =>
r.json().models[1].visibility === "VISIBILITY_PUBLIC",
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].owner`]: (r) =>
r.json().models[1].user === 'users/local-user',
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].create_time`]: (r) =>
r.json().models[1].create_time !== undefined,
[`GET /v1alpha/models?view=VIEW_FULL task cls response models[1].update_time`]: (r) =>
r.json().models[1].update_time !== undefined,
});

// clean up
check(http.request("DELETE", `${constant.apiHost}/v1alpha/models/${model_id}`, null, {
check(http.request("DELETE", `${constant.apiHost}/v1alpha/models/${model_id_1}`, null, {
headers: genHeader(`application/json`),
}), {
"DELETE clean up response status": (r) =>
r.status === 204
});
check(http.request("DELETE", `${constant.apiHost}/v1alpha/models/${model_id_2}`, null, {
headers: genHeader(`application/json`),
}), {
"DELETE clean up response status": (r) =>
r.status === 204
});

});
}
}
Expand Down
46 changes: 39 additions & 7 deletions integration-test/rest_query_model_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,49 @@ export function ListModelInstance() {
sleep(1)
currentTime = new Date().getTime();
}
let resp = http.get(`${constant.apiHost}/v1alpha/models/${model_id}/instances?page_size=1`, {
headers: genHeader(`application/json`),
})
check(resp, {
[`GET /v1alpha/models/${model_id}/instances task cls response status`]: (r) =>
r.status === 200,
[`GET /v1alpha/models/${model_id}/instances task cls response next_page_token`]: (r) =>
r.json().next_page_token !== undefined,
[`GET /v1alpha/models/${model_id}/instances task cls response total_size`]: (r) =>
r.json().total_size == 2,
[`GET /v1alpha/models/${model_id}/instances task cls response instances.length`]: (r) =>
r.json().instances.length == 1,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].name`]: (r) =>
r.json().instances[0].name === `models/${model_id}/instances/v1.0-cpu`,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].uid`]: (r) =>
r.json().instances[0].uid !== undefined,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].id`]: (r) =>
r.json().instances[0].id === "v1.0-cpu",
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].state`]: (r) =>
r.json().instances[0].state === "STATE_OFFLINE",
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].task`]: (r) =>
r.json().instances[0].task === "TASK_CLASSIFICATION",
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].model_definition`]: (r) =>
r.json().instances[0].model_definition === "model-definitions/github",
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].create_time`]: (r) =>
r.json().instances[0].create_time !== undefined,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].update_time`]: (r) =>
r.json().instances[0].update_time !== undefined,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].configuration`]: (r) =>
r.json().instances[0].configuration === null,
});

check(http.get(`${constant.apiHost}/v1alpha/models/${model_id}/instances`, {
check(http.get(`${constant.apiHost}/v1alpha/models/${model_id}/instances?page_size=1&page_token=${resp.json().next_page_token}`, {
headers: genHeader(`application/json`),
}), {
[`GET /v1alpha/models/${model_id}/instances task cls response status`]: (r) =>
r.status === 200,
[`GET /v1alpha/models/${model_id}/instances task cls response next_page_token`]: (r) =>
r.json().next_page_token !== undefined,
r.json().next_page_token === "",
[`GET /v1alpha/models/${model_id}/instances task cls response total_size`]: (r) =>
r.json().total_size == 2,
[`GET /v1alpha/models/${model_id}/instances task cls response instances.length`]: (r) =>
r.json().instances.length == 2,
r.json().instances.length == 1,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].name`]: (r) =>
r.json().instances[0].name === `models/${model_id}/instances/v1.1-cpu`,
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].uid`]: (r) =>
Expand All @@ -287,6 +318,7 @@ export function ListModelInstance() {
[`GET /v1alpha/models/${model_id}/instances task cls response instances[0].configuration`]: (r) =>
r.json().instances[0].configuration === null,
});

check(http.get(`${constant.apiHost}/v1alpha/models/${model_id}/instances?view=VIEW_FULL`, {
headers: genHeader(`application/json`),
}), {
Expand All @@ -299,11 +331,11 @@ export function ListModelInstance() {
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances.length`]: (r) =>
r.json().instances.length === 2,
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].name`]: (r) =>
r.json().instances[0].name === `models/${model_id}/instances/v1.1-cpu`,
r.json().instances[0].name === `models/${model_id}/instances/v1.0-cpu`,
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].uid`]: (r) =>
r.json().instances[0].uid !== undefined,
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].id`]: (r) =>
r.json().instances[0].id === "v1.1-cpu",
r.json().instances[0].id === "v1.0-cpu",
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].state`]: (r) =>
r.json().instances[0].state === "STATE_OFFLINE",
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].task`]: (r) =>
Expand All @@ -317,9 +349,9 @@ export function ListModelInstance() {
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].configuration.repository`]: (r) =>
r.json().instances[0].configuration.repository === "instill-ai/model-dummy-cls",
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].configuration.html_url`]: (r) =>
r.json().instances[0].configuration.html_url === "https://github.com/instill-ai/model-dummy-cls/tree/v1.1-cpu",
r.json().instances[0].configuration.html_url === "https://github.com/instill-ai/model-dummy-cls/tree/v1.0-cpu",
[`GET /v1alpha/models/${model_id}/instances?view=VIEW_FULL task cls response instances[0].configuration.tag`]: (r) =>
r.json().instances[0].configuration.tag === "v1.1-cpu",
r.json().instances[0].configuration.tag === "v1.0-cpu",
});

// clean up
Expand Down

0 comments on commit 1f19ed4

Please sign in to comment.