为 os-migrations API 添加分页和自变更过滤支持

https://blueprints.launchpad.net/nova/+spec/ add-pagination-and-change-since-for-migration-list

此蓝图为 GET /os-migrations 请求添加可选参数 limitmarker 以支持分页。

此蓝图还为 GET /os-migrations 请求添加可选参数 changes-since 以支持按更新时间过滤响应数据。

问题描述

目前,os-migrations API 不支持分页。 在大规模部署中,迁移记录的数量也可能非常大,全部查询会导致性能瓶颈,因此支持分页将非常有用。

此外,os-migrations API 不支持按最后更新时间过滤迁移记录。 对于生产部署,系统将运行很长时间,迁移记录的数量也会非常多。 支持按最后更新时间过滤将非常有用。

用例

对于大规模生产部署,管理员可以使用分页和最新的更新时间过滤器来获得更高效的数据库查询。

提议的变更

添加一个 API 微版本,允许使用通用的分页机制,通过向 GET /os-migrations 请求添加可选参数 limitmarker 来获取多个迁移。 并通过向 GET /os-migrations 请求添加可选参数 `changes-since 来添加过滤器。

  • marker:上一页的最后一个迁移 ID。 显示“marker”之后的迁移列表。

  • limit:要显示的迁移的最大数量。 如果 limit == -1,将显示所有迁移。 如果 limit 大于 Nova API 的 osapi_max_limit 选项,则将使用 osapi_max_limit 代替。

备选方案

数据模型影响

REST API 影响

该提案将添加 API 微版本,用于使用通用分页机制获取多个迁移。 新的可选参数 limitmarkerchanges-since 将添加到 GET /os-migrations 请求中。

通用请求格式

GET /os-migrations?limit={limit}&marker={migration_id}
  1. 获取所有迁移

    GET /os-migrations
    

    响应

    {
    "migrations": [
        {
            "created_at": "2012-10-29T13:42:02.000000",
            "dest_compute": "compute2",
            "dest_host": "1.2.3.4",
            "dest_node": "node2",
            "id": 1234,
            "instance_uuid": "instance_id_123",
            "new_instance_type_id": 2,
            "old_instance_type_id": 1,
            "source_compute": "compute1",
            "source_node": "node1",
            "status": "Done",
            "updated_at": "2012-10-29T13:42:02.000000"
        },
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 5678,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000"
        },
        {
            "created_at": "2013-10-22T13:45:02.000000",
            "dest_compute": "compute21",
            "dest_host": "5.6.7.8",
            "dest_node": "node21",
            "id": 5679,
            "instance_uuid": "instance_id_4561",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:45:02.000000"
        }
    ]
    }
    
  2. 获取最多 2 个迁移

    GET /os-migrations?limit=2
    

    响应

    {
    "migrations": [
        {
            "created_at": "2012-10-29T13:42:02.000000",
            "dest_compute": "compute2",
            "dest_host": "1.2.3.4",
            "dest_node": "node2",
            "id": 1234,
            "instance_uuid": "instance_id_123",
            "new_instance_type_id": 2,
            "old_instance_type_id": 1,
            "source_compute": "compute1",
            "source_node": "node1",
            "status": "Done",
            "updated_at": "2012-10-29T13:42:02.000000"
        },
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 5678,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000"
        }
    ]
    }
    
  3. 获取 id=1234 之后的全部迁移

    GET /os-migrations?marker=1234
    

    响应

    {
    "migrations": [
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 5678,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000"
        },
        {
            "created_at": "2013-10-22T13:45:02.000000",
            "dest_compute": "compute21",
            "dest_host": "5.6.7.8",
            "dest_node": "node21",
            "id": 5679,
            "instance_uuid": "instance_id_4561",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:45:02.000000"
        }
    ]
    }
    

请求格式

GET /os-migrations?changes-since=2013-10-22T13:45:02.000000

响应

{
"migrations":[
    {
        "created_at": "2013-10-22T13:45:02.000000",
        "dest_compute": "compute21",
        "dest_host": "5.6.7.8",
        "dest_node": "node21",
        "id": 1234,
        "instance_uuid": "instance_id_4561",
        "new_instance_type_id": 6,
        "old_instance_type_id": 5,
        "source_compute": "compute10",
        "source_node": "node10",
        "status": "Done",
        "updated_at": "2013-10-22T13:45:02.000000"
    }
]
}

安全影响

通知影响

其他最终用户影响

性能影响

通过分页和从 Nova 端检索迁移的时间过滤来减轻 Horizon 的负载。

其他部署者影响

开发人员影响

实现

负责人

主要负责人

郑振宇

工作项

创建一个新的 API 微版本,用于使用通用分页机制和时间戳过滤来获取多个迁移。

依赖项

测试

需要新的 Tempest、功能和单元测试。

文档影响

需要新的 API 微版本和用量文档。

参考资料