Skip to content

Add Tag field to Run table and controller - #140

Open
amathuria wants to merge 5 commits into
ceph:mainfrom
amathuria:wip-amat-add-metadata-tag-74166
Open

amathuria wants to merge 5 commits into
ceph:mainfrom
amathuria:wip-amat-add-metadata-tag-74166

Conversation

@amathuria

Copy link
Copy Markdown
Contributor

No description provided.

Add an optional metadata string tag to runs, allowing users to associate
a tag with a collection of runs.

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
Support tag in run creation (POST) and query-param filtering (?tag=foo).

Add TagsController/TagController for path-based access (/runs/tag/foo/)
and wire tag into all existing filter controllers for composable queries.

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
@amathuria
amathuria requested a review from zmc March 13, 2026 18:33
@amathuria

Copy link
Copy Markdown
Contributor Author

@zmc There's no PUT/PATCH on RunController - it only has GET and DELETE. So if we want to stick to the current workflow, tags can only be added at run creation.
If we want the option to UPDATE a Run, you can let me know - keeping the PR in draft state till then.

@kshtsk

kshtsk commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Do I understand correctly this only implements a single tag? I would suggest to implement tags, so a run can have several tags.

@zmc

zmc commented Mar 17, 2026

Copy link
Copy Markdown
Member

@amathuria Thanks!
I think we may as well add a PUT at this point. I think we ought to start moving some of the items we duplicate across Jobs into the Run object, and we'll need to be able to modify them directly to do that. Further in the future we could choose to implement PATCH, but the semantics are quite different so that's probably best left to a dedicated effort.
Diffs like this make me look forward to us moving away from the path-based Run routing we use currently :)
Thinking about @kshtsk's comment about multiple tags, and I think maybe we ought to just go ahead and store an array of tags in each Run row, even if the main use-case is only one tag per run. What do you think?

@batrick

batrick commented Mar 24, 2026

Copy link
Copy Markdown
Member

Thinking about @kshtsk's comment about multiple tags, and I think maybe we ought to just go ahead and store an array of tags in each Run row, even if the main use-case is only one tag per run. What do you think?

Actually, this was a gap in my feature request. I think multiple tags is best. Many thanks to @kshtsk thinking of that.

I've updated the ticket: https://tracker.ceph.com/issues/74166

@amathuria

Copy link
Copy Markdown
Contributor Author

@amathuria Thanks! I think we may as well add a PUT at this point. I think we ought to start moving some of the items we duplicate across Jobs into the Run object, and we'll need to be able to modify them directly to do that. Further in the future we could choose to implement PATCH, but the semantics are quite different so that's probably best left to a dedicated effort. Diffs like this make me look forward to us moving away from the path-based Run routing we use currently :) Thinking about @kshtsk's comment about multiple tags, and I think maybe we ought to just go ahead and store an array of tags in each Run row, even if the main use-case is only one tag per run. What do you think?

@zmc @batrick multiple tags makes sense to me! I'll update the PR soon.
Thanks @kshtsk!

Replace Run.tag with Run.tags (JSONType list) and add PUT /runs/<name>/
to update tags.
Update tag filtering/listing to work with tag arrays,
including comma-separated ?tag=
We have to add a cast to UnicodeText for filtering to avoid JSONType bind-param JSON encoding.

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
@amathuria

Copy link
Copy Markdown
Contributor Author

@kshtsk @zmc @batrick I have added the multi-tag support and PUT to RunController.
Let me know what you think.
The CI is failing due to a new unit test I have added failing - I'm looking into this.

Comment thread paddles/controllers/runs.py Outdated

def latest_runs(fields=None, count=conf.default_latest_runs_count, page=1):
query = Run.query.order_by(Run.posted.desc())
def latest_runs(fields=None, count=conf.default_latest_runs_count, page=1, tag=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we want tags=None?

Comment thread paddles/controllers/runs.py Outdated
# JSON-encoded unless we compare as plain text:
tags_text = cast(Run.tags, UnicodeText)
for t in tag.split(','):
query = query.filter(tags_text.contains('"%s"' % t.strip()))

@kshtsk kshtsk Apr 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor)

for tag in (t.strip() for t in tags.split(',')):
    . . . filter(tags_text.contains(tag))

so if tags_text is json "[abc,xyz]" the contains('bc') matches?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tags_text is comma separated text wouldn't it be less effective to use:

run_tags = (t.strip() for t in tags_text.split(','))
for tag in (t.strip() for t in tags.split(',')):
   query = query.filter(tag in run_tags)

@batrick

batrick commented May 27, 2026

Copy link
Copy Markdown
Member

Any update on this?

@amathuria

Copy link
Copy Markdown
Contributor Author

Any update on this?

Yes, I am testing it with the Teuthology changes @anshuman-agarwala is working on.
Should be done by next week.

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
@amathuria
amathuria marked this pull request as ready for review June 3, 2026 07:17

@zmc zmc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I had not seen the update to this PR until today! I have some changes I would like to see:

  • we would need a db migration but the PR doesn't include one
  • I might rather drop the controller path-based query implementation for this feature; it was never a great pattern
  • the tags column should probably have an index since it's being queried
  • run_tags_text_has_element's approach of manually parsing the json string is fragile and also quietly allows searching by wildcard ("%", "_").

Regarding the column type, I had liked the idea of using the ARRAY type but sadly sqlite doesn't support it.
It looks like if we use the native JSON type, we won't be able to avoid having to use different sqlalchemy APIs for postgres and sqlite. I don't know how much we should care about that, but I don't love it.
I wonder if we should just use a separate tags table - it would be safer and more performant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants