Skip to content

Buildkite::TestCollector.tag_execution(key, value)#240

Merged
pda merged 1 commit intomainfrom
per-execution-tags
Feb 21, 2025
Merged

Buildkite::TestCollector.tag_execution(key, value)#240
pda merged 1 commit intomainfrom
per-execution-tags

Conversation

@pda
Copy link
Member

@pda pda commented Feb 19, 2025

Draft support for per-execution tagging.

  • Decide if Buildkite::TestCollector.tag_execution(key, value) is an okay API for this.
  • Add some test coverage.

I don't love adding yet another Thread.current[:_buildkite…] fiber-local (global-ish) name, but I don't see a really good place to put these tags otherwise, and really it's an inconsequential implementation detail, compared to the public API in front of it. I don't think they really belong in Buildkite::TestCollector::Tracer (we're tagging the execution, not the potentially-nested traces therein) and adding them there just adds complexity.

@pda pda changed the title Buildkite::TestCollector.tag_execution(key, value) Buildkite::TestCollector.tag_execution(key, value) Feb 19, 2025
@pda pda marked this pull request as ready for review February 21, 2025 03:50
@pda pda requested a review from a team as a code owner February 21, 2025 03:50
@pda pda force-pushed the per-execution-tags branch from ffc22e2 to 1176ad4 Compare February 21, 2025 03:50
Thread.current[:_buildkite_tags] = nil

if !tracer.nil?
Thread.current[:_buildkite_tracer] = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there was a reason that this is put behind this if nil condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's just that there's no point clearing it if it was nil to begin with.
But AFAIK there's also no harm in it, and grouping them together in source code felt better.

Something worth noting: Thread.current[] works differently to other things in Ruby; there's no “delete” operation for a key; assigning nil actually deletes it, so this line changes Thread.current.key?(:_buildkite_tracer) from true to false.

tags = Thread.current[:_buildkite_tags]
raise "_buildkite_tags not available" unless tags

unless key.is_a?(String) && value.is_a?(String)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider supporting String like classes like numbers and booleans?

Should we be more strict about sanitisation or should we handle that server side?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure, so I started strict and we can expand it to be more permissive without breaking anything for anyone.
(Can't do the other direction)

Copy link
Contributor

@gchan gchan left a comment

Choose a reason for hiding this comment

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

:shipit:

@pda pda merged commit b5a582b into main Feb 21, 2025
1 check passed
@pda pda deleted the per-execution-tags branch February 21, 2025 05:06
@pda pda mentioned this pull request Feb 21, 2025
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.

3 participants