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

add enable-metrics arg to disable metrics #2232

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func CmdMain() {
go loopOvnNbctlDaemon(config)
go func() {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
if config.EnableMetrics {
mux.Handle("/metrics", promhttp.Handler())
}
if config.EnablePprof {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
Expand Down
4 changes: 3 additions & 1 deletion cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func CmdMain() {
}

mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
if config.EnableMetrics {
mux.Handle("/metrics", promhttp.Handler())
}
if config.EnablePprof {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
Expand Down
6 changes: 4 additions & 2 deletions cmd/ovn_monitor/ovn_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ func CmdMain() {
}
exporter.StartOvnMetrics()

http.Handle(config.MetricsPath, promhttp.Handler())
klog.Infoln("Listening on", config.ListenAddress)
if config.EnableMetrics {
http.Handle(config.MetricsPath, promhttp.Handler())
klog.Infoln("Listening on", config.ListenAddress)
}

// conform to Gosec G114
// https://github.com/securego/gosec#available-rules
Expand Down
3 changes: 2 additions & 1 deletion cmd/pinger/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func CmdMain() {
if err != nil {
util.LogFatalAndExit(err, "failed to parse config")
}
if config.Mode == "server" {
if config.Mode == "server" && config.EnableMetrics {
http.Handle("/metrics", promhttp.Handler())

go func() {
// conform to Gosec G114
// https://github.com/securego/gosec#available-rules
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Configuration struct {
EnableEcmp bool
EnableKeepVmIP bool
EnableLbSvc bool
EnableMetrics bool

ExternalGatewaySwitch string
ExternalGatewayConfigNS string
Expand Down Expand Up @@ -147,6 +148,7 @@ func ParseFlags() (*Configuration, error) {
argEnableEcmp = pflag.Bool("enable-ecmp", false, "Enable ecmp route for centralized subnet")
argKeepVmIP = pflag.Bool("keep-vm-ip", false, "Whether to keep ip for kubevirt pod when pod is rebuild")
argEnableLbSvc = pflag.Bool("enable-lb-svc", false, "Whether to support loadbalancer service")
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")

argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
argExternalGatewaySwitch = pflag.String("external-gateway-switch", "external", "The name of the external gateway switch which is a ovs bridge to provide external network, default: external")
Expand Down Expand Up @@ -226,6 +228,7 @@ func ParseFlags() (*Configuration, error) {
GCInterval: *argGCInterval,
InspectInterval: *argInspectInterval,
EnableLbSvc: *argEnableLbSvc,
EnableMetrics: *argEnableMetrics,
}

if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Configuration struct {
DefaultInterfaceName string
ExternalGatewayConfigNS string
ExternalGatewaySwitch string // provider network underlay vlan subnet
EnableMetrics bool
}

// ParseFlags will parse cmd args then init kubeClient and configuration
Expand Down Expand Up @@ -86,6 +87,7 @@ func ParseFlags() *Configuration {
argsDefaultInterfaceName = pflag.String("default-interface-name", "", "The default host interface name in the vlan/vxlan type")
argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
argExternalGatewaySwitch = pflag.String("external-gateway-switch", "external", "The name of the external gateway switch which is a ovs bridge to provide external network, default: external")
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
)

// mute info log for ipset lib
Expand Down Expand Up @@ -133,6 +135,7 @@ func ParseFlags() *Configuration {
DefaultInterfaceName: *argsDefaultInterfaceName,
ExternalGatewayConfigNS: *argExternalGatewayConfigNS,
ExternalGatewaySwitch: *argExternalGatewaySwitch,
EnableMetrics: *argEnableMetrics,
}
return config
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/ovnmonitor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Configuration struct {
ServiceVswitchdFilePidPath string
ServiceNorthdFileLogPath string
ServiceNorthdFilePidPath string
EnableMetrics bool
}

// ParseFlags get parameters information.
Expand All @@ -49,6 +50,7 @@ func ParseFlags() (*Configuration, error) {
argMetricsPath = pflag.String("telemetry-path", "/metrics", "Path under which to expose metrics.")
argPollTimeout = pflag.Int("ovs.timeout", 2, "Timeout on JSON-RPC requests to OVN.")
argPollInterval = pflag.Int("ovs.poll-interval", 30, "The minimum interval (in seconds) between collections from OVN server.")
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")

argSystemRunDir = pflag.String("system.run.dir", "/var/run/openvswitch", "OVS default run directory.")
argDatabaseVswitchName = pflag.String("database.vswitch.name", "Open_vSwitch", "The name of OVS db.")
Expand Down Expand Up @@ -121,6 +123,7 @@ func ParseFlags() (*Configuration, error) {
ServiceVswitchdFilePidPath: *argServiceVswitchdFilePidPath,
ServiceNorthdFileLogPath: *argServiceNorthdFileLogPath,
ServiceNorthdFilePidPath: *argServiceNorthdFilePidPath,
EnableMetrics: *argEnableMetrics,
}

klog.Infof("ovn monitor config is %+v", config)
Expand Down
3 changes: 3 additions & 0 deletions pkg/pinger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Configuration struct {
PodProtocols []string
ExternalAddress string
NetworkMode string
EnableMetrics bool

// Used for OVS Monitor
PollTimeout int
Expand Down Expand Up @@ -64,6 +65,7 @@ func ParseFlags() (*Configuration, error) {
argExternalDns = pflag.String("external-dns", "", "check external dns resolve from pod")
argExternalAddress = pflag.String("external-address", "", "check ping connection to an external address, default: 114.114.114.114")
argNetworkMode = pflag.String("network-mode", "kube-ovn", "The cni plugin current cluster used, default: kube-ovn")
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")

argPollTimeout = pflag.Int("ovs.timeout", 2, "Timeout on JSON-RPC requests to OVS.")
argPollInterval = pflag.Int("ovs.poll-interval", 15, "The minimum interval (in seconds) between collections from OVS server.")
Expand Down Expand Up @@ -115,6 +117,7 @@ func ParseFlags() (*Configuration, error) {
PodName: os.Getenv("POD_NAME"),
ExternalAddress: *argExternalAddress,
NetworkMode: *argNetworkMode,
EnableMetrics: *argEnableMetrics,

// OVS Monitor
PollTimeout: *argPollTimeout,
Expand Down