dropbox / nsot

Network Source of Truth is an open source IPAM and network inventory database
https://nsot.readthedocs.io
Other
399 stars 66 forks source link

Change diffs and performance improvements #290

Closed nickpegg closed 7 years ago

nickpegg commented 7 years ago

Some indicies were added to the Change object, notably on change_at as well as a couple of common lookups: (resource_name, resource_id) and (resource_name, event). These greatly speeds up lookups, especially the change_at index which for example makes the CLI command nsot changes list -l 5 no longer take seconds to return data.

Additionally I added a diff API endpoint to /changes/, which is a thin wrapper around a new diff() method on Change. What this does is take the JSON representations of the given resource at its current state and the state before the Change happened, and returns a unified diff of those two.

Here's an example of what the API returns, taken from the updated CLI that supports this:

$ nsot changes list -i 2946025 diff
  {
    "attributes": {
      "facility": "nrt1", 
      "metro": "nrt", 
-     "monitor": "ignored"
?                 ^^^ ^

+     "monitor": "collected"
?                 ^ ^^^^^

    }, 
    "hostname": "jawn", 
    "id": 29936, 
    "site_id": 1
  }
jathanism commented 7 years ago

:shipit: