-
Notifications
You must be signed in to change notification settings - Fork 606
feat: Configure Prometheus endpoint via Helm chart (#4562) #4643
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -101,6 +101,7 @@ func buildHeadlampCFG(conf *config.Config, kubeConfigStore kubeconfig.ContextSto | |||
| TLSCertPath: conf.TLSCertPath, | ||||
| TLSKeyPath: conf.TLSKeyPath, | ||||
| SessionTTL: conf.SessionTTL, | ||||
| PrometheusEndpoint: *conf.PrometheusEndpoint, | ||||
|
||||
| PrometheusEndpoint: *conf.PrometheusEndpoint, |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -178,7 +178,7 @@ func (c *HeadlampConfig) parseKubeConfig(w http.ResponseWriter, r *http.Request) | |||||
| return | ||||||
| } | ||||||
|
|
||||||
| clientConfig := clientConfig{contexts, c.EnableDynamicClusters} | ||||||
| clientConfig := clientConfig{contexts, c.EnableDynamicClusters, c.PrometheusEndpoint} | ||||||
|
||||||
| clientConfig := clientConfig{contexts, c.EnableDynamicClusters, c.PrometheusEndpoint} | |
| clientConfig := clientConfig{contexts, c.EnableDynamicClusters, ""} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,8 +83,9 @@ type Config struct { | |
| StdoutTraceEnabled *bool `koanf:"stdout-trace-enabled"` | ||
| SamplingRate *float64 `koanf:"sampling-rate"` | ||
| // TLS config | ||
| TLSCertPath string `koanf:"tls-cert-path"` | ||
| TLSKeyPath string `koanf:"tls-key-path"` | ||
| TLSCertPath string `koanf:"tls-cert-path"` | ||
| TLSKeyPath string `koanf:"tls-key-path"` | ||
| PrometheusEndpoint *string `koanf:"prometheus-endpoint"` | ||
| } | ||
|
|
||
| func (c *Config) Validate() error { | ||
|
|
@@ -144,6 +145,16 @@ func (c *Config) Validate() error { | |
| } | ||
| } | ||
|
|
||
| return c.validatePrometheusEndpoint() | ||
| } | ||
|
|
||
| func (c *Config) validatePrometheusEndpoint() error { | ||
| if c.PrometheusEndpoint != nil && *c.PrometheusEndpoint != "" { | ||
| if !strings.HasPrefix(*c.PrometheusEndpoint, "http://") && !strings.HasPrefix(*c.PrometheusEndpoint, "https://") { | ||
| return errors.New("prometheus-endpoint must start with http:// or https://") | ||
| } | ||
| } | ||
|
Comment on lines
+148
to
+156
|
||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -448,6 +459,7 @@ func addGeneralFlags(f *flag.FlagSet) { | |
| f.Uint("port", defaultPort, "Port to listen from") | ||
| f.String("proxy-urls", "", "Allow proxy requests to specified URLs") | ||
| f.Bool("enable-helm", false, "Enable Helm operations") | ||
| f.String("prometheus-endpoint", "", "Prometheus endpoint for the cluster") | ||
| } | ||
|
Comment on lines
459
to
463
|
||
|
|
||
| func addOIDCFlags(f *flag.FlagSet) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,4 +63,5 @@ type HeadlampCFG struct { | |
| TLSCertPath string | ||
| TLSKeyPath string | ||
| SessionTTL int | ||
| PrometheusEndpoint string | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,6 @@ import ( | |||||
| "path/filepath" | ||||||
| "testing" | ||||||
|
|
||||||
| "github.com/kubernetes-sigs/headlamp/backend/pkg/config" | ||||||
| "github.com/kubernetes-sigs/headlamp/backend/pkg/kubeconfig" | ||||||
| "github.com/pkg/errors" | ||||||
| "github.com/stretchr/testify/assert" | ||||||
|
|
@@ -314,12 +313,55 @@ func createTempKubeconfig(t *testing.T, content string) string { | |||||
| return tempFile.Name() | ||||||
| } | ||||||
|
|
||||||
| // setupMockK8sServer creates a test HTTP server and a temporary kubeconfig pointing to it. | ||||||
| // Returns the server, temp kubeconfig path, and a cleanup function. | ||||||
|
||||||
| // Returns the server, temp kubeconfig path, and a cleanup function. | |
| // It returns the server and the path to the temporary kubeconfig file. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -319,6 +319,9 @@ spec: | |||||
| {{- with .Values.config.baseURL }} | ||||||
| - "-base-url={{ . }}" | ||||||
| {{- end }} | ||||||
| {{- with .Values.config.prometheus.endpoint }} | ||||||
| - "-prometheus-endpoint={{ . | quote }}" | ||||||
|
||||||
| - "-prometheus-endpoint={{ . | quote }}" | |
| - "-prometheus-endpoint={{ . }}" |
Copilot
AI
Feb 8, 2026
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.
Helm values are injected directly into a double-quoted YAML string here. If the endpoint ever contains characters that need escaping (e.g., quotes), it can render invalid YAML. Prefer using Helm quoting/printf patterns that safely escape the value when building the arg string.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,9 @@ config: | |||||
| baseURL: "" | ||||||
| # -- session token TTL in seconds (default is 24 hours) | ||||||
| sessionTTL: 86400 | ||||||
| prometheus: | ||||||
| # -- Prometheus endpoint for the cluster | ||||||
|
||||||
| # -- Prometheus endpoint for the cluster | |
| # -- Prometheus HTTP(S) endpoint URL used by Headlamp to query metrics for the cluster. Leave empty to disable Prometheus integration. |
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 code references
c.PrometheusEndpoint, butHeadlampConfigembedsheadlampconfig.HeadlampConfig/HeadlampCFG, which currently do not include aPrometheusEndpointfield. This will fail to compile until the config structs are updated to carry this value (or the code is changed to retrieve it from the correct place).