tektoncd / results

Long term storage of execution results.
Apache License 2.0
77 stars 73 forks source link

Filter by labels and namespace in querying results #537

Closed xinnjie closed 1 year ago

xinnjie commented 1 year ago

Feature request

Support querying results filtered by labels and namespace

Use case

alan-ghelardi commented 1 year ago

Actually, this is possible nowadays for querying Records via CEL filters: data.metadata.labels["foo"] == "bar"

To query Results I'd recommend the following steps:

  1. Annotate the PipelineRun with the results.tektond.dev/resultAnnotations annotation by passing a JSON object with the values you'd like to use to identify the Result. For example:

    results.tekton.dev/resultAnnotations: {"foo":"bar"}
  2. Once the Result is archived, you can query it by using the following CEL filter: annotations["foo"] == "bar". Behind the scenes this CEL filter is translated to a Postgres JSON filter which behaves quite well even at scale with millions of entries in the db without restricting the query to a given parent. It's equivalent to search PipelineRuns from all namespaces by using a label selector (assuming that the foo above is a label). But you can use whatever value you want (e.g. a Git commit, a repository name, etc.).

I need to document these things, but lately I haven't been managing to find a spare time to do so 😢 . Anyhow, e2e tests show how to use the aforementioned annotation.

xinnjie commented 1 year ago

This feature is pretty great. Seems that only some documentation works need to be done.