Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, all
k8sv1.Object
s are constantly bulk upserted, regardless of whether their properties or just their sub-resources have changed. For example, when a container is terminated, the pod is updated first and then all its containers (not just the one that was terminated),pod_{owner, volume,condition}
, and so on. As you can see, so many useless queries are executed just because a container has changed its state. This PR addresses exactly this shortcoming of config sync.Initial Sync
To make this work reliably, all tables have a properties checksum attribute from now on, which contains the
SHA1
of all columns. In addition, each of the sync pipelines provides its own internal cache store, which is populated with the respective properties checksum when initially starting the sync. This takes place as follows:Sync#warmup()
retrieves all database records for the specified sync subject and their relations usingDB#YieldAll()
recursively. All base types (i.e. entities implementing thecontracts.Resource
interface) are handed over to the controller, where the fingerprint of all entities loaded from the DB is added to the sync cache store simultaneously.icinga-kubernetes/pkg/sync/v1/sync.go
Lines 117 to 126 in 30975ad
The
Fingerprint
is tiny and usually contains thePropertiesChecksum
, the entity and its parent unique identifier likeID
,PodId
. However, when the sync pipeline is being started with theNoWarmup
sync feature, the process described above is a no-op.Upsert events
When k8s propagates an
Update/Add
event for an object, the objects are always bulk upserted. Here's what this process looks like.contracts.Entity
interface, it will just forward that entity to the next stage.contracts.Entity
, it applies thepreExecution
callback on this entity (which should compare the checksums), and forwards the entity to theforward
chan only if the filter function returns true and initiates a database upsert stream.relation.Stream()
method to the respective cached stream of the relation.However, when the first item doesn't satisfy the
database.HasRelations
interface, it will just use only two stages for the streamed entities to be upserted:preExecution
callback (if any) on each of the entities. This won't forward entities for which thepreExec
function didn't also return true as well.Delete events
The workflow for delete events is quite similar to that of upsert events but operates only by ID and not by an entire entity object.