Add trigger type reference based filtering to the /v1/triggerinstances API endpoint #4151
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.
This pull request adds TriggerType reference based filtering to the
/v1/triggerinstances
API endpoint as discussed with @enykeev.Example usage -
curl http://127.0.0.1:9101/v1/triggerinstances?trigger_type=core.st2.generic.actiontrigger
.Note on the implementation detail - We only store Trigger reference on the TriggerInstance object so to be able to filter on TriggerType reference we need to do that via Trigger reference on the TriggerInstance object.
In relational database that would be a simple join and in non-relational database that would be a simple query in case Trigger is correctly denormalized and trigger reference also stored on the TriggerInstance object (that's not the case for our schema right now).
Recent versions of MongoDB also support simple aggregate queries and joins, but our API filtering code is not designed to support it yet so I went with a simpler "two queries" approach.
That works fine in this scenario because there will likely never be many thousand of Trigger objects in the database.