Skip to content

Commit 0d88edd

Browse files
committed
add enable-metrics arg to disable metrics (#2232)
1 parent 41120b2 commit 0d88edd

File tree

8 files changed

+24
-5
lines changed

8 files changed

+24
-5
lines changed

cmd/controller/controller.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func CmdMain() {
4343
go loopOvnNbctlDaemon(config)
4444
go func() {
4545
mux := http.NewServeMux()
46-
mux.Handle("/metrics", promhttp.Handler())
46+
if config.EnableMetrics {
47+
mux.Handle("/metrics", promhttp.Handler())
48+
}
4749
if config.EnablePprof {
4850
mux.HandleFunc("/debug/pprof/", pprof.Index)
4951
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)

cmd/daemon/cniserver.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ func CmdMain() {
8787
}
8888

8989
mux := http.NewServeMux()
90-
mux.Handle("/metrics", promhttp.Handler())
90+
if config.EnableMetrics {
91+
mux.Handle("/metrics", promhttp.Handler())
92+
}
9193
if config.EnablePprof {
9294
mux.HandleFunc("/debug/pprof/", pprof.Index)
9395
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)

cmd/ovn_monitor/ovn_monitor.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ func CmdMain() {
3232
}
3333
exporter.StartOvnMetrics()
3434

35-
http.Handle(config.MetricsPath, promhttp.Handler())
36-
klog.Infoln("Listening on", config.ListenAddress)
35+
if config.EnableMetrics {
36+
http.Handle(config.MetricsPath, promhttp.Handler())
37+
klog.Infoln("Listening on", config.ListenAddress)
38+
}
3739

3840
// conform to Gosec G114
3941
// https://github.com/securego/gosec#available-rules

cmd/pinger/pinger.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ func CmdMain() {
2424
if err != nil {
2525
util.LogFatalAndExit(err, "failed to parse config")
2626
}
27-
if config.Mode == "server" {
27+
if config.Mode == "server" && config.EnableMetrics {
2828
http.Handle("/metrics", promhttp.Handler())
29+
2930
go func() {
3031
server := &http.Server{
3132
Addr: fmt.Sprintf("0.0.0.0:%d", config.Port),

pkg/controller/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Configuration struct {
8080
EnableExternalVpc bool
8181
EnableEcmp bool
8282
EnableKeepVmIP bool
83+
EnableMetrics bool
8384

8485
ExternalGatewayConfigNS string
8586
ExternalGatewayNet string
@@ -136,6 +137,7 @@ func ParseFlags() (*Configuration, error) {
136137
argEnableExternalVpc = pflag.Bool("enable-external-vpc", true, "Enable external vpc support")
137138
argEnableEcmp = pflag.Bool("enable-ecmp", false, "Enable ecmp route for centralized subnet")
138139
argKeepVmIP = pflag.Bool("keep-vm-ip", false, "Whether to keep ip for kubevirt pod when pod is rebuild")
140+
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
139141

140142
argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
141143
argExternalGatewayNet = pflag.String("external-gateway-net", "external", "The namespace of configmap external-gateway-config, default: external")
@@ -205,6 +207,7 @@ func ParseFlags() (*Configuration, error) {
205207
EnableEcmp: *argEnableEcmp,
206208
EnableKeepVmIP: *argKeepVmIP,
207209
NodePgProbeTime: *argNodePgProbeTime,
210+
EnableMetrics: *argEnableMetrics,
208211
}
209212

210213
if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {

pkg/daemon/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Configuration struct {
5555
DefaultProviderName string
5656
DefaultInterfaceName string
5757
ExternalGatewayConfigNS string
58+
EnableMetrics bool
5859
}
5960

6061
// ParseFlags will parse cmd args then init kubeClient and configuration
@@ -84,6 +85,7 @@ func ParseFlags() *Configuration {
8485
argsDefaultProviderName = pflag.String("default-provider-name", "provider", "The vlan or vxlan type default provider interface name")
8586
argsDefaultInterfaceName = pflag.String("default-interface-name", "", "The default host interface name in the vlan/vxlan type")
8687
argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
88+
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
8789
)
8890

8991
// mute info log for ipset lib
@@ -130,6 +132,7 @@ func ParseFlags() *Configuration {
130132
DefaultProviderName: *argsDefaultProviderName,
131133
DefaultInterfaceName: *argsDefaultInterfaceName,
132134
ExternalGatewayConfigNS: *argExternalGatewayConfigNS,
135+
EnableMetrics: *argEnableMetrics,
133136
}
134137
return config
135138
}

pkg/ovnmonitor/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Configuration struct {
4040
ServiceVswitchdFilePidPath string
4141
ServiceNorthdFileLogPath string
4242
ServiceNorthdFilePidPath string
43+
EnableMetrics bool
4344
}
4445

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

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

126129
klog.Infof("ovn monitor config is %+v", config)

pkg/pinger/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Configuration struct {
3434
PodProtocols []string
3535
ExternalAddress string
3636
NetworkMode string
37+
EnableMetrics bool
3738

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

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

119122
// OVS Monitor
120123
PollTimeout: *argPollTimeout,

0 commit comments

Comments
 (0)