Skip to content
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

[ui] Jobspec UI block: Descriptions and Links #18292

Merged
merged 21 commits into from May 22, 2024

Conversation

philrenaud
Copy link
Contributor

@philrenaud philrenaud commented Aug 22, 2023

Adds a ui block to Nomad job specs. Users can define any number of links and a single description that will show up on the Job index page in the web UI:

image
from spec

job "fails_every_10" {

  ui {
    description = "A job that fails **every 10 allocations**, but a 1x [restart](https://nomadproject.io) and 1x <a href='https://hashicorp.com'>reschedule</a> means that a given allocation would have to fail 4x (initial, restarted, rescheduled, rescheduled+restarted) to be considered permanently failed, or 0.01% permanent failure rate (1/10,000 allocs)"
    link {
      label = "nomad"
      url = "https://nomadproject.io"
    }
    link {
      label = "Some Arbitrary String Label"
      url = "http://hashicorp.com/"
    }
  }

...

Notably, this supports markdown, so you can, for example, add a table with a jobspec like this:

job "ui-block-tester" {

  ui {
    description = <<EOT
| Name              | Team                 | Position | Average | HRs | Wikipedia Article                                          |
|-------------------|----------------------|----------|---------|-----|------------------------------------------------------------|
| Babe Ruth         | New York Yankees     | OF/P     | .342    | 714 | [Link](https://en.wikipedia.org/wiki/Babe_Ruth)            |
| Hank Aaron        | Atlanta Braves       | OF       | .305    | 755 | [Link](https://en.wikipedia.org/wiki/Hank_Aaron)           |
| Ted Williams      | Boston Red Sox       | OF       | .344    | 521 | [Link](https://en.wikipedia.org/wiki/Ted_Williams)         |
| Jackie Robinson   | Brooklyn Dodgers     | 2B       | .311    | 137 | [Link](https://en.wikipedia.org/wiki/Jackie_Robinson)      |
| Roberto Clemente  | Pittsburgh Pirates   | OF       | .317    | 240 | [Link](https://en.wikipedia.org/wiki/Roberto_Clemente)     |
EOT
    link {
      label = "nomad"
      url = "https://nomadproject.io"
    }
    link {
      label = "Some Arbitrary String Label"
      url = "http://hashicorp.com/"
    }
  }

...

image

Resolves #18127
Resolves #15706

@philrenaud philrenaud self-assigned this Aug 22, 2023
@philrenaud philrenaud linked an issue Aug 22, 2023 that may be closed by this pull request
@philrenaud philrenaud force-pushed the 18127-render-customizable-links-in-dashboard branch 2 times, most recently from 7f7a8ca to 524fe53 Compare August 22, 2023 19:50
@github-actions
Copy link

github-actions bot commented Aug 22, 2023

Ember Test Audit comparison

main da068a8 change
passes 1559 1562 +3
failures 0 0 0
flaky 0 0 0
duration 11m 21s 907ms 11m 20s 165ms -01s 742ms

@octdanb
Copy link

octdanb commented Nov 7, 2023

This is a great proposal, +1

api/jobs.go Outdated Show resolved Hide resolved
nomad/structs/structs.go Outdated Show resolved Hide resolved
},
},
Expected: &JobDiff{
Type: DiffTypeEdited,
Copy link
Member

Choose a reason for hiding this comment

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

Weirdly no, because there's an empty JobUIConfig block here, which the new job populates.

@@ -4554,6 +4594,7 @@ func (j *Job) Copy() *Job {
nj.Constraints = CopySliceConstraints(nj.Constraints)
nj.Affinities = CopySliceAffinities(nj.Affinities)
nj.Multiregion = nj.Multiregion.Copy()
Copy link
Member

Choose a reason for hiding this comment

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

This reads strangely but still works the same either way. After we do *nj = *j, then nj.UI and j.UI are pointing to the same location in memory. By doing nj.UI = nj.UI.Copy() we're copying that object to a new memory location and assigning that pointer to nj.UI but not j.UI.

For readability, it does feel like it'd make more sense to use j as the receiver for all 5 of these deep copy lines, but it's harmless.

@tgross tgross added the stage/needs-rebase This PR needs to be rebased on main before it can be backported to pick up new BPA workflows label May 17, 2024
@david-yu
Copy link
Contributor

Wondering what it would take to perhaps have a config flag that gates this functionality for the UI?

@philrenaud
Copy link
Contributor Author

@david-yu I believe a sentinel policy could target this block.

@david-yu
Copy link
Contributor

david-yu commented May 20, 2024

@david-yu I believe a sentinel policy could target this block.

That could possibly work. May be a good suggestion for a template to add?

@philrenaud philrenaud added the backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent label May 21, 2024
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Last item on the pointer on JobUIConfig.Links and this should be good-to-go

nomad/structs/structs.go Outdated Show resolved Hide resolved
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgross tgross dismissed Juanadelacuesta’s stale review May 22, 2024 18:27

Juanita is out and I've verified the PR addresses here concerns

@philrenaud philrenaud merged commit e8b77fc into main May 22, 2024
31 checks passed
@philrenaud philrenaud deleted the 18127-render-customizable-links-in-dashboard branch May 22, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent stage/needs-rebase This PR needs to be rebased on main before it can be backported to pick up new BPA workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Render customizable links in dashboard Description field
5 participants