为 os-instance-actions API 添加分页和 changes-since 过滤支持¶
https://blueprints.launchpad.net/nova/+spec/pagination-add-changes-since-for-instance-action-list
此蓝图为 GET /os-instance-actions/{server_id} 请求添加了可选参数 limit 和 marker,以支持分页。
此蓝图还为 GET /os-instance-actions/{server_id} 请求添加了可选参数 changes-since,以支持按更新时间过滤响应数据。
问题描述¶
目前,os-instance-actions API 不支持分页。在生产部署中,每个实例的实例操作记录数量也可能非常大,查询所有记录可能导致性能瓶颈,因此支持分页将非常有用。
此外,os-instance-actions API 不支持按上次更新时间过滤实例操作记录。对于生产部署,一个实例可能运行很长时间,并且实例操作记录的数量(例如迁移操作)也会非常大。考虑到公有云中恶意攻击的情况,攻击者故意对一个实例执行大量操作,实例操作记录也会非常庞大,一旦攻击者查询这些实例操作,也会对其他操作产生一些不良影响,我们需要分页支持来最大限度地减少影响。支持按上次更新时间过滤将非常有用。
存在一个问题,即 instance action 记录的 updated_at 字段实际上并没有被更新 [1]。我们建议通过在操作创建或操作事件更新时更新 instance actions 的 updated_at 来修复此问题 [2]。
用例¶
对于长期运行的部署,管理员可以使用分页和上次更新时间过滤器来获得更高效的数据库查询。
提议的变更¶
添加一个 API 微版本,允许使用通用的分页机制,通过 GET /os-instance-actions/{server_id} 请求的 limit 可选参数获取多个实例操作。并使用 GET /os-instance-actions/{server_id} 请求的 changes-since 可选参数添加过滤器。
limit:要显示的实例操作的最大数量。如果 limit 大于 Nova API 的 [api]/max_limit 选项,则将使用 [api]/max_limit 代替。
marker:上一页的最后一个实例操作的 request_id。显示 “marker” 之后的实例操作列表。
待办事项
当指定 changes-since 参数时,我们需要决定是否按 updated_at 字段或 created_at 字段排序。由于 changes-since 过滤的是 updated_at 字段,因此按 updated_at 字段排序可能更有意义。但是,这将与使用 changes-since 过滤器列出实例时实例的默认排序方式不一致。这是一个可以在代码审查期间讨论的实现细节。
备选方案¶
无
数据模型影响¶
将在 nova.instance_actions 表的 (instance_uuid, updated_at) 列上添加数据库索引,以提高按 ‘changes-since’ 参数过滤实例操作的性能。
REST API 影响¶
该提案将添加 API 微版本,用于使用通用的分页机制获取多个实例操作。新的可选参数 limit、marker 和 changes-since 将添加到 GET /os-instance-actions/{server_id} 请求中。
通用请求格式
GET /os-instance-actions/{server_id}?limit={limit}&marker={request_id}
获取所有实例操作
GET /os-instance-actions/ccc6afd4-2484-4c32-bd42-70cacf571a0e
响应
{ "instanceActions": [ { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T03:20:13.000000", "request_id": "req-11ac94e9-8a6e-41bc-81ac-507fc38a7e50", "action": "reboot", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" }, { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T03:16:34.000000", "request_id": "req-c3053bed-f1f0-4cb3-bde0-21cca81f0543", "action": "start", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" }, { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T03:16:10.000000", "request_id": "req-aef8b118-a8b6-4d53-bfff-c81f035cda2b", "action": "stop", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" }, { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T02:10:14.000000", "request_id": "req-79fa95a3-ce44-4554-bf66-b6731353866d", "action": "create", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" } ] }
获取不超过 2 个实例操作
GET /os-instance-actions/ccc6afd4-2484-4c32-bd42-70cacf571a0e?limit=2 Response :: { "instanceActions": [ { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T03:20:13.000000", "request_id": "req-11ac94e9-8a6e-41bc-81ac-507fc38a7e50", "action": "reboot", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" }, { "instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e", "user_id": "7b2ddda599f74f9aabfe554a978aeca2", "start_time": "2015-10-30T03:16:34.000000", "request_id": "req-c3053bed-f1f0-4cb3-bde0-21cca81f0543", "action": "start", "message": null, "project_id": "0721e55af7904e3b83f1276cd7ef769d" } ], "links": [ { "href": "https://openstack.example.com/v2.1/os-instance-actions?limit=2&marker=req-c3053bed-f1f0-4cb3-bde0-21cca81f0543", "rel": "next" } ] }
3) 获取 changes-since=2013-10-22T13:45:02.000000 之后的所有实例操作 :: 请求格式
GET /os-instance-actions/ccc6afd4-2484-4c32-bd42-70cacf571a0e?changes-since=2015-10-30T03:16:10.000000"
注意
提供的时间应为 ISO 8061 格式的时间。例如 2013-10-22T13:45:02.000000, 2017-10-18T16:06:59Z
响应
{
"instanceActions": [
{
"instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e",
"user_id": "7b2ddda599f74f9aabfe554a978aeca2",
"start_time": "2015-10-30T03:20:13.000000",
"request_id": "req-11ac94e9-8a6e-41bc-81ac-507fc38a7e50",
"action": "reboot",
"message": null,
"project_id": "0721e55af7904e3b83f1276cd7ef769d"
},
{
"instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e",
"user_id": "7b2ddda599f74f9aabfe554a978aeca2",
"start_time": "2015-10-30T03:16:34.000000",
"request_id": "req-c3053bed-f1f0-4cb3-bde0-21cca81f0543",
"action": "start",
"message": null,
"project_id": "0721e55af7904e3b83f1276cd7ef769d"
},
{
"instance_uuid": "ccc6afd4-2484-4c32-bd42-70cacf571a0e",
"user_id": "7b2ddda599f74f9aabfe554a978aeca2",
"start_time": "2015-10-30T03:16:10.000000",
"request_id": "req-aef8b118-a8b6-4d53-bfff-c81f035cda2b",
"action": "stop",
"message": null,
"project_id": "0721e55af7904e3b83f1276cd7ef769d"
}
]
}
安全影响¶
无
通知影响¶
无
其他最终用户影响¶
Python-novaclient 将被修改以处理实例操作分页支持的新微版本。
性能影响¶
无
其他部署者影响¶
无
开发人员影响¶
无
实现¶
负责人¶
- 主要负责人
江益坤
- 其他贡献者
郑振宇
工作项¶
创建一个新的 API 微版本,用于使用通用的分页机制和时间戳过滤获取多个实例操作。
修改 Nova 客户端以处理实例操作分页支持的新微版本。
依赖项¶
此更改取决于 instance actions 的 updated_at 错误的修复。 [2]
测试¶
需要新的树内功能和单元测试。
文档影响¶
需要新的 API 微版本和用量文档。
参考资料¶
历史¶
发布名称 |
描述 |
|---|---|
Newton |
提议 |
Queens |
重新提出 |