-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[cli] UI URL hints for common CLI commands #24454
base: main
Are you sure you want to change the base?
Conversation
3621929
to
70dd502
Compare
70dd502
to
f251fd3
Compare
f251fd3
to
67f5207
Compare
b5d296b
to
67a6584
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few style guide nits
@@ -58,6 +58,11 @@ and the configuration is individual to each agent. | |||
- `label` <code>([Label]: nil)</code> - Configures a user-defined | |||
label to display in the Nomad Web UI header. | |||
|
|||
- `cli_url_links` `(bool: true)` - Controls whether CLI commands display hints | |||
about equivalent UI pages. For example, when running `nomad server members`, | |||
the CLI will show a message indicating where to find server information in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the CLI will show a message indicating where to find server information in | |
the CLI shows a message indicating where to find server information in |
@@ -106,7 +111,7 @@ header sent with the web UI response. | |||
- `text` `(string: "")` - Specifies the text of the label that will be | |||
displayed in the header of the Web UI. | |||
- `background_color` `(string: "")` - The background color of the label to | |||
be displayed. The Web UI will default to a black background. HEX values | |||
be displayed. The Web UI will default to a black background. HEX values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be displayed. The Web UI will default to a black background. HEX values | |
be displayed. The Web UI defaults to a black background. HEX values |
present tense (I know this clashes with the copious amounts of future tense already in the docs. Eventually I will address that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @philrenaud, I can see this being really useful.
I've added some inline comments after a first pass and will do some local testing as a followup. I have some slight trepidation that when using these commands an additional API call will be required to get the configuration value back, but I see its value and it's a fairly lightweight one.
Our CLI documentation includes the available flags for each command, so I think it would be nice to include this in the PR for completeness. Node status example.
@@ -0,0 +1,3 @@ | |||
```release-note:improvement | |||
cli: Added UI URL hints to the end of common CLI commands and a -ui flag to auto-open them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli: Added UI URL hints to the end of common CLI commands and a -ui flag to auto-open them | |
cli: Added UI URL hints to the end of common CLI commands and a `-ui` flag to auto-open them |
return fmt.Sprintf("%s/ui%s", client.Address(), path), nil | ||
} | ||
|
||
func (m *Meta) showUIPath(ctx UIHintContext) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like all callers ignore the error returned here. Do we expect this to be used in the future, should we check the error, or remove the return option from the function?
func DefaultUIConfig() *UIConfig { | ||
enabled := true | ||
return &UIConfig{ | ||
Enabled: true, | ||
Enabled: enabled, | ||
Consul: &ConsulUIConfig{}, | ||
Vault: &VaultUIConfig{}, | ||
Label: &LabelUIConfig{}, | ||
ContentSecurityPolicy: DefaultCSPConfig(), | ||
CLIURLLinks: &enabled, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove the variable instantiation by using the pointer.Of function:
func DefaultUIConfig() *UIConfig {
return &UIConfig{
Enabled: true,
Consul: &ConsulUIConfig{},
Vault: &VaultUIConfig{},
Label: &LabelUIConfig{},
ContentSecurityPolicy: DefaultCSPConfig(),
CLIURLLinks: pointer.Of(true),
}
}
path = strings.ReplaceAll(path, fmt.Sprintf(":%s", k), v) | ||
} | ||
|
||
return fmt.Sprintf("%s/ui%s", client.Address(), path), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might lead to confusion where the CLI uses mTLS to talk to the Nomad HTTP API but the Web UI is only accessible through a proxy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good point. I am actually worried that might sink this whole feature, the more I think about it.
Do we have any way of knowing at a config level if there is a reverse proxy set up? Or is that more extra-nomad than we can know about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any way of knowing at a config level if there is a reverse proxy set up? Or is that more extra-nomad than we can know about?
Sadly I don't think we have anything today to do that, but a nomad.ui_url
agent configuration parameter like consul and vault have would be sufficient. That would still require an Agent().Self()
call to retrieve unless we did something very clever in the Agent HTTP API like sniff the User-Agent, and if it's the Nomad CLI: return an HTTP header with the ui_url
. As hacky as that sounds I think returning extra metadata to the CLI might be a useful pattern?
return true | ||
} | ||
|
||
return !uiConfig["CLIURLLinks"].(bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would cause new CLIs to panic when talking to old Agents that do not report this value: https://go.dev/play/p/Nm5dJx37eI0
return true | ||
} | ||
agentConfig := agent.Config | ||
uiConfig, ok := agentConfig["UI"].(map[string]interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be locally configurable instead of clusterwide configurable. For example it's probably desirable on operator machines and bastion hosts, but potentially undesirable on actual Nomad Clients where the CLI is only used for maintenance/debugging.
Since the UI is often proxied across many agents, if not the entire cluster, configuring this parameter clusterwide seems difficult.
I think we probably want to implement something like #24706 or at least an env var to let this behavior be user configurable.
We should probably be careful about doing implicit API calls from the CLI as well. Even though Agent().Self()
should be cheap for the responding Agent, users running scripts over potentially slow links may see a significant slowdown from the extra roundtrips.
Adds a "View more in the Web UI: $url" message at the end of common CLI commands to give users a way to dive deeper with a single click (or copy/paste)
Modify the
ui
block of your agent config with the following to disable:cli_url_links = false
Add a
-ui
flag to several common commands (nomad job status
for example) for your default browser to open to the suggested page