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

[cli] UI URL hints for common CLI commands #24454

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

philrenaud
Copy link
Contributor

@philrenaud philrenaud commented Nov 13, 2024

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)

image

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

Copy link
Contributor

@aimeeu aimeeu left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.)

Copy link
Member

@jrasell jrasell left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Member

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?

Comment on lines 141 to 151
func DefaultUIConfig() *UIConfig {
enabled := true
return &UIConfig{
Enabled: true,
Enabled: enabled,
Consul: &ConsulUIConfig{},
Vault: &VaultUIConfig{},
Label: &LabelUIConfig{},
ContentSecurityPolicy: DefaultCSPConfig(),
CLIURLLinks: &enabled,
}
}
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@schmichael schmichael Dec 18, 2024

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)
Copy link
Member

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{})
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: read-more with context
4 participants