Add functionality to bind custom IP address for Etcd metrics endpoint (#2750)

* Add functionality to bind custom IP address for Etcd metrics endpoint

Signed-off-by: yuriydzobak <yurii.dzobak@lotusflare.com>
pull/2862/head
Yuriy 2021-01-23 03:40:48 +02:00 committed by GitHub
parent f152f656a0
commit 06fda7accf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

View File

@ -60,6 +60,7 @@ type Server struct {
StartupHooks []func(context.Context, <-chan struct{}, string) error StartupHooks []func(context.Context, <-chan struct{}, string) error
EtcdSnapshotName string EtcdSnapshotName string
EtcdDisableSnapshots bool EtcdDisableSnapshots bool
EtcdExposeMetrics bool
EtcdSnapshotDir string EtcdSnapshotDir string
EtcdSnapshotCron string EtcdSnapshotCron string
EtcdSnapshotRetention int EtcdSnapshotRetention int
@ -210,6 +211,11 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Destination: &ServerConfig.DatastoreKeyFile, Destination: &ServerConfig.DatastoreKeyFile,
EnvVar: version.ProgramUpper + "_DATASTORE_KEYFILE", EnvVar: version.ProgramUpper + "_DATASTORE_KEYFILE",
}, },
&cli.BoolFlag{
Name: "etcd-expose-metrics",
Usage: "(db) Expose etcd metrics to client interface. (Default false)",
Destination: &ServerConfig.EtcdExposeMetrics,
},
&cli.BoolFlag{ &cli.BoolFlag{
Name: "etcd-disable-snapshots", Name: "etcd-disable-snapshots",
Usage: "(db) Disable automatic etcd snapshots", Usage: "(db) Disable automatic etcd snapshots",

View File

@ -116,6 +116,7 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir serverConfig.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir
serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention
serverConfig.ControlConfig.EtcdDisableSnapshots = cfg.EtcdDisableSnapshots serverConfig.ControlConfig.EtcdDisableSnapshots = cfg.EtcdDisableSnapshots
serverConfig.ControlConfig.EtcdExposeMetrics = cfg.EtcdExposeMetrics
if cfg.ClusterResetRestorePath != "" && !cfg.ClusterReset { if cfg.ClusterResetRestorePath != "" && !cfg.ClusterReset {
return errors.New("Invalid flag use. --cluster-reset required with --cluster-reset-restore-path") return errors.New("Invalid flag use. --cluster-reset required with --cluster-reset-restore-path")

View File

@ -132,6 +132,7 @@ type Control struct {
TLSCipherSuites []uint16 TLSCipherSuites []uint16
EtcdSnapshotName string EtcdSnapshotName string
EtcdDisableSnapshots bool EtcdDisableSnapshots bool
EtcdExposeMetrics bool
EtcdSnapshotDir string EtcdSnapshotDir string
EtcdSnapshotCron string EtcdSnapshotCron string
EtcdSnapshotRetention int EtcdSnapshotRetention int

View File

@ -482,6 +482,14 @@ func (e *ETCD) clientURL() string {
return fmt.Sprintf("https://%s:2379", e.address) return fmt.Sprintf("https://%s:2379", e.address)
} }
// metricsURL returns the metrics access address
func (e *ETCD) metricsURL(expose bool) string {
if expose {
return fmt.Sprintf("http://%s:2381", e.address)
}
return "http://127.0.0.1:2381"
}
// cluster returns ETCDConfig for a cluster // cluster returns ETCDConfig for a cluster
func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.InitialOptions) error { func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.InitialOptions) error {
return executor.ETCD(executor.ETCDConfig{ return executor.ETCD(executor.ETCDConfig{
@ -489,7 +497,7 @@ func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.Init
InitialOptions: options, InitialOptions: options,
ForceNewCluster: forceNew, ForceNewCluster: forceNew,
ListenClientURLs: fmt.Sprintf(e.clientURL() + ",https://127.0.0.1:2379"), ListenClientURLs: fmt.Sprintf(e.clientURL() + ",https://127.0.0.1:2379"),
ListenMetricsURLs: "http://127.0.0.1:2381", ListenMetricsURLs: e.metricsURL(e.config.EtcdExposeMetrics),
ListenPeerURLs: e.peerURL(), ListenPeerURLs: e.peerURL(),
AdvertiseClientURLs: e.clientURL(), AdvertiseClientURLs: e.clientURL(),
DataDir: etcdDBDir(e.config), DataDir: etcdDBDir(e.config),