Emit account_id and job metadata as Kubernetes pod labels#310
Open
wesleyjellis wants to merge 2 commits into
Open
Emit account_id and job metadata as Kubernetes pod labels#310wesleyjellis wants to merge 2 commits into
wesleyjellis wants to merge 2 commits into
Conversation
archf
reviewed
Jul 7, 2026
Rather than weaving the account_id job variable into the pod name (which risks the 63-char limit and OpsLevel-side naming conventions), stamp descriptive labels on the job pod for observability: app.kubernetes.io/name: opslevel-job opslevel.com/account-id: <account_id> (when the job sets it) opslevel.com/job-id: <job id> opslevel.com/mode: <faktory|api> These enable native DataDog filtering via podLabelsAsTags with no pod name parsing. Labels are added after building the PDB label selector so they stay out of the selector, which the instance label already makes unique. Adds a getRunnerJobVariable helper (named explicitly since a similar helper is anticipated for egress proxies). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
3cc6b31 to
45b7d16
Compare
The OpsLevel API uppercases/sanitizes variable keys before sending them to the runner (RunnerJobType#format_key_as_valid_env_var_name), so the account id arrives as ACCOUNT_ID, not account_id. The previous lookup used the lowercase key and never matched, leaving opslevel.com/account-id always empty. Match the uppercase key instead. Also read a JOB_TYPE variable into an opslevel.com/job-type label so pods can be filtered by job kind (template). This is a no-op until the OpsLevel API emits JOB_TYPE as a derived variable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
archf
reviewed
Jul 10, 2026
archf
left a comment
Contributor
There was a problem hiding this comment.
This is super cool, thanks a heap!
Let's also add a changie record and we're good to go!
| // name. Added after building the selector so they stay out of the PDB | ||
| // selector, which the instance label already makes unique. | ||
| labels["app.kubernetes.io/name"] = "opslevel-job" | ||
| labels["opslevel.com/job-id"] = id |
Contributor
There was a problem hiding this comment.
can we 'dup' and add short form keys as well?
e.g.:
labels["accountiD"] = accountID ...
[...]That would be cool for a CLI speedrun instead of typing out the long form.
e.g. kubectl get pods -l accountID=XXX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Emit account/job metadata as Kubernetes pod labels rather than weaving it
into the pod name (which risks the 63-char limit and OpsLevel-side naming
conventions). This enables native DataDog filtering via
podLabelsAsTagswithno pod-name parsing. The pod/ConfigMap/PDB name is unchanged.
Labels stamped on each job pod:
app.kubernetes.io/nameopslevel-jobopslevel.com/modefaktory|apiopslevel.com/account-idopslevel.com/job-idopslevel.com/job-typeLabels are added after building the PDB label selector so they stay out of the
selector, which the
app.kubernetes.io/instancelabel already makes unique.Also adds a
getRunnerJobVariablehelper (named explicitly since a similarhelper is anticipated for egress proxies).
Fixes
ACCOUNT_IDlookup: the OpsLevel API uppercases/sanitizes variable keysbefore sending them (
RunnerJobType#format_key_as_valid_env_var_name), so theaccount id arrives as
ACCOUNT_ID, notaccount_id. The original lookup usedthe lowercase key and never matched, leaving the label always empty. Now
matches the uppercase key.
Requires a companion OpsLevel change
opslevel.com/job-typeis a no-op until the OpsLevel API emits aJOB_TYPEvariable. The job's kind is its template (
Runners::JobRun#template_name,~13 values) and is currently only carried by the DB
template_idcolumn — it isnever sent to the runner. To light up the label, add a derived variable in
app/models/runners/job_run.rb#derived_variables(alongsideJOB_ID/ACCOUNT_ID):Sending a clean slug from the server keeps the label value valid (raw
template_namecontains::, which is invalid in a k8s label value) andlow-cardinality.
Test plan
go build ./...go test ./pkgpassesTestGetRunnerJobVariable_*cover the helper, including a case-sensitivityguard for the
ACCOUNT_IDbug🤖 Generated with Claude Code