定义行动计划失效/无效的时间

https://blueprints.launchpad.net/watcher/+spec/stale-action-plan

问题描述

当创建审计并成功启动时,它会生成一个状态为 RECOMMENDED 的新行动计划。如果集群数据模型逐渐发生变化,行动计划仍然保持在 RECOMMENDED 状态。到目前为止,还没有过期日期或事件可以使行动计划失效。

用例

作为 Watcher 管理员,我希望 watcher 自动将任何行动计划的状态从 RECOMMENDED 更新为 SUPERSEDED,如果该行动计划已过期(默认过期时间:24 小时)。

作为 Watcher 管理员,在推荐的行动计划成功启动后,我希望 watcher 自动将基于相同集群数据模型的任何行动计划的状态从 RECOMMENDED 更新为 SUPERSEDED

作为 Watcher 管理员,当集群数据模型发生变化时,我希望 watcher 自动将基于此集群数据模型的行动计划的状态从 RECOMMENDED 更新为 SUPERSEDED

项目优先级

提议的变更

需要考虑三种场景

SCENARIO_1 行动计划过期

如果行动计划在 RECOMMENDED 状态下保持指定的时间(默认 24 小时),则状态将自动设置为 SUPERSEDED。

例如

actionplan_1{created_at:'2017-02-07 01:00:00', state:RECOMMENDED}
actionplan_2{created_at:'2017-02-07 02:00:00', state:RECOMMENDED}

when datetime='2017-02-08 01:01:00'
(datetime-actionplan_1.created_at)>24 hours
(datetime-actionplan_2.created_at)<24 hours
result:
actionplan_1{created_at:'2017-02-07 01:00:00', state:SUPERSEDED}
actionplan_2{created_at:'2017-02-07 02:00:00', state:RECOMMENDED}

when datetime='2017-02-08 02:01:00'
(datetime-actionplan_1.created_at)>24 hours
(datetime-actionplan_2.created_at)>24 hours
result:
actionplan_1{created_at:'2017-02-07 01:00:00', state:SUPERSEDED}
actionplan_2{created_at:'2017-02-07 02:00:00', state:SUPERSEDED}

SCENARIO_2 行动计划启动

RECOMMENDED 行动计划成功启动时,其他仍处于 RECOMMENDED 状态的行动计划将被设置为 SUPERSEDED 状态。

两种情况

CASE a

无论生成行动计划的审计范围如何,只要行动计划的状态为 RECOMMENDED,都将被设置为 SUPERSEDED

例如

scope_1 = {'availability_zones': [{'name': 'AZ1'}]}
scope_2 = {'availability_zones': [{'name': 'AZ2'}]}
scope_3 = {'availability_zones': [{'name': 'AZ3'}]}

actionplan_1{audit.scope:'scope_1', state:RECOMMENDED}
actionplan_2{audit.scope:'scope_2', state:RECOMMENDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

when launch actionplan_1{audit.scope:'scope_1', state:SUCCEEDED}
result:
actionplan_2{audit.scope:'scope_2', state:SUPERSEDED}
actionplan_3{audit.scope:'scope_3', state:SUPERSEDED}

CASE b

考虑生成行动计划的审计范围,检查生成行动计划的审计范围,并且仅将具有相同范围的行动计划设置为 SUPERSEDED

例如

scope_1 = [{'availability_zones': [{'name': 'AZ1'}, {'name': 'AZ2'}]}]
scope_2 = [{'availability_zones': [{'name': 'AZ1'}, {'name': 'AZ2'}]}]
scope_3 = [{'availability_zones': [{'name': 'AZ2'}, {'name': 'AZ1'}]}]

actionplan_1{audit.scope:'scope_1', state:RECOMMENDED}
actionplan_2{audit.scope:'scope_2', state:RECOMMENDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

when launch actionplan_1{audit.scope:'scope_1', state:SUCCEEDED},
scope_1==scope_2:True
scope_1==scope_3:False
result:
actionplan_2{audit.scope:'scope_2', state:SUPERSEDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

注意: 此处比较 audit.scope 字符串值。 因此 scope_1 和 scope_3 的比较结果为 false。

SCENARIO_3 数据模型变更

当数据模型中的节点发生变化时,处于 RECOMMENDED 状态的行动计划将被设置为 SUPERSEDED 状态。

两种情况

CASE a

只要存在节点变化,处于 RECOMMENDED 状态的行动计划将被设置为 SUPERSEDED 状态。

例如

scope_1 = {'availability_zones': [{'name': 'AZ1'}]}
scope_2 = {'availability_zones': [{'name': 'AZ2'}]}
scope_3 = {'availability_zones': [{'name': 'AZ3'}]}

actionplan_1{audit.scope:'scope_1', state:RECOMMENDED}
actionplan_2{audit.scope:'scope_2', state:RECOMMENDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

when any node in data model change
result:
actionplan_1{audit.scope:'scope_1', state:SUPERSEDED}
actionplan_2{audit.scope:'scope_2', state:SUPERSEDED}
actionplan_3{audit.scope:'scope_3', state:SUPERSEDED}

CASE b

检查生成的行动计划的审计范围。只有当审计范围内的节点发生变化时,相应的行动计划才会被设置为 SUPERSEDED

例如

scope_1 = {'availability_zones': [{'name': 'AZ1'}]}
scope_2 = {'availability_zones': [{'name': 'AZ2'}]}
scope_3 = {'availability_zones': [{'name': 'AZ3'}]}

actionplan_1{audit.scope:'scope_1', state:RECOMMENDED}
actionplan_2{audit.scope:'scope_2', state:RECOMMENDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

when node in scope_1 change
result:
actionplan_1{audit.scope:'scope_1', state:SUPERSEDED}
actionplan_2{audit.scope:'scope_2', state:RECOMMENDED}
actionplan_3{audit.scope:'scope_3', state:RECOMMENDED}

讨论结论 如下有三个选项可供选择。根据 PTG 会议的结论,我们首先做最简单的,并在未来的工作中根据需要考虑范围。

1: 简单,仅 SCENARIO_1

2: 严格,SCENARIO_1 + SCENARIO_2a + SCENARIO_3a

3: 复杂,SCENARIO_1 + SCENARIO_2b + SCENARIO_3b

备选方案

数据模型影响

REST API 影响

安全影响

通知影响

其他最终用户影响

性能影响

其他部署者影响

添加新的配置参数 action_plan_expirycheck_periodic_interval

cfg.IntOpt('action_plan_expiry',
           default=24,
           help=('An expiry date(hours). We invalidate the action plan'
                  'if its created older than the expiry date.')),
cfg.IntOpt('check_periodic_interval',
           default=30*60,
           help=('Seconds between running periodic tasks.'))

开发人员影响

实现

负责人

主要负责人

<licanwei>

工作项

以下是预见的工作项目列表

  • 添加配置参数 action_plan_expirycheck_periodic_interval (SCENARIO_1)。

  • 修改 DefaultActionPlanHandler 类,触发检查行动计划的状态(SCENARIO_2)。

  • 目前,当接收到特定事件(例如 nova 通知 event_type:service.update, instance.update, instance.delete.end)时,决策引擎将更新集群数据模型。我们需要将行动计划状态更新添加到此过程中(SCENARIO_3)。

  • 添加一个新的 StateManager 类。在这个类中,我们实现行动计划状态管理(SCENARIO_1, SCENARIO_2, SCENARIO_3)。

依赖项

https://blueprints.launchpad.net/watcher/+spec/define-the-audit-scope

测试

单元测试和 tempest 测试需要更新。

文档影响

需要更新架构文档中的 行动计划状态机

参考资料

历史