Skip to content

Adding job labels for FinOps#673

Merged
hadley merged 5 commits into
r-dbi:mainfrom
JulianUmbhau:job_labels
May 11, 2026
Merged

Adding job labels for FinOps#673
hadley merged 5 commits into
r-dbi:mainfrom
JulianUmbhau:job_labels

Conversation

@JulianUmbhau
Copy link
Copy Markdown
Contributor

@JulianUmbhau JulianUmbhau commented Feb 23, 2026

Added labels to job creation calls for FinOps purposes
Labels can be set globally via:
options(bigrquery.labels = list(env = "prod", team = "analytics"))
Labels are then automatically attached to all BigQuery job requests (query, load, extract, copy).

  • Added check_labels() to validate labels against BigQuery's key/value constraints before sending
  • Added bigrquery.labels default option (NULL) in .onLoad()
  • Added tests for check_labels()
  • Fixed pre-existing inconsistency: auto_unbox = TRUE was already present in bq_post/bq_patch but was missing from the toJSON calls in bq_perform_upload and bq_parse_single

Fixes #652

@hadley
Copy link
Copy Markdown
Member

hadley commented Feb 25, 2026

Would you mind pointing me to the BigQuery docs for labels?

In the interest of using the simplest possible data structure, is there a reason to use a list instead of a named character vector?

@JulianUmbhau
Copy link
Copy Markdown
Contributor Author

Would you mind pointing me to the BigQuery docs for labels?

In the interest of using the simplest possible data structure, is there a reason to use a list instead of a named character vector?

Here are the docs: https://docs.cloud.google.com/bigquery/docs

And you are correct, the list was unnecessary. I have changed that to a named chr vector.

@schifferl
Copy link
Copy Markdown

Adding my support for this feature – it is important for cost allocation in production applications that use R to communicate with BigQuery.

Copy link
Copy Markdown
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! A few comments on the overall approach and implementation below.

I assume you have tested this interactively?

Comment thread R/bq-perform.R Outdated
Comment thread R/bq-perform.R Outdated
Comment thread R/utils.R Outdated
Comment thread R/utils.R Outdated
Comment thread R/utils.R Outdated
Comment thread R/utils.R Outdated
Comment thread R/bq-parse.R Outdated
@JulianUmbhau
Copy link
Copy Markdown
Contributor Author

JulianUmbhau commented Mar 6, 2026

Thanks for working on this! A few comments on the overall approach and implementation below.

I assume you have tested this interactively?

Ofc, thank you the comments!

We use this every day, but I have now tested it more thoroughly.

I had to change the character vector back to list - i hadn't tested that change well enough.
The jsonlite::toJSON function drops the names of the character vector and changes it to an array. And the auto_unbox = TRUE is needed to ensure the value is not wrapped in an array.

@hadley hadley added this to the v1.6.2 milestone Apr 29, 2026
@hadley
Copy link
Copy Markdown
Member

hadley commented Apr 30, 2026

@JulianUmbhau could you please double check that my changes haven't broken anything for you?

@hadley
Copy link
Copy Markdown
Member

hadley commented May 8, 2026

@JulianUmbhau I'm going to release early next week so I'd really appreciate a look if you have the time 😄

JulianUmbhau and others added 5 commits May 11, 2026 13:35
* Make it an explicit argument
* Move `check_labels()` to standard structure
* Add news bullet
@hadley hadley merged commit 334a076 into r-dbi:main May 11, 2026
14 checks passed
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.

Add support for labels in BigQuery jobs

3 participants