feat(doc): sort cli flags documentation

This commit is contained in:
Maxim Pogozhiy 2023-12-04 16:16:37 +07:00
parent 1f06e26080
commit 038b023dd0
15 changed files with 358 additions and 86 deletions

View file

@ -66,7 +66,7 @@ func main() {
mc := metric.NewDummyCollector() mc := metric.NewDummyCollector()
if conf.EnableMetrics { if conf.EnableMetrics {
// TODO: Ingress class is not a part of dataplane anymore // TODO: Ingress class is not a part of dataplane anymore
mc, err = metric.NewCollector(conf.MetricsPerHost, conf.ReportStatusClasses, reg, conf.IngressClassConfiguration.Controller, *conf.MetricsBuckets, conf.ExcludeSocketMetrics) mc, err = metric.NewCollector(conf.MetricsPerHost, conf.ReportStatusClasses, reg, conf.IngressClassConfiguration.Controller, *conf.MetricsBuckets, conf.ExcludeSocketMetrics, conf.IncludeIngressLabels, conf.IngressLabelsPrefix)
if err != nil { if err != nil {
klog.Fatalf("Error creating prometheus collector: %v", err) klog.Fatalf("Error creating prometheus collector: %v", err)
} }

View file

@ -130,7 +130,7 @@ func main() {
mc := metric.NewDummyCollector() mc := metric.NewDummyCollector()
if conf.EnableMetrics { if conf.EnableMetrics {
mc, err = metric.NewCollector(conf.MetricsPerHost, conf.ReportStatusClasses, reg, conf.IngressClassConfiguration.Controller, *conf.MetricsBuckets, conf.ExcludeSocketMetrics) mc, err = metric.NewCollector(conf.MetricsPerHost, conf.ReportStatusClasses, reg, conf.IngressClassConfiguration.Controller, *conf.MetricsBuckets, conf.ExcludeSocketMetrics, conf.IncludeIngressLabels, conf.IngressLabelsPrefix)
if err != nil { if err != nil {
klog.Fatalf("Error creating prometheus collector: %v", err) klog.Fatalf("Error creating prometheus collector: %v", err)
} }

View file

@ -4,72 +4,74 @@ The following command line arguments are accepted by the Ingress controller exec
They are set in the container spec of the `ingress-nginx-controller` Deployment manifest They are set in the container spec of the `ingress-nginx-controller` Deployment manifest
| Argument | Description | | Argument | Description |
|----------|-------------| |-------------------------------------|-------------|
| `--annotations-prefix` | Prefix of the Ingress annotations specific to the NGINX controller. (default "nginx.ingress.kubernetes.io") | | `-v, --v Level` | number for the log level verbosity |
| `--apiserver-host` | Address of the Kubernetes API server. Takes the form "protocol://address:port". If not specified, it is assumed the program runs inside a Kubernetes cluster and local discovery is attempted. | | `--annotations-prefix` | Prefix of the Ingress annotations specific to the NGINX controller. (default "nginx.ingress.kubernetes.io") |
| `--certificate-authority` | Path to a cert file for the certificate authority. This certificate is used only when the flag --apiserver-host is specified. | | `--apiserver-host` | Address of the Kubernetes API server. Takes the form "protocol://address:port". If not specified, it is assumed the program runs inside a Kubernetes cluster and local discovery is attempted. |
| `--configmap` | Name of the ConfigMap containing custom global configurations for the controller. | | `--certificate-authority` | Path to a cert file for the certificate authority. This certificate is used only when the flag --apiserver-host is specified. |
| `--controller-class` | Ingress Class Controller value this Ingress satisfies. The class of an Ingress object is set using the field IngressClassName in Kubernetes clusters version v1.19.0 or higher. The .spec.controller value of the IngressClass referenced in an Ingress Object should be the same value specified here to make this object be watched. | | `--configmap` | Name of the ConfigMap containing custom global configurations for the controller. |
| `--deep-inspect` | Enables ingress object security deep inspector. (default true) | | `--controller-class` | Ingress Class Controller value this Ingress satisfies. The class of an Ingress object is set using the field IngressClassName in Kubernetes clusters version v1.19.0 or higher. The .spec.controller value of the IngressClass referenced in an Ingress Object should be the same value specified here to make this object be watched. |
| `--default-backend-service` | Service used to serve HTTP requests not matching any known server name (catch-all). Takes the form "namespace/name". The controller configures NGINX to forward requests to the first port of this Service. | | `--deep-inspect` | Enables ingress object security deep inspector. (default true) |
| `--default-server-port` | Port to use for exposing the default server (catch-all). (default 8181) | | `--default-backend-service` | Service used to serve HTTP requests not matching any known server name (catch-all). Takes the form "namespace/name". The controller configures NGINX to forward requests to the first port of this Service. |
| `--default-ssl-certificate` | Secret containing a SSL certificate to be used by the default HTTPS server (catch-all). Takes the form "namespace/name". | | `--default-server-port` | Port to use for exposing the default server (catch-all). (default 8181) |
| `--enable-annotation-validation` | If true, will enable the annotation validation feature. This value will be defaulted to true on a future release. | | `--default-ssl-certificate` | Secret containing a SSL certificate to be used by the default HTTPS server (catch-all). Takes the form "namespace/name". |
| `--disable-catch-all` | Disable support for catch-all Ingresses. (default false) | | `--disable-catch-all` | Disable support for catch-all Ingresses. (default false) |
| `--disable-full-test` | Disable full test of all merged ingresses at the admission stage and tests the template of the ingress being created or updated (full test of all ingresses is enabled by default). | | `--disable-full-test` | Disable full test of all merged ingresses at the admission stage and tests the template of the ingress being created or updated (full test of all ingresses is enabled by default). |
| `--disable-svc-external-name` | Disable support for Services of type ExternalName. (default false) | | `--disable-svc-external-name` | Disable support for Services of type ExternalName. (default false) |
| `--disable-sync-events` | Disables the creation of 'Sync' Event resources, but still logs them | | `--disable-sync-events` | Disables the creation of 'Sync' Event resources, but still logs them |
| `--dynamic-configuration-retries` | Number of times to retry failed dynamic configuration before failing to sync an ingress. (default 15) | | `--dynamic-configuration-retries` | Number of times to retry failed dynamic configuration before failing to sync an ingress. (default 15) |
| `--election-id` | Election id to use for Ingress status updates. (default "ingress-controller-leader") | | `--election-id` | Election id to use for Ingress status updates. (default "ingress-controller-leader") |
| `--enable-metrics` | Enables the collection of NGINX metrics. (default true) | | `--enable-annotation-validation` | If true, will enable the annotation validation feature. This value will be defaulted to true on a future release. |
| `--enable-ssl-chain-completion` | Autocomplete SSL certificate chains with missing intermediate CA certificates. Certificates uploaded to Kubernetes must have the "Authority Information Access" X.509 v3 extension for this to succeed. (default false)| | `--enable-metrics` | Enables the collection of NGINX metrics. (default true) |
| `--enable-ssl-passthrough` | Enable SSL Passthrough. (default false) | | `--enable-ssl-chain-completion` | Autocomplete SSL certificate chains with missing intermediate CA certificates. Certificates uploaded to Kubernetes must have the "Authority Information Access" X.509 v3 extension for this to succeed. (default false)|
| `--enable-topology-aware-routing` | Enable topology aware routing feature, needs service object annotation service.kubernetes.io/topology-mode sets to auto. (default false) | | `--enable-ssl-passthrough` | Enable SSL Passthrough. (default false) |
| `--exclude-socket-metrics` | Set of socket request metrics to exclude which won't be exported nor being calculated. The possible socket request metrics to exclude are documented in the monitoring guide e.g. 'nginx_ingress_controller_request_duration_seconds,nginx_ingress_controller_response_size'| | `--enable-topology-aware-routing` | Enable topology aware routing feature, needs service object annotation service.kubernetes.io/topology-mode sets to auto. (default false) |
| `--health-check-path` | URL path of the health check endpoint. Configured inside the NGINX status server. All requests received on the port defined by the healthz-port parameter are forwarded internally to this path. (default "/healthz") | | `--exclude-socket-metrics` | Set of socket request metrics to exclude which won't be exported nor being calculated. The possible socket request metrics to exclude are documented in the monitoring guide e.g. 'nginx_ingress_controller_request_duration_seconds,nginx_ingress_controller_response_size'|
| `--health-check-timeout` | Time limit, in seconds, for a probe to health-check-path to succeed. (default 10) | | `--health-check-path` | URL path of the health check endpoint. Configured inside the NGINX status server. All requests received on the port defined by the healthz-port parameter are forwarded internally to this path. (default "/healthz") |
| `--healthz-port` | Port to use for the healthz endpoint. (default 10254) | | `--health-check-timeout` | Time limit, in seconds, for a probe to health-check-path to succeed. (default 10) |
| `--healthz-host` | Address to bind the healthz endpoint. | | `--healthz-host` | Address to bind the healthz endpoint. |
| `--http-port` | Port to use for servicing HTTP traffic. (default 80) | | `--healthz-port` | Port to use for the healthz endpoint. (default 10254) |
| `--https-port` | Port to use for servicing HTTPS traffic. (default 443) | | `--http-port` | Port to use for servicing HTTP traffic. (default 80) |
| `--ingress-class` | Name of the ingress class this controller satisfies. The class of an Ingress object is set using the field IngressClassName in Kubernetes clusters version v1.18.0 or higher or the annotation "kubernetes.io/ingress.class" (deprecated). If this parameter is not set, or set to the default value of "nginx", it will handle ingresses with either an empty or "nginx" class name. | | `--https-port` | Port to use for servicing HTTPS traffic. (default 443) |
| `--ingress-class-by-name` | Define if Ingress Controller should watch for Ingress Class by Name together with Controller Class. (default false). | | `--include-ingress-labels` | Set of ingress labels to include in the metrics. E.g. 'app,version'. |
| `--internal-logger-address` | Address to be used when binding internal syslogger. (default 127.0.0.1:11514) | | `--ingress-class` | Name of the ingress class this controller satisfies. The class of an Ingress object is set using the field IngressClassName in Kubernetes clusters version v1.18.0 or higher or the annotation "kubernetes.io/ingress.class" (deprecated). If this parameter is not set, or set to the default value of "nginx", it will handle ingresses with either an empty or "nginx" class name. |
| `--kubeconfig` | Path to a kubeconfig file containing authorization and API server information. | | `--ingress-class-by-name` | Define if Ingress Controller should watch for Ingress Class by Name together with Controller Class. (default false). |
| `--length-buckets` | Set of buckets which will be used for prometheus histogram metrics such as RequestLength, ResponseLength. (default `[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]`) | | `--ingress-labels-prefix` | Prefix for ingress labels in the metrics. E.g. 'ingress_'. |
| `--maxmind-edition-ids` | Maxmind edition ids to download GeoLite2 Databases. (default "GeoLite2-City,GeoLite2-ASN") | | `--internal-logger-address` | Address to be used when binding internal syslogger. (default 127.0.0.1:11514) |
| `--maxmind-retries-timeout` | Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong. (default 0s) | | `--kubeconfig` | Path to a kubeconfig file containing authorization and API server information. |
| `--maxmind-retries-count` | Number of attempts to download the GeoIP DB. (default 1) | | `--length-buckets` | Set of buckets which will be used for prometheus histogram metrics such as RequestLength, ResponseLength. (default `[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]`) |
| `--maxmind-license-key` | Maxmind license key to download GeoLite2 Databases. https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases . | | `--maxmind-edition-ids` | Maxmind edition ids to download GeoLite2 Databases. (default "GeoLite2-City,GeoLite2-ASN") |
| `--maxmind-mirror` | Maxmind mirror url (example: http://geoip.local/databases. | | `--maxmind-license-key` | Maxmind license key to download GeoLite2 Databases. https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases . |
| `--metrics-per-host` | Export metrics per-host. (default true) | | `--maxmind-mirror` | Maxmind mirror url (example: http://geoip.local/databases. |
| `--monitor-max-batch-size` | Max batch size of NGINX metrics. (default 10000)| | `--maxmind-retries-count` | Number of attempts to download the GeoIP DB. (default 1) |
| `--post-shutdown-grace-period` | Additional delay in seconds before controller container exits. (default 10) | | `--maxmind-retries-timeout` | Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong. (default 0s) |
| `--profiler-port` | Port to use for expose the ingress controller Go profiler when it is enabled. (default 10245) | | `--metrics-per-host` | Export metrics per-host. (default true) |
| `--profiling` | Enable profiling via web interface host:port/debug/pprof/ . (default true) | | `--monitor-max-batch-size` | Max batch size of NGINX metrics. (default 10000)|
| `--publish-service` | Service fronting the Ingress controller. Takes the form "namespace/name". When used together with update-status, the controller mirrors the address of this service's endpoints to the load-balancer status of all Ingress objects it satisfies. | | `--post-shutdown-grace-period` | Additional delay in seconds before controller container exits. (default 10) |
| `--publish-status-address` | Customized address (or addresses, separated by comma) to set as the load-balancer status of Ingress objects this controller satisfies. Requires the update-status parameter. | | `--profiler-port` | Port to use for expose the ingress controller Go profiler when it is enabled. (default 10245) |
| `--report-node-internal-ip-address`| Set the load-balancer status of Ingress objects to internal Node addresses instead of external. Requires the update-status parameter. (default false) | | `--profiling` | Enable profiling via web interface host:port/debug/pprof/ . (default true) |
| `--report-status-classes` | If true, report status classes in metrics (2xx, 3xx, 4xx and 5xx) instead of full status codes. (default false) | | `--publish-service` | Service fronting the Ingress controller. Takes the form "namespace/name". When used together with update-status, the controller mirrors the address of this service's endpoints to the load-balancer status of all Ingress objects it satisfies. |
| `--ssl-passthrough-proxy-port` | Port to use internally for SSL Passthrough. (default 442) | | `--publish-status-address` | Customized address (or addresses, separated by comma) to set as the load-balancer status of Ingress objects this controller satisfies. Requires the update-status parameter. |
| `--status-port` | Port to use for the lua HTTP endpoint configuration. (default 10246) | | `--report-node-internal-ip-address` | Set the load-balancer status of Ingress objects to internal Node addresses instead of external. Requires the update-status parameter. (default false) |
| `--status-update-interval` | Time interval in seconds in which the status should check if an update is required. Default is 60 seconds. (default 60) | | `--report-status-classes` | If true, report status classes in metrics (2xx, 3xx, 4xx and 5xx) instead of full status codes. (default false) |
| `--stream-port` | Port to use for the lua TCP/UDP endpoint configuration. (default 10247) | | `--shutdown-grace-period` | Seconds to wait after receiving the shutdown signal, before stopping the nginx process. (default 0) |
| `--sync-period` | Period at which the controller forces the repopulation of its local object stores. Disabled by default. | | `--size-buckets` | Set of buckets which will be used for prometheus histogram metrics such as BytesSent. (default `[10, 100, 1000, 10000, 100000, 1e+06, 1e+07]`) |
| `--sync-rate-limit` | Define the sync frequency upper limit. (default 0.3) | | `--ssl-passthrough-proxy-port` | Port to use internally for SSL Passthrough. (default 442) |
| `--tcp-services-configmap` | Name of the ConfigMap containing the definition of the TCP services to expose. The key in the map indicates the external port to be used. The value is a reference to a Service in the form "namespace/name:port", where "port" can either be a port number or name. TCP ports 80 and 443 are reserved by the controller for servicing HTTP traffic. | | `--status-port` | Port to use for the lua HTTP endpoint configuration. (default 10246) |
| `--time-buckets` | Set of buckets which will be used for prometheus histogram metrics such as RequestTime, ResponseTime. (default `[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]`) | | `--status-update-interval` | Time interval in seconds in which the status should check if an update is required. Default is 60 seconds. (default 60) |
| `--udp-services-configmap` | Name of the ConfigMap containing the definition of the UDP services to expose. The key in the map indicates the external port to be used. The value is a reference to a Service in the form "namespace/name:port", where "port" can either be a port name or number. | | `--stream-port` | Port to use for the lua TCP/UDP endpoint configuration. (default 10247) |
| `--update-status` | Update the load-balancer status of Ingress objects this controller satisfies. Requires setting the publish-service parameter to a valid Service reference. (default true) | | `--sync-period` | Period at which the controller forces the repopulation of its local object stores. Disabled by default. |
| `--update-status-on-shutdown` | Update the load-balancer status of Ingress objects when the controller shuts down. Requires the update-status parameter. (default true) | | `--sync-rate-limit` | Define the sync frequency upper limit. (default 0.3) |
| `--shutdown-grace-period` | Seconds to wait after receiving the shutdown signal, before stopping the nginx process. (default 0) | | `--tcp-services-configmap` | Name of the ConfigMap containing the definition of the TCP services to expose. The key in the map indicates the external port to be used. The value is a reference to a Service in the form "namespace/name:port", where "port" can either be a port number or name. TCP ports 80 and 443 are reserved by the controller for servicing HTTP traffic. |
| `--size-buckets` | Set of buckets which will be used for prometheus histogram metrics such as BytesSent. (default `[10, 100, 1000, 10000, 100000, 1e+06, 1e+07]`) | | `--time-buckets` | Set of buckets which will be used for prometheus histogram metrics such as RequestTime, ResponseTime. (default `[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]`) |
| `-v, --v Level` | number for the log level verbosity | | `--udp-services-configmap` | Name of the ConfigMap containing the definition of the UDP services to expose. The key in the map indicates the external port to be used. The value is a reference to a Service in the form "namespace/name:port", where "port" can either be a port name or number. |
| `--validating-webhook` | The address to start an admission controller on to validate incoming ingresses. Takes the form "<host>:port". If not provided, no admission controller is started. | | `--update-status` | Update the load-balancer status of Ingress objects this controller satisfies. Requires setting the publish-service parameter to a valid Service reference. (default true) |
| `--validating-webhook-certificate` | The path of the validating webhook certificate PEM. | | `--update-status-on-shutdown` | Update the load-balancer status of Ingress objects when the controller shuts down. Requires the update-status parameter. (default true) |
| `--validating-webhook-key` | The path of the validating webhook key PEM. | | `--validating-webhook` | The address to start an admission controller on to validate incoming ingresses. Takes the form "<host>:port". If not provided, no admission controller is started. |
| `--version` | Show release information about the Ingress-Nginx Controller and exit. | | `--validating-webhook-certificate` | The path of the validating webhook certificate PEM. |
| `--watch-ingress-without-class` | Define if Ingress Controller should also watch for Ingresses without an IngressClass or the annotation specified. (default false) | | `--validating-webhook-key` | The path of the validating webhook key PEM. |
| `--watch-namespace` | Namespace the controller watches for updates to Kubernetes objects. This includes Ingresses, Services and all configuration resources. All namespaces are watched if this parameter is left empty. | | `--version` | Show release information about the Ingress-Nginx Controller and exit. |
| `--watch-namespace-selector` | The controller will watch namespaces whose labels match the given selector. This flag only takes effective when `--watch-namespace` is empty. | | `--watch-ingress-without-class` | Define if Ingress Controller should also watch for Ingresses without an IngressClass or the annotation specified. (default false) |
| `--watch-namespace` | Namespace the controller watches for updates to Kubernetes objects. This includes Ingresses, Services and all configuration resources. All namespaces are watched if this parameter is left empty. |
| `--watch-namespace-selector` | The controller will watch namespaces whose labels match the given selector. This flag only takes effective when `--watch-namespace` is empty. |

View file

@ -197,6 +197,7 @@ github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcs
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE= github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo= github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo=
github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM= github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM=
@ -255,6 +256,7 @@ golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
@ -267,11 +269,13 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=

View file

@ -107,6 +107,8 @@ type Configuration struct {
MetricsBuckets *collectors.HistogramBuckets MetricsBuckets *collectors.HistogramBuckets
ReportStatusClasses bool ReportStatusClasses bool
ExcludeSocketMetrics []string ExcludeSocketMetrics []string
IncludeIngressLabels []string
IngressLabelsPrefix string
FakeCertificate *ingress.SSLCert FakeCertificate *ingress.SSLCert
@ -726,6 +728,8 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
server = servers[defServerName] server = servers[defServerName]
} }
server.Labels = ing.ObjectMeta.GetLabels()
if rule.HTTP == nil && if rule.HTTP == nil &&
host != defServerName { host != defServerName {
klog.V(3).Infof("Ingress %q does not contain any HTTP rule, using default backend", ingKey) klog.V(3).Infof("Ingress %q does not contain any HTTP rule, using default backend", ingKey)

View file

@ -283,6 +283,7 @@ var funcMap = text_template.FuncMap{
"shouldLoadAuthDigestModule": shouldLoadAuthDigestModule, "shouldLoadAuthDigestModule": shouldLoadAuthDigestModule,
"buildServerName": buildServerName, "buildServerName": buildServerName,
"buildCorsOriginRegex": buildCorsOriginRegex, "buildCorsOriginRegex": buildCorsOriginRegex,
"buildLabels": buildLabels,
} }
// escapeLiteralDollar will replace the $ character with ${literal_dollar} // escapeLiteralDollar will replace the $ character with ${literal_dollar}
@ -1037,6 +1038,7 @@ type ingressInformation struct {
Rule string Rule string
Service string Service string
ServicePort string ServicePort string
Labels map[string]string
Annotations map[string]string Annotations map[string]string
} }
@ -1056,6 +1058,9 @@ func (info *ingressInformation) Equal(other *ingressInformation) bool {
if !reflect.DeepEqual(info.Annotations, other.Annotations) { if !reflect.DeepEqual(info.Annotations, other.Annotations) {
return false return false
} }
if !reflect.DeepEqual(info.Labels, other.Labels) {
return false
}
return true return true
} }
@ -1087,6 +1092,7 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation {
Namespace: ing.GetNamespace(), Namespace: ing.GetNamespace(),
Rule: ing.GetName(), Rule: ing.GetName(),
Annotations: ing.Annotations, Annotations: ing.Annotations,
Labels: ing.Labels,
Path: ingressPath, Path: ingressPath,
} }
@ -1754,3 +1760,16 @@ func buildCorsOriginRegex(corsOrigins []string) string {
originsRegex += ")$ ) { set $cors 'true'; }" originsRegex += ")$ ) { set $cors 'true'; }"
return originsRegex return originsRegex
} }
func buildLabels(labels map[string]string) string {
var parsedLabels []string
for k, v := range labels {
k = strings.Replace(k, ".", "_", -1)
k = strings.Replace(k, "/", "_", -1)
k = strings.Replace(k, "-", "_", -1)
parsedLabels = append(parsedLabels, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(parsedLabels, ";")
}

View file

@ -1180,6 +1180,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
DefaultBackend: &networking.IngressBackend{ DefaultBackend: &networking.IngressBackend{
@ -1202,6 +1205,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "a-svc", Service: "a-svc",
ServicePort: "8080", ServicePort: "8080",
}, },
@ -1215,6 +1221,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
DefaultBackend: &networking.IngressBackend{ DefaultBackend: &networking.IngressBackend{
@ -1237,6 +1246,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "a-svc", Service: "a-svc",
ServicePort: "b-svc", ServicePort: "b-svc",
}, },
@ -1250,6 +1262,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
DefaultBackend: &networking.IngressBackend{ DefaultBackend: &networking.IngressBackend{
@ -1269,6 +1284,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "a-svc", Service: "a-svc",
}, },
}, },
@ -1281,6 +1299,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
Rules: []networking.IngressRule{ Rules: []networking.IngressRule{
@ -1318,6 +1339,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "b-svc", Service: "b-svc",
ServicePort: "80", ServicePort: "80",
}, },
@ -1331,6 +1355,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
Rules: []networking.IngressRule{ Rules: []networking.IngressRule{
@ -1368,6 +1395,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "b-svc", Service: "b-svc",
ServicePort: "b-svc-80", ServicePort: "b-svc-80",
}, },
@ -1381,6 +1411,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
Rules: []networking.IngressRule{ Rules: []networking.IngressRule{
@ -1413,6 +1446,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
}, },
"valid ingress definition with name demo in namespace something and path /ok with both a nil service and a valid one": { "valid ingress definition with name demo in namespace something and path /ok with both a nil service and a valid one": {
@ -1424,6 +1460,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
}, },
Spec: networking.IngressSpec{ Spec: networking.IngressSpec{
Rules: []networking.IngressRule{ Rules: []networking.IngressRule{
@ -1468,6 +1507,9 @@ func TestGetIngressInformation(t *testing.T) {
Annotations: map[string]string{ Annotations: map[string]string{
"ingress.annotation": "ok", "ingress.annotation": "ok",
}, },
Labels: map[string]string{
"test_label": "test_label_value",
},
Service: "b-svc", Service: "b-svc",
ServicePort: "b-svc-80", ServicePort: "b-svc-80",
}, },

View file

@ -21,6 +21,7 @@ import (
"io" "io"
"net" "net"
"os" "os"
"slices"
"strings" "strings"
"syscall" "syscall"
@ -49,6 +50,8 @@ type socketData struct {
Service string `json:"service"` Service string `json:"service"`
Canary string `json:"canary"` Canary string `json:"canary"`
Path string `json:"path"` Path string `json:"path"`
IngressLabels string `json:"ingressLabels"`
} }
// HistogramBuckets allow customizing prometheus histogram buckets values // HistogramBuckets allow customizing prometheus histogram buckets values
@ -82,7 +85,11 @@ type SocketCollector struct {
hosts sets.Set[string] hosts sets.Set[string]
metricsPerHost bool metricsPerHost bool
labels []string
labelsPrefix string
reportStatusClasses bool reportStatusClasses bool
} }
@ -104,7 +111,7 @@ var defObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
// NewSocketCollector creates a new SocketCollector instance using // NewSocketCollector creates a new SocketCollector instance using
// the ingress watch namespace and class used by the controller // the ingress watch namespace and class used by the controller
func NewSocketCollector(pod, namespace, class string, metricsPerHost, reportStatusClasses bool, buckets HistogramBuckets, excludeMetrics []string) (*SocketCollector, error) { func NewSocketCollector(pod, namespace, class string, metricsPerHost, reportStatusClasses bool, buckets HistogramBuckets, excludeMetrics []string, includeIngressMetrics []string, ingressLabelsPrefix string) (*SocketCollector, error) {
socket := "/tmp/nginx/prometheus-nginx.socket" socket := "/tmp/nginx/prometheus-nginx.socket"
// unix sockets must be unlink()ed before being used // unix sockets must be unlink()ed before being used
//nolint:errcheck // Ignore unlink error //nolint:errcheck // Ignore unlink error
@ -131,6 +138,10 @@ func NewSocketCollector(pod, namespace, class string, metricsPerHost, reportStat
requestTags = append(requestTags, "host") requestTags = append(requestTags, "host")
} }
if len(includeIngressMetrics) > 0 {
requestTags = append(requestTags, buildIngressMetricsLabels(includeIngressMetrics, ingressLabelsPrefix)...)
}
em := make(map[string]struct{}, len(excludeMetrics)) em := make(map[string]struct{}, len(excludeMetrics))
for _, m := range excludeMetrics { for _, m := range excludeMetrics {
// remove potential nginx_ingress_controller prefix from the metric name // remove potential nginx_ingress_controller prefix from the metric name
@ -263,6 +274,9 @@ func NewSocketCollector(pod, namespace, class string, metricsPerHost, reportStat
), ),
} }
sc.labels = includeIngressMetrics
sc.labelsPrefix = ingressLabelsPrefix
sc.metricMapping = mm sc.metricMapping = mm
return sc, nil return sc, nil
} }
@ -365,6 +379,13 @@ func (sc *SocketCollector) handleMessage(msg []byte) {
"canary": stats.Canary, "canary": stats.Canary,
} }
if stats.IngressLabels != "-" && len(sc.labels) > 0 {
for label, value := range parseLabels(sc.labels, replaceLabelsString(stats.IngressLabels), sc.labelsPrefix) {
requestLabels[label] = value
collectorLabels[label] = value
}
}
if sc.requests != nil { if sc.requests != nil {
requestsMetric, err := sc.requests.GetMetricWith(collectorLabels) requestsMetric, err := sc.requests.GetMetricWith(collectorLabels)
if err != nil { if err != nil {
@ -575,3 +596,44 @@ func deleteConstants(labels prometheus.Labels) {
delete(labels, "controller_class") delete(labels, "controller_class")
delete(labels, "controller_pod") delete(labels, "controller_pod")
} }
// replaceLabelsString key with underscores, dots and dashes. This is needed to convert the labels to valid prometheus labels.
func replaceLabelsString(labelString string) string {
labelString = strings.Replace(labelString, ".", "_", -1)
labelString = strings.Replace(labelString, "/", "_", -1)
labelString = strings.Replace(labelString, "-", "_", -1)
return labelString
}
// replaceLabels key with underscores, dots and dashes. This is needed to convert the labels to valid prometheus labels.
func replaceLabels(labels []string) []string {
for k, v := range labels {
labels[k] = replaceLabelsString(v)
}
return labels
}
// parseLabels parses the ingressLabels string and returns a map of labels
func parseLabels(includedLabels []string, ingressLabels string, prefix string) map[string]string {
labels := make(map[string]string, len(includedLabels))
for _, v := range strings.Split(ingressLabels, ";") {
label := strings.Split(v, "=")
if slices.Contains(includedLabels, addLabelsPrefix(label[0], prefix)) {
labels[addLabelsPrefix(label[0], prefix)] = label[1]
}
}
return labels
}
// addLabelsPrefix add ingress labels prefix
func addLabelsPrefix(str string, prefix string) string {
return fmt.Sprintf("%s%s", prefix, str)
}
func buildIngressMetricsLabels(labels []string, prefix string) []string {
for i, v := range labels {
labels[i] = addLabelsPrefix(v, prefix)
}
return replaceLabels(labels)
}

View file

@ -85,14 +85,16 @@ func TestCollector(t *testing.T) {
} }
cases := []struct { cases := []struct {
name string name string
data []string data []string
metrics []string metrics []string
useStatusClasses bool useStatusClasses bool
excludeMetrics []string excludeMetrics []string
wantBefore string includeIngressLabels []string
removeIngresses []string ingressLabelsPrefix string
wantAfter string wantBefore string
removeIngresses []string
wantAfter string
}{ }{
{ {
name: "invalid metric object should not increase prometheus metrics", name: "invalid metric object should not increase prometheus metrics",
@ -589,13 +591,103 @@ func TestCollector(t *testing.T) {
nginx_ingress_controller_response_duration_seconds_count{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 1 nginx_ingress_controller_response_duration_seconds_count{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 1
`, `,
}, },
{
name: "include ingress labels metrics exist",
data: []string{`[{
"host":"testshop.com",
"status":"200",
"bytesSent":150.0,
"method":"GET",
"path":"/admin",
"requestLength":300.0,
"requestTime":60.0,
"upstreamLatency":1.0,
"upstreamHeaderTime":5.0,
"upstreamName":"test-upstream",
"upstreamIP":"1.1.1.1:8080",
"upstreamResponseTime":200,
"upstreamStatus":"220",
"namespace":"test-app-production",
"ingress":"web-yml",
"service":"test-app",
"canary":"",
"ingressLabels":"app.kubernetes.io/name=test-app;test=test"
}]`},
metrics: []string{"nginx_ingress_controller_response_duration_seconds"},
includeIngressLabels: []string{"app.kubernetes.io/name"},
useStatusClasses: true,
wantBefore: `
# HELP nginx_ingress_controller_response_duration_seconds The time spent on receiving the response from the upstream server
# TYPE nginx_ingress_controller_response_duration_seconds histogram
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.005"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.01"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.025"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.05"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.1"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.25"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="0.5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="1"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="2.5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="10"} 0
nginx_ingress_controller_response_duration_seconds_bucket{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",le="+Inf"} 1
nginx_ingress_controller_response_duration_seconds_sum{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 200
nginx_ingress_controller_response_duration_seconds_count{app_kubernetes_io_name="test_app",canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 1
`,
},
{
name: "include ingress labels metrics with prefix exist",
data: []string{`[{
"host":"testshop.com",
"status":"200",
"bytesSent":150.0,
"method":"GET",
"path":"/admin",
"requestLength":300.0,
"requestTime":60.0,
"upstreamLatency":1.0,
"upstreamHeaderTime":5.0,
"upstreamName":"test-upstream",
"upstreamIP":"1.1.1.1:8080",
"upstreamResponseTime":200,
"upstreamStatus":"220",
"namespace":"test-app-production",
"ingress":"web-yml",
"service":"test-app",
"canary":"",
"ingressLabels":"app.kubernetes.io/name=test-app;test=test-app"
}]`},
metrics: []string{"nginx_ingress_controller_response_duration_seconds"},
includeIngressLabels: []string{"app.kubernetes.io/name"},
ingressLabelsPrefix: "test_",
useStatusClasses: true,
wantBefore: `
# HELP nginx_ingress_controller_response_duration_seconds The time spent on receiving the response from the upstream server
# TYPE nginx_ingress_controller_response_duration_seconds histogram
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.005"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.01"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.025"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.05"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.1"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.25"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="0.5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="1"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="2.5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="5"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="10"} 0
nginx_ingress_controller_response_duration_seconds_bucket{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app",le="+Inf"} 1
nginx_ingress_controller_response_duration_seconds_sum{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app"} 200
nginx_ingress_controller_response_duration_seconds_count{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx",test_app_kubernetes_io_name="test_app"} 1
`,
},
} }
for _, c := range cases { for _, c := range cases {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
registry := prometheus.NewPedanticRegistry() registry := prometheus.NewPedanticRegistry()
sc, err := NewSocketCollector("pod", "default", "ingress", true, c.useStatusClasses, buckets, c.excludeMetrics) sc, err := NewSocketCollector("pod", "default", "ingress", true, c.useStatusClasses, buckets, c.excludeMetrics, c.includeIngressLabels, c.ingressLabelsPrefix)
if err != nil { if err != nil {
t.Errorf("%v: unexpected error creating new SocketCollector: %v", c.name, err) t.Errorf("%v: unexpected error creating new SocketCollector: %v", c.name, err)
} }

View file

@ -71,7 +71,7 @@ type collector struct {
} }
// NewCollector creates a new metric collector the for ingress controller // NewCollector creates a new metric collector the for ingress controller
func NewCollector(metricsPerHost, reportStatusClasses bool, registry *prometheus.Registry, ingressclass string, buckets collectors.HistogramBuckets, excludedSocketMetrics []string) (Collector, error) { func NewCollector(metricsPerHost, reportStatusClasses bool, registry *prometheus.Registry, ingressclass string, buckets collectors.HistogramBuckets, excludedSocketMetrics []string, includeIngressMetrics []string, ingressLabelsPrefix string) (Collector, error) {
podNamespace := os.Getenv("POD_NAMESPACE") podNamespace := os.Getenv("POD_NAMESPACE")
if podNamespace == "" { if podNamespace == "" {
podNamespace = "default" podNamespace = "default"
@ -89,7 +89,7 @@ func NewCollector(metricsPerHost, reportStatusClasses bool, registry *prometheus
return nil, err return nil, err
} }
s, err := collectors.NewSocketCollector(podName, podNamespace, ingressclass, metricsPerHost, reportStatusClasses, buckets, excludedSocketMetrics) s, err := collectors.NewSocketCollector(podName, podNamespace, ingressclass, metricsPerHost, reportStatusClasses, buckets, excludedSocketMetrics, includeIngressMetrics, ingressLabelsPrefix)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -214,6 +214,8 @@ type Server struct {
SSLPreferServerCiphers string `json:"sslPreferServerCiphers,omitempty"` SSLPreferServerCiphers string `json:"sslPreferServerCiphers,omitempty"`
// AuthTLSError contains the reason why the access to a server should be denied // AuthTLSError contains the reason why the access to a server should be denied
AuthTLSError string `json:"authTLSError,omitempty"` AuthTLSError string `json:"authTLSError,omitempty"`
// Metrics labels from ingress labels
Labels map[string]string `json:"labels,omitempty"`
} }
// Location describes an URI inside a server. // Location describes an URI inside a server.

View file

@ -178,7 +178,10 @@ Requires the update-status parameter.`)
lengthBuckets = flags.Float64Slice("length-buckets", prometheus.LinearBuckets(10, 10, 10), "Set of buckets which will be used for prometheus histogram metrics such as RequestLength, ResponseLength.") lengthBuckets = flags.Float64Slice("length-buckets", prometheus.LinearBuckets(10, 10, 10), "Set of buckets which will be used for prometheus histogram metrics such as RequestLength, ResponseLength.")
sizeBuckets = flags.Float64Slice("size-buckets", prometheus.ExponentialBuckets(10, 10, 7), "Set of buckets which will be used for prometheus histogram metrics such as BytesSent.") sizeBuckets = flags.Float64Slice("size-buckets", prometheus.ExponentialBuckets(10, 10, 7), "Set of buckets which will be used for prometheus histogram metrics such as BytesSent.")
excludeSocketMetrics = flags.StringSlice("exclude-socket-metrics", []string{}, "et of socket request metrics to exclude which won't be exported nor being calculated. E.g. 'nginx_ingress_controller_success,nginx_ingress_controller_header_duration_seconds'.") excludeSocketMetrics = flags.StringSlice("exclude-socket-metrics", []string{}, "et of socket request metrics to exclude which won't be exported nor being calculated. E.g. 'nginx_ingress_controller_success,nginx_ingress_controller_header_duration_seconds'.")
monitorMaxBatchSize = flags.Int("monitor-max-batch-size", 10000, "Max batch size of NGINX metrics.") includeIngressLabels = flags.StringSlice("include-ingress-labels", []string{}, "Set of ingress labels to include in the metrics. E.g. 'app,version'.")
ingressLabelsPrefix = flags.String("ingress-labels-prefix", "", "Prefix for ingress labels in the metrics. E.g. 'ingress_'.")
monitorMaxBatchSize = flags.Int("monitor-max-batch-size", 10000, "Max batch size 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.`)
@ -330,6 +333,8 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
MetricsBuckets: histogramBuckets, MetricsBuckets: histogramBuckets,
ReportStatusClasses: *reportStatusClasses, ReportStatusClasses: *reportStatusClasses,
ExcludeSocketMetrics: *excludeSocketMetrics, ExcludeSocketMetrics: *excludeSocketMetrics,
IncludeIngressLabels: *includeIngressLabels,
IngressLabelsPrefix: *ingressLabelsPrefix,
MonitorMaxBatchSize: *monitorMaxBatchSize, MonitorMaxBatchSize: *monitorMaxBatchSize,
DisableServiceExternalName: *disableServiceExternalName, DisableServiceExternalName: *disableServiceExternalName,
EnableSSLPassthrough: *enableSSLPassthrough, EnableSSLPassthrough: *enableSSLPassthrough,

View file

@ -18,6 +18,7 @@ package flags
import ( import (
"os" "os"
"slices"
"testing" "testing"
) )
@ -109,3 +110,36 @@ func TestMaxmindRetryDownload(t *testing.T) {
t.Fatalf("Expected an error parsing flags but none returned") t.Fatalf("Expected an error parsing flags but none returned")
} }
} }
func TestIncludeIngressLabels(t *testing.T) {
ResetForTesting(func() { t.Fatal("Parsing failed") })
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{
"cmd",
"--default-backend-service", "namespace/test",
"--http-port", "0",
"--https-port", "0",
"--ingress-class", "test",
"--include-ingress-labels", "app.kubernetes.io/name,testlabel",
}
_, conf, err := ParseFlags()
if err != nil {
t.Fatalf("Unexpected error parsing default flags: %v", err)
}
if len(conf.IncludeIngressLabels) != 2 {
t.Fatal("Expected flag \"include-ingress-labels\" should have 2 elements")
}
if !slices.Contains(conf.IncludeIngressLabels, "app.kubernetes.io/name") {
t.Fatal("Expected flag \"include-ingress-labels\" should contain \"app.kubernetes.io/name\"")
}
if !slices.Contains(conf.IncludeIngressLabels, "testlabel") {
t.Fatal("Expected flag \"include-ingress-labels\" should contain \"testlabel\"")
}
}

View file

@ -51,6 +51,8 @@ local function metrics()
upstreamResponseTime = tonumber(ngx.var.upstream_response_time) or -1, upstreamResponseTime = tonumber(ngx.var.upstream_response_time) or -1,
upstreamResponseLength = tonumber(ngx.var.upstream_response_length) or -1, upstreamResponseLength = tonumber(ngx.var.upstream_response_length) or -1,
--upstreamStatus = ngx.var.upstream_status or "-", --upstreamStatus = ngx.var.upstream_status or "-",
ingressLabels = ngx.var.ingress_labels or "-",
} }
end end

View file

@ -757,7 +757,7 @@ stream {
lua_package_path "/etc/nginx/lua/?.lua;/etc/nginx/lua/vendor/?.lua;;"; lua_package_path "/etc/nginx/lua/?.lua;/etc/nginx/lua/vendor/?.lua;;";
lua_shared_dict tcp_udp_configuration_data 5M; lua_shared_dict tcp_udp_configuration_data 5M;
{{ buildResolvers $cfg.Resolver $cfg.DisableIpv6DNS }} {{ buildResolvers $cfg.Resolver $cfg.DisableIpv6DNS }}
init_by_lua_block { init_by_lua_block {
@ -1223,6 +1223,10 @@ stream {
set $location_path {{ $ing.Path | escapeLiteralDollar | quote }}; set $location_path {{ $ing.Path | escapeLiteralDollar | quote }};
set $global_rate_limit_exceeding n; set $global_rate_limit_exceeding n;
{{ if gt (len $server.Labels) 0 }}
set $ingress_labels {{ buildLabels $server.Labels | quote }};
{{ end }}
{{ buildOpentelemetryForLocation $all.Cfg.EnableOpentelemetry $all.Cfg.OpentelemetryTrustIncomingSpan $location }} {{ buildOpentelemetryForLocation $all.Cfg.EnableOpentelemetry $all.Cfg.OpentelemetryTrustIncomingSpan $location }}
{{ if $location.Mirror.Source }} {{ if $location.Mirror.Source }}