rackerlabs/otter — pull request #483 by cyli (2013-11-25 19:14:59+00:00)
Title: Audit log some group changes (ready for review)

This pull request adds some audit logging for policy creation and deletion. However, mainly, this:

1. fixed a bug in the get_capacity() function of the group state - `active_capacity` should be `current_capacity`
2. added a decorator to audit log requests when they are done and successful, so we can add this to all group-changing handlers
3. include the request IP with the request audit logs only - we may eventually want to move this to transaction id, but perhaps when we separate the convergence and request stuff?

Future PRs after this one:
1. add decorator + tests for all create + deletes + updates that do not involve any convergence
2. decorator + extra stuff for group edits that require convergence - this is tricky since "convergence" kicks off between the start of the request and the end, so the convergence log will appear before the request log. This may require some refactoring to fix.

These are logs on my local vm after creating some policies, executing a policy, and deleting a policy:

2013-11-25_19:07:59.14155
{
"is_error": false,
"event_type": "request.policy.create",
"data": {
"policies": [
{
"name": "scale up by 1",
"links": [
{
"href": "http://127.0.0.1:9000/v1.0/851153/groups/8c8d2dcf-41cc-46f0-9c56-da086e099fe7/policies/f0a9731d-d0d0-4a46-abcd-4987435a9329/",
"rel": "self"
}
],
"cooldown": 5,
"type": "webhook",
"id": "f0a9731d-d0d0-4a46-abcd-4987435a9329",
"change": 1
},
{
"name": "scale down by 1",
"links": [
{
"href": "http://127.0.0.1:9000/v1.0/851153/groups/8c8d2dcf-41cc-46f0-9c56-da086e099fe7/policies/837ad374-d124-4d95-bf13-4ce359a537eb/",
"rel": "self"
}
],
"cooldown": 5,
"type": "webhook",
"id": "837ad374-d124-4d95-bf13-4ce359a537eb",
"change": -1
}
]
},
"@timestamp": 1385406479.141083,
"_message": "Created at least one policy.",
"scaling_group_id": "8c8d2dcf-41cc-46f0-9c56-da086e099fe7",
"host": "ubuntu",
"request_ip": "127.0.0.1",
"tenant_id": "851153",
"@version": 1,
"transaction_id": "6ef2c066-ae16-4304-a56a-c819859b003e",
"audit_log": true
}
^[[B^C
2013-11-25_19:09:13.14705
{
"is_error": false,
"event_type": "convergence.scale_up",
"tenant_id": "851153",
"@timestamp": 1385406553.14698,
"_message": "Starting 1 new servers to satisfy desired capacity",
"convergence_delta": 1,
"scaling_group_id": "8c8d2dcf-41cc-46f0-9c56-da086e099fe7",
"desired_capacity": 3,
"host": "ubuntu",
"current_capacity": 2,
"pending_capacity": 1,
"@version": 1,
"transaction_id": "92987541-cfe8-4638-b25d-128c94b272de",
"audit_log": true
}
2013-11-25_19:09:39.12887
{
"is_error": false,
"event_type": "request.policy.delete",
"tenant_id": "851153",
"@timestamp": 1385406579.128812,
"_message": "Deleted scaling policy.",
"scaling_group_id": "8c8d2dcf-41cc-46f0-9c56-da086e099fe7",
"host": "ubuntu",
"request_ip": "127.0.0.1",
"policy_id": "f0a9731d-d0d0-4a46-abcd-4987435a9329",
"@version": 1,
"transaction_id": "553592d1-73b9-451c-8087-d7ec27c1c24c",
"audit_log": true
}