sensu / sensu-go

Simple. Scalable. Multi-cloud monitoring.
https://sensu.io
MIT License
1.01k stars 177 forks source link

[SPIKE] Determine the cost of adding support for Not-Modified and Created indicators with postgres #4985

Closed fguimond closed 1 year ago

fguimond commented 1 year ago

See if features from the Postgres API such as rows affected can be used to implement #4631 without adding complexity. The original issue's milestone should be updated based on the output of this spike.

echlebek commented 1 year ago

While no feature can ever be added without also adding complexity, some features need more complexity than others. This feature can be added with fairly minimal complexity.

Knowing if a resource can be created or not is a simple matter of looking at the xmax system column. When xmax = 0, the row was inserted. Otherwise, it will not equal 0.

Knowing if a resource should be updated or not is a matter of computing and storing the entity tag for the resource. We can easily have postgres do this for us with the pgcrypto extension, which is available by default on RDS and most other deployments. The etag can be stored in a new etag column, which will hold the checksum of the resource. If the database detects that the user is attempting to store a resource with the same etag, it can report that the resource wasn't modified by returning the existing etag, and the updated etag, and letting the user compare them.