Skip to content

Commit

Permalink
use env var instead of config file
Browse files Browse the repository at this point in the history
Signed-off-by: mornyx <[email protected]>
  • Loading branch information
mornyx committed Sep 9, 2024
1 parent e365041 commit 2b595a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 0 additions & 3 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,3 @@

## When enabled, usage data will be sent to PingCAP for improving user experience.
# enable-telemetry = false

## When enabled, configuring a custom prometheus address through Dashboard will not be allowed.
# disable-custom-prom-addr = false
14 changes: 13 additions & 1 deletion pkg/dashboard/adapter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
package adapter

import (
"os"
"strings"

"github.com/pingcap/tidb-dashboard/pkg/config"

"github.com/tikv/pd/server"
)

const (
envTidbDashboardDisableCustomPromAddr = "TIDB_DASHBOARD_DISABLE_CUSTOM_PROM_ADDR"
)

// GenDashboardConfig generates a configuration for Dashboard Server.
func GenDashboardConfig(srv *server.Server) (*config.Config, error) {
cfg := srv.GetConfig()
Expand All @@ -35,7 +42,6 @@ func GenDashboardConfig(srv *server.Server) (*config.Config, error) {
dashboardCfg.PublicPathPrefix = cfg.Dashboard.PublicPathPrefix
dashboardCfg.EnableTelemetry = cfg.Dashboard.EnableTelemetry
dashboardCfg.EnableExperimental = cfg.Dashboard.EnableExperimental
dashboardCfg.DisableCustomPromAddr = cfg.Dashboard.DisableCustomPromAddr
if dashboardCfg.ClusterTLSConfig, err = cfg.Security.ToTLSConfig(); err != nil {
return nil, err
}
Expand All @@ -48,5 +54,11 @@ func GenDashboardConfig(srv *server.Server) (*config.Config, error) {

dashboardCfg.NormalizePublicPathPrefix()

// Allow setting DisableCustomPromAddr via environment variable.
disableCustomPromAddr := strings.ToLower(os.Getenv(envTidbDashboardDisableCustomPromAddr))
if disableCustomPromAddr == "true" || disableCustomPromAddr == "1" {
dashboardCfg.DisableCustomPromAddr = true
}

return dashboardCfg, nil
}
15 changes: 7 additions & 8 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,14 +1362,13 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) {

// DashboardConfig is the configuration for tidb-dashboard.
type DashboardConfig struct {
TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb-cacert-path"`
TiDBCertPath string `toml:"tidb-cert-path" json:"tidb-cert-path"`
TiDBKeyPath string `toml:"tidb-key-path" json:"tidb-key-path"`
PublicPathPrefix string `toml:"public-path-prefix" json:"public-path-prefix"`
InternalProxy bool `toml:"internal-proxy" json:"internal-proxy"`
EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"`
EnableExperimental bool `toml:"enable-experimental" json:"enable-experimental"`
DisableCustomPromAddr bool `toml:"disable-custom-prom-addr" json:"disable-custom-prom-addr"`
TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb-cacert-path"`
TiDBCertPath string `toml:"tidb-cert-path" json:"tidb-cert-path"`
TiDBKeyPath string `toml:"tidb-key-path" json:"tidb-key-path"`
PublicPathPrefix string `toml:"public-path-prefix" json:"public-path-prefix"`
InternalProxy bool `toml:"internal-proxy" json:"internal-proxy"`
EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"`
EnableExperimental bool `toml:"enable-experimental" json:"enable-experimental"`
}

// ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard.
Expand Down

0 comments on commit 2b595a9

Please sign in to comment.