Allow to disable NGINX metrics
This commit is contained in:
parent
c4ba23832a
commit
06d33c16b5
9 changed files with 42 additions and 9 deletions
|
@ -147,6 +147,9 @@ Requires the update-status parameter.`)
|
||||||
`Dynamically update SSL certificates instead of reloading NGINX.
|
`Dynamically update SSL certificates instead of reloading NGINX.
|
||||||
Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not enabled`)
|
Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not enabled`)
|
||||||
|
|
||||||
|
enableMetrics = flags.Bool("enable-metrics", true,
|
||||||
|
`Enables the collection of NGINX metrics`)
|
||||||
|
|
||||||
httpPort = flags.Int("http-port", 80, `Port to use for servicing HTTP traffic.`)
|
httpPort = flags.Int("http-port", 80, `Port to use for servicing HTTP traffic.`)
|
||||||
httpsPort = flags.Int("https-port", 443, `Port to use for servicing HTTPS traffic.`)
|
httpsPort = flags.Int("https-port", 443, `Port to use for servicing HTTPS traffic.`)
|
||||||
statusPort = flags.Int("status-port", 18080, `Port to use for exposing NGINX status pages.`)
|
statusPort = flags.Int("status-port", 18080, `Port to use for exposing NGINX status pages.`)
|
||||||
|
@ -223,6 +226,7 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en
|
||||||
UpdateStatus: *updateStatus,
|
UpdateStatus: *updateStatus,
|
||||||
ElectionID: *electionID,
|
ElectionID: *electionID,
|
||||||
EnableProfiling: *profiling,
|
EnableProfiling: *profiling,
|
||||||
|
EnableMetrics: *enableMetrics,
|
||||||
EnableSSLPassthrough: *enableSSLPassthrough,
|
EnableSSLPassthrough: *enableSSLPassthrough,
|
||||||
EnableSSLChainCompletion: *enableSSLChainCompletion,
|
EnableSSLChainCompletion: *enableSSLChainCompletion,
|
||||||
ResyncPeriod: *resyncPeriod,
|
ResyncPeriod: *resyncPeriod,
|
||||||
|
|
|
@ -128,10 +128,13 @@ func main() {
|
||||||
ReportErrors: true,
|
ReportErrors: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mc, err := metric.NewCollector(conf.ListenPorts.Status, reg)
|
mc := metric.NewDummyCollector()
|
||||||
|
if conf.EnableMetrics {
|
||||||
|
mc, err = metric.NewCollector(conf.ListenPorts.Status, reg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Error creating prometheus collector: %v", err)
|
glog.Fatalf("Error creating prometheus collector: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mc.Start()
|
mc.Start()
|
||||||
|
|
||||||
ngx := controller.NewNGINXController(conf, mc, fs)
|
ngx := controller.NewNGINXController(conf, mc, fs)
|
||||||
|
|
|
@ -715,6 +715,7 @@ type TemplateConfig struct {
|
||||||
ListenPorts *ListenPorts
|
ListenPorts *ListenPorts
|
||||||
PublishService *apiv1.Service
|
PublishService *apiv1.Service
|
||||||
DynamicCertificatesEnabled bool
|
DynamicCertificatesEnabled bool
|
||||||
|
EnableMetrics bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPorts describe the ports required to run the
|
// ListenPorts describe the ports required to run the
|
||||||
|
|
|
@ -87,6 +87,8 @@ type Configuration struct {
|
||||||
|
|
||||||
EnableProfiling bool
|
EnableProfiling bool
|
||||||
|
|
||||||
|
EnableMetrics bool
|
||||||
|
|
||||||
EnableSSLChainCompletion bool
|
EnableSSLChainCompletion bool
|
||||||
|
|
||||||
FakeCertificatePath string
|
FakeCertificatePath string
|
||||||
|
|
|
@ -602,6 +602,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
||||||
ListenPorts: n.cfg.ListenPorts,
|
ListenPorts: n.cfg.ListenPorts,
|
||||||
PublishService: n.GetPublishService(),
|
PublishService: n.GetPublishService(),
|
||||||
DynamicCertificatesEnabled: n.cfg.DynamicCertificatesEnabled,
|
DynamicCertificatesEnabled: n.cfg.DynamicCertificatesEnabled,
|
||||||
|
EnableMetrics: n.cfg.EnableMetrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
tc.Cfg.Checksum = ingressCfg.ConfigurationChecksum
|
tc.Cfg.Checksum = ingressCfg.ConfigurationChecksum
|
||||||
|
|
|
@ -914,13 +914,15 @@ func proxySetHeader(loc interface{}) string {
|
||||||
|
|
||||||
// buildCustomErrorDeps is a utility function returning a struct wrapper with
|
// buildCustomErrorDeps is a utility function returning a struct wrapper with
|
||||||
// the data required to build the 'CUSTOM_ERRORS' template
|
// the data required to build the 'CUSTOM_ERRORS' template
|
||||||
func buildCustomErrorDeps(proxySetHeaders map[string]string, errorCodes []int) interface{} {
|
func buildCustomErrorDeps(proxySetHeaders map[string]string, errorCodes []int, enableMetrics bool) interface{} {
|
||||||
return struct {
|
return struct {
|
||||||
ProxySetHeaders map[string]string
|
ProxySetHeaders map[string]string
|
||||||
ErrorCodes []int
|
ErrorCodes []int
|
||||||
|
EnableMetrics bool
|
||||||
}{
|
}{
|
||||||
ProxySetHeaders: proxySetHeaders,
|
ProxySetHeaders: proxySetHeaders,
|
||||||
ErrorCodes: errorCodes,
|
ErrorCodes: errorCodes,
|
||||||
|
EnableMetrics: enableMetrics,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -826,7 +826,7 @@ func TestEscapeLiteralDollar(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_opentracingPropagateContext(t *testing.T) {
|
func TestOpentracingPropagateContext(t *testing.T) {
|
||||||
tests := map[interface{}]string{
|
tests := map[interface{}]string{
|
||||||
&ingress.Location{BackendProtocol: "HTTP"}: "opentracing_propagate_context",
|
&ingress.Location{BackendProtocol: "HTTP"}: "opentracing_propagate_context",
|
||||||
&ingress.Location{BackendProtocol: "HTTPS"}: "opentracing_propagate_context",
|
&ingress.Location{BackendProtocol: "HTTPS"}: "opentracing_propagate_context",
|
||||||
|
|
|
@ -16,7 +16,15 @@ limitations under the License.
|
||||||
|
|
||||||
package metric
|
package metric
|
||||||
|
|
||||||
import "k8s.io/ingress-nginx/internal/ingress"
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewDummyCollector returns a dummy metric collector
|
||||||
|
func NewDummyCollector() Collector {
|
||||||
|
return &DummyCollector{}
|
||||||
|
}
|
||||||
|
|
||||||
// DummyCollector dummy implementation for mocks in tests
|
// DummyCollector dummy implementation for mocks in tests
|
||||||
type DummyCollector struct{}
|
type DummyCollector struct{}
|
||||||
|
@ -41,3 +49,6 @@ func (dc DummyCollector) Stop() {}
|
||||||
|
|
||||||
// SetSSLExpireTime ...
|
// SetSSLExpireTime ...
|
||||||
func (dc DummyCollector) SetSSLExpireTime([]*ingress.Server) {}
|
func (dc DummyCollector) SetSSLExpireTime([]*ingress.Server) {}
|
||||||
|
|
||||||
|
// SetHosts ...
|
||||||
|
func (dc DummyCollector) SetHosts(hosts sets.String) {}
|
||||||
|
|
|
@ -78,12 +78,14 @@ http {
|
||||||
balancer = res
|
balancer = res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
{{ if $all.EnableMetrics }}
|
||||||
ok, res = pcall(require, "monitor")
|
ok, res = pcall(require, "monitor")
|
||||||
if not ok then
|
if not ok then
|
||||||
error("require failed: " .. tostring(res))
|
error("require failed: " .. tostring(res))
|
||||||
else
|
else
|
||||||
monitor = res
|
monitor = res
|
||||||
end
|
end
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if $all.DynamicCertificatesEnabled }}
|
{{ if $all.DynamicCertificatesEnabled }}
|
||||||
ok, res = pcall(require, "certificate")
|
ok, res = pcall(require, "certificate")
|
||||||
|
@ -97,7 +99,9 @@ http {
|
||||||
|
|
||||||
init_worker_by_lua_block {
|
init_worker_by_lua_block {
|
||||||
balancer.init_worker()
|
balancer.init_worker()
|
||||||
|
{{ if $all.EnableMetrics }}
|
||||||
monitor.init_worker()
|
monitor.init_worker()
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/* Enable the real_ip module only if we use either X-Forwarded headers or Proxy Protocol. */}}
|
{{/* Enable the real_ip module only if we use either X-Forwarded headers or Proxy Protocol. */}}
|
||||||
|
@ -576,7 +580,7 @@ http {
|
||||||
{{ $cfg.ServerSnippet }}
|
{{ $cfg.ServerSnippet }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders $cfg.CustomHTTPErrors) }}
|
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders $cfg.CustomHTTPErrors $all.EnableMetrics) }}
|
||||||
}
|
}
|
||||||
## end server {{ $server.Hostname }}
|
## end server {{ $server.Hostname }}
|
||||||
|
|
||||||
|
@ -679,7 +683,7 @@ http {
|
||||||
proxy_pass http://upstream_balancer;
|
proxy_pass http://upstream_balancer;
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders $cfg.CustomHTTPErrors) }}
|
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders $cfg.CustomHTTPErrors $all.EnableMetrics) }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,6 +804,7 @@ stream {
|
||||||
{{/* definition of templates to avoid repetitions */}}
|
{{/* definition of templates to avoid repetitions */}}
|
||||||
{{ define "CUSTOM_ERRORS" }}
|
{{ define "CUSTOM_ERRORS" }}
|
||||||
{{ $proxySetHeaders := .ProxySetHeaders }}
|
{{ $proxySetHeaders := .ProxySetHeaders }}
|
||||||
|
{{ $enableMetrics := .EnableMetrics }}
|
||||||
{{ range $errCode := .ErrorCodes }}
|
{{ range $errCode := .ErrorCodes }}
|
||||||
location @custom_{{ $errCode }} {
|
location @custom_{{ $errCode }} {
|
||||||
internal;
|
internal;
|
||||||
|
@ -821,7 +826,9 @@ stream {
|
||||||
|
|
||||||
proxy_pass http://upstream_balancer;
|
proxy_pass http://upstream_balancer;
|
||||||
log_by_lua_block {
|
log_by_lua_block {
|
||||||
|
{{ if $enableMetrics }}
|
||||||
monitor.call()
|
monitor.call()
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -922,7 +929,7 @@ stream {
|
||||||
{{ $server.ServerSnippet }}
|
{{ $server.ServerSnippet }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders (collectCustomErrorsPerServer $server)) }}
|
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders (collectCustomErrorsPerServer $server) $all.EnableMetrics) }}
|
||||||
|
|
||||||
{{ $enforceRegex := enforceRegexModifier $server.Locations }}
|
{{ $enforceRegex := enforceRegexModifier $server.Locations }}
|
||||||
{{ range $location := $server.Locations }}
|
{{ range $location := $server.Locations }}
|
||||||
|
@ -1087,7 +1094,9 @@ stream {
|
||||||
waf:exec()
|
waf:exec()
|
||||||
{{ end }}
|
{{ end }}
|
||||||
balancer.log()
|
balancer.log()
|
||||||
|
{{ if $all.EnableMetrics }}
|
||||||
monitor.call()
|
monitor.call()
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ if (and (not (empty $server.SSLCert.PemFileName)) $all.Cfg.HSTS) }}
|
{{ if (and (not (empty $server.SSLCert.PemFileName)) $all.Cfg.HSTS) }}
|
||||||
|
|
Loading…
Reference in a new issue