Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
feat(dataset): Phase 4 — submit to jobs-manager + watch + summary (#152)#10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b5ff6d
feat(dataset): Phase 4 — submit to jobs-manager + watch + summary (#152)
saadqbal 257c8ef
fix(submit): enforce JobWatchTimeout + flush parser + typed watch err…
saadqbal 5694560
fix(submit): zero-metric finalize + namespace check + fresh ctx for f…
saadqbal 466eb54
fix(submit): port-forward to jobs-manager from off-cluster (Bugbot r3)
saadqbal cf82636
fix(submit): pick most-recent useful-phase Pod, not items[0] (Bugbot r4)
saadqbal 0b02cd4
fix(submit): Pod-wait timeout = Detached (not failed); non-blocking e…
saadqbal cc72c59
fix(submit): JobWatchTimeout-during-stream = Detached, not exit 9
saadqbal 9f02cf8
fix(submit): per-reason detach message (Bugbot r7)
saadqbal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Package submit owns the `tracebloc dataset push` Phase 4 step: | ||
| // POST the synthesized ingest spec to jobs-manager's | ||
| // /internal/submit-ingestion-run endpoint, then watch the ingestor | ||
| // Job the cluster spawns in response. | ||
| // | ||
| // Phase 4 sits between Phase 3's stage Pod (which lays files on the | ||
| // PVC) and Phase 5's release distribution. The protocol is the same | ||
| // one tracebloc/client's ingestor subchart's post-install hook uses | ||
| // today — see ingestor/templates/configmap-ingest-config.yaml. | ||
| // Keeping the protocol identical means the CLI and the helm flow | ||
| // are interchangeable at the cluster's API surface, and the chart | ||
| // stays a fully-supported alternative for ops folks who prefer it. | ||
| // | ||
| // The package is split into: | ||
| // - body.go (this file): synthesize the POST body | ||
| // - client.go: HTTP client + bearer token + 4xx framing | ||
| // - watch.go: poll Job + stream Pod logs | ||
| // - summary.go: parse the 📊 INGESTION SUMMARY banner | ||
| // - submit.go: top-level orchestrator | ||
| package submit | ||
| import ( | ||
| "crypto/rand" | ||
| "encoding/hex" | ||
| "fmt" | ||
| ) | ||
| // SubmitRequest is the wire shape POSTed to jobs-manager's | ||
| // /internal/submit-ingestion-run. Field names mirror the chart's | ||
| // ingestor/templates/configmap-ingest-config.yaml body.json key | ||
| // for-key so the chart and the CLI are interchangeable on the | ||
| // server side. | ||
| // | ||
| // json struct tags are explicit-snake so a future re-import via | ||
| // encoding/json doesn't silently produce mixedCase keys. | ||
| type SubmitRequest struct { | ||
| // IngestConfig is the customer's ingest spec as a verbatim | ||
| // YAML string. jobs-manager re-parses + revalidates this | ||
| // server-side. We don't re-marshal — the CLI's Phase 3 spec | ||
| // synthesis already produced canonical YAML. | ||
| IngestConfig string `json:"ingest_config"` | ||
| // IdempotencyKey is the per-invocation replay token. | ||
| // jobs-manager records this in its idempotency-key table; a | ||
| // second POST with the same key returns the SAME job_name as | ||
| // the first (with replay=true) instead of spawning a new Job. | ||
| // | ||
| // Default is a fresh UUID-ish 16-byte hex string per | ||
| // invocation; `--idempotency-key <s>` overrides for the | ||
| // at-most-once-across-attempts case where the customer | ||
| // genuinely wants retry-safety across multiple CLI runs. | ||
| IdempotencyKey string `json:"idempotency_key"` | ||
| // ImageDigest optionally pins the ingestor container image. | ||
| // Empty = let jobs-manager use the cluster's configured | ||
| // default (set by the parent client chart's | ||
| // `images.ingestor.digest`, kept current by the auto-upgrade | ||
| // cronjob). Setting it locks the run to a specific image, | ||
| // matching the chart's --set image.digest=... override path. | ||
| // | ||
| // `omitempty` on the JSON tag means jobs-manager sees no | ||
| // image_digest key at all when this is empty, which is the | ||
| // well-tested default-image code path on the server side. | ||
| ImageDigest string `json:"image_digest,omitempty"` | ||
| } | ||
| // BuildRequest is the constructor used by the orchestrator. Both | ||
| // IngestConfig (the YAML the CLI already synthesized in Phase 3) | ||
| // and the optional ImageDigest flow through unchanged; the | ||
| // idempotency key is the only non-trivial bit. | ||
| // | ||
| // If override is empty, a fresh 16-byte hex string is generated | ||
| // from crypto/rand. UUID-shaped without the dashes — the chart's | ||
| // own helper does the same (ingestor.idempotencyKey in | ||
| // _helpers.tpl), so server-side hash-table lookups are uniform | ||
| // across both flows. | ||
| func BuildRequest(ingestYAML string, idempotencyKeyOverride, imageDigest string) (*SubmitRequest, error) { | ||
| key := idempotencyKeyOverride | ||
| if key == "" { | ||
| raw := make([]byte, 16) | ||
| if _, err := rand.Read(raw); err != nil { | ||
| return nil, fmt.Errorf("generating idempotency key: %w", err) | ||
| } | ||
| key = hex.EncodeToString(raw) | ||
| } | ||
| return &SubmitRequest{ | ||
| IngestConfig: ingestYAML, | ||
| IdempotencyKey: key, | ||
| ImageDigest: imageDigest, | ||
| }, nil | ||
| } | ||
| // SubmitResponse is jobs-manager's 201 reply. job_name is the | ||
| // ingestor Job watch.go will poll; namespace is the resolved API | ||
| // namespace (usually the same one the CLI POSTed to, but | ||
| // jobs-manager can in principle redirect cross-namespace). | ||
| // | ||
| // Replay distinguishes "we just spawned this Job" (replay=false) | ||
| // from "we already have a Job for this idempotency key, here it | ||
| // is" (replay=true). The CLI prints a different lifecycle banner | ||
| // for each — replay means "another invocation already kicked | ||
| // this off; we're attaching to it." | ||
| type SubmitResponse struct { | ||
| JobName string `json:"job_name"` | ||
| Namespace string `json:"namespace"` | ||
| Replay bool `json:"replay"` | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.