Logging
You can enable, disable, and view logs for an external Application Load Balancer backend service.
You enable or disable logging for each backend service. You can configure whether to log all requests or a randomly sampled fraction.
You must ensure that you don't have a logs exclusion that applies to external Application Load Balancers. For information about how to verify that external Application Load Balancer logs are allowed, see Log sink filters.
Logs sampling and collection
The requests and corresponding responses that are handled by load balancer
backend virtual machine (VM) instances are sampled. These sampled requests are
then processed to generate logs. You control the fraction of the requests that
are emitted as log entries according to the
logConfig.sampleRate field.
When logConfig.sampleRate is 1.0 (100%), this means that logs are
generated for all of the requests and written to Cloud Logging.
Optional fields
Log records contain required fields and optional fields. The What is logged section lists which fields are optional and which are required. All required fields are always included. You can customize which optional fields you keep.
If you select include all optional, all optional fields in the log record format are included in the logs. When new optional fields are added to the record format, the logs automatically include the new fields.
If you select exclude all optional, all optional fields are omitted.
If you select custom, you can specify the optional fields that you want to include, such as
tls.protocol,tls.cipher,orca_load_report.cpu_utilization,orca_load_report.mem_utilization.
For information about customizing optional fields, see Enable logging on a new backend service.
Enabling logging on a new backend service
Console
In the Google Cloud console, go to the Load Balancing page.
Click the name of your load balancer.
Click Edit.
Click Backend Configuration.
Select Create a backend service.
Complete the required backend service fields.
In the Logging section, select the Enable logging checkbox.
Set a Sample rate fraction. You can set a number from
0.0through1.0, where0.0means that no requests are logged and1.0means that 100% of the requests are logged. The default value is1.0.Optional: To include all the optional fields in the logs, in the Optional fields section, click Include all optional fields.
To finish editing the backend service, click Update.
To finish editing the load balancer, click Update.
gcloud
Create a backend service and enable logging by using the
gcloud compute backend-services create
command.
gcloud compute backend-services create BACKEND_SERVICE \
--region=REGION \
--enable-logging \
--logging-sample-rate=VALUE \
--load-balancing-scheme=EXTERNAL_MANAGED \
--logging-optional=LOGGING_OPTIONAL_MODE \
--logging-optional-fields=OPTIONAL_FIELDS
where
--regionindicates that the backend service is regional. Use this field for backend services used with regional external Application Load Balancers.--enable-loggingenables logging for that backend service.--logging-sample-ratelets you specify a value from0.0through1.0, where0.0means that no requests are logged and1.0means that 100% of the requests are logged. This field is only meaningful with the--enable-loggingparameter. Enabling logging but setting the sampling rate to0.0is equivalent to disabling logging. The default value is1.0.--logging-optionallets you specify the optional fields that you want to include in the logs:INCLUDE_ALL_OPTIONALto include all optional fields.EXCLUDE_ALL_OPTIONAL(default) to exclude all optional fields.CUSTOMto include a custom list of optional fields that you specify inOPTIONAL_FIELDS.
--logging-optional-fieldslets you specify a comma-separated list of optional fields that you want to include in the logs.For example,
tls.protocol,tls.ciphercan only be set ifLOGGING_OPTIONAL_MODEis set toCUSTOM. If you use custom metrics and want to log elements of the ORCA load report, you setLOGGING_OPTIONAL_MODEtoCUSTOMand specify which elements must be logged in theOPTIONAL_FIELDSfield. For example,orca_load_report.cpu_utilization,orca_load_report.mem_utilization.
Enabling logging on an existing backend service
Console
In the Google Cloud console, go to the Load Balancing page.
Click the name of your load balancer.
Click Edit.
Click Backend Configuration.
Click Edit next to your backend service.
In the Logging section, select the Enable logging checkbox.
In the Sample rate field, set the sampling probability. You can set a number from
0.0through1.0, where0.0means that no requests are logged and1.0means that 100% of the requests are logged. The default value is1.0.Optional: To include all the optional fields in the logs, in the Optional fields section, click Include all optional fields.
To finish editing the backend service, click Update.
To finish editing the load balancer, click Update.
gcloud
Enable logging on an existing backend service with the
gcloud compute backend-services update command.
gcloud compute backend-services update BACKEND_SERVICE \
--region=REGION \
--enable-logging \
--logging-sample-rate=VALUE \
--logging-optional=LOGGING_OPTIONAL_MODE \
--logging-optional-fields=OPTIONAL_FIELDS
where
--regionindicates that the backend service is regional. Use this field for backend services used with regional external Application Load Balancers.--enable-loggingenables logging for that backend service.--logging-sample-ratelets you specify a value from0.0through1.0, where0.0means that no requests are logged and1.0means that 100% of the requests are logged. Only meaningful with the--enable-loggingparameter. Enabling logging but setting the sampling rate to0.0is equivalent to disabling logging. The default value is1.0.--logging-optionallets you specify the optional fields that you want to include in the logs.INCLUDE_ALL_OPTIONALto include all optional fields.EXCLUDE_ALL_OPTIONAL(default) to exclude all optional fields.CUSTOMto include a custom list of optional fields that you specify inOPTIONAL_FIELDS.
--logging-optional-fieldslets you specify a comma-separated list of optional fields that you want to include in the logs.For example,
tls.protocol,tls.cipher. Can only be set ifLOGGING_OPTIONAL_MODEis set toCUSTOM. If you use custom metrics and want to log elements of the ORCA load report, you setLOGGING_OPTIONAL_MODEtoCUSTOMand specify which elements must be logged in theOPTIONAL_FIELDSfield. For example,orca_load_report.cpu_utilization,orca_load_report.mem_utilization.