Repository navigation
Conversation
…agent provider When INTERNAL_API_URL_CHMURA_SECONDARY is set, hosted jobs of organizations with the secondary_hosted_agent_provider feature occupy their agent from that provider, which serves the same chmura API. Each job records the provider that gave it its agent (jobs.agent_provider), so the release goes back to the same one. A not-found answer from the second provider leaves only that job waiting instead of pausing its machine type for every organization. Without the variable nothing changes.
github_hooks runs the jobs table's migrations; zebra's copy only builds its test database. Where the column exists, the migration does not lock jobs. Otherwise it adds the column in a short transaction whose ALTER gives up after 5 s waiting for its lock instead of queueing every query on jobs.
The protoc image the Makefile uses produced these from cache.proto, which gains GetS3Credentials, and the new registry.proto with RegistryService.GetCredentials. The existing cache modules are unchanged.
…t provider Hosted jobs of organizations served by the secondary agent provider get temporary S3 credentials for their project's cache prefix and container registry credentials for their organization, both from cachehub, instead of the SFTP cache. The provider is decided once per job, with the same rule the dispatcher uses. - Credentials are asked to stay valid for the job's time limit plus an hour, at most 12 hours. - Forked pull requests get neither. An approval that enabled the cache still grants the S3 cache, never the registry. - A job that sets any SEMAPHORE_CACHE_* or SEMAPHORE_REGISTRY_* variable itself, in its YAML or its secrets, gets none of that group. - The S3 key, secret and session token and the registry password are blanked when the request is sanitized. - When cachehub fails, the job runs without them. Jobs of other organizations, and every job when no secondary provider is configured, are unchanged.
…cupy requests After a NOT_FOUND the dispatcher stops asking the primary provider for the rest of the machine type's jobs in that tick, so a provider that sizes a warm pool from refused requests sees at most one batch of a burst. Each occupy now carries how many of the tick's jobs wait for the same provider (counted from the ids the tick already read; one grouped query by id only when a secondary provider is configured), plus the job's organization and project for cost tagging. Providers that do not know the fields ignore them; 0 means unknown.
The S3 cache and registry credentials last at most 12 hours, while a job can run for 24. Zebra now asks cachehub for a refresh grant scoped to the job along with the credentials, valid for the job's time limit plus an hour and at most 25 hours. With CACHEHUB_JOB_API_URL set, a job that got credentials also gets SEMAPHORE_CACHE_S3_REFRESH_TOKEN and _REFRESH_URL, and SEMAPHORE_REGISTRY_REFRESH_TOKEN and _REFRESH_URL. Jobs that get no credentials, such as forked pull requests, get no grant. Both tokens are sanitized like the credentials. Jobs also get SEMAPHORE_CACHE_S3_EXPIRES_AT and SEMAPHORE_REGISTRY_EXPIRES_AT (unix seconds), so clients can refresh before the credentials expire. The generated proto modules gain the new request and response fields.
The secondary agent provider publishes AgentLost on the hosted_agent_events exchange when the machine under an occupied agent is taken back or terminated. Until now such a job kept running until its execution time limit. A new consumer finishes the job as failed, with a reason shown on the job page (stopped by the infrastructure provider, terminated, or lost). It is not retried. - Already finished jobs, self-hosted jobs, jobs on a different agent and jobs whose agent is not from the secondary provider are left as they are, so redelivered messages are harmless. - The job row is locked while it is checked and finished. The finished callback now locks it too, so a callback racing a loss can no longer overwrite the result. - The worker starts where the teardown callback worker runs and a secondary provider endpoint is configured. START_AGENT_LOST_WORKER set to true or false overrides that. - The message stub is generated from hosted_agent_events.proto.
…e tick on it Each occupy now carries how many of the tick's jobs for its provider wait from that job onward, itself included, so jobs the same tick served ahead of it are not counted again. A failure to build the count (a DB error) is logged and counted, and the tick dispatches its jobs without it.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff380b72bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| org_id = job.organization_id | ||
| spec = Job.decode_spec(job.spec) | ||
| job_type = Job.detect_type(job) | ||
| secondary? = secondary_provider?(job) |
There was a problem hiding this comment.
Persist provider selection with the prepared request
When the feature changes, or job-request and dispatcher replicas have different feature-cache state, this line can prepare S3/registry credentials for the secondary provider while HostedAgent.occupy/2 later recomputes the flag and routes the job to the default provider, or vice versa. Because the provider-specific backend and credentials are already baked into job.request, affected jobs can lose cache or registry access; persist the selection when constructing the request and have dispatch honor it.
Useful? React with 👍 / 👎.
| secrets = all_secrets.job_secrets ++ List.flatten(all_secrets.container_secrets) | ||
|
|
||
| Enum.map(spec_env_vars, & &1["name"]) ++ | ||
| Enum.flat_map(spec.agent.containers, fn c -> Enum.map(c.env_vars, & &1.name) end) ++ | ||
| Enum.flat_map(secrets, fn s -> Enum.map(s.env_vars, & &1["name"]) end) |
There was a problem hiding this comment.
Exclude container-only variables from main-job overrides
When a service container or its container-scoped secret defines any SEMAPHORE_CACHE_* or SEMAPHORE_REGISTRY_* variable, adding those names here causes Cache.env_vars/4 or Registry.env_vars/2 to remove the entire credential group from the main job. Container variables are encoded separately under request["compose"]["containers"], so they cannot override the main request variables; only main-job YAML variables and job-scoped secrets should suppress these credentials.
Useful? React with 👍 / 👎.
The hosted agent provider publishes AgentUpdated when an occupied agent is reached at a new address or ports. A new consumer replaces the job's agent ip address, ctrl port and ssh port, so log fetch, job stop and SSH debug talk to the agent where it is now. The job's state is never changed. Delivery is at least once and not ordered: the job records when its address was observed (new jobs column agent_address_updated_at) and only a newer update replaces it. Updates for finished, unknown or other-provider jobs, for another agent, for idle agents, and malformed ones are dropped. The consumer starts where the lost-agent consumer does, with its own START_AGENT_UPDATED_WORKER override.
AgentUpdated now carries an HMAC-SHA256 signature over its fields, keyed with AGENT_EVENTS_SIGNING_KEY. Unsigned or wrongly signed messages are dropped, and so is every message while no key is configured, so nothing else that can publish to the exchange can point a job's agent traffic at another address. Agent ids must be UUIDs and the agent type a single line, which keeps the signed input unambiguous.
AGENT_EVENTS_SIGNING_KEYS takes a comma separated list (entries trimmed, empty ones skipped, each at least 32 bytes); a message signed with any of them is accepted. Without valid keys the agent updated worker is not started: zebra logs an error and counts agent_updated.worker.disabled, and every other worker runs as usual. Unsigned or wrongly signed messages are moved to the worker's dead letter queue instead of being dropped, and counted per outcome in agent_updated.processed. The signing input is pinned in tests against a fixed digest and an end to end message. Also adds the worker start tests that the first commit was missing.
… queue Workers.boot/0 decides the workers at startup. When the agent updated worker is asked for but has no valid signing keys, it logs that once, sets the agent_updated.worker.disabled gauge to 1 (0 otherwise), and still declares and binds the worker's queue the way the consumer would, so updates wait there until the worker runs instead of being lost. The health check keeps calling active/0, which no longer logs. Rejected messages are copied to the dead letter queue with a publisher confirm before the original is acked; without a confirm the original is retried.
[ui] Resources tab on the job page: commands flamechart, time range, one chart per resource, command rollups, callouts [ui] workflow page: one icon per job box; the side bar opens on click and loads that job only [ui] running jobs update about once a second while the page has focus and every 15 s without it, following a cursor; errors back off [api] Front.JobMetrics reads job metrics from the metrics service (JOB_METRICS_API_URL), scoped to the job's organization, with a field whitelist [api] finished jobs use a downsampled series plus service totals; reads are bounded in pages and time, partial data is labelled [config] feature job_resource_metrics: with it off, no tab, no icon, no side bar and no calls to the metrics service [test] flag on and off, data and no data, service errors, organization mismatch, field whitelist, polling, paging and deadlines
ff380b7 to
7931801
Compare
Secondary hosted agent provider in zebra, job agent address updates, and a job resources tab in front. Replaces #1421, #1422, #1423 and #1457.
secondary_hosted_agent_providerfeature flag. Fails jobs whose machine is lost, reports the waiting count and project on occupy, and passes cache credential refresh grants to jobs.AgentUpdatedevents (HMAC with rotating keys, newer-only updates, rejected messages dead-lettered). The worker stays off without valid keys.job_resource_metricsfeature. With the feature off nothing changes.