diff --git a/CHANGES/1564.feature b/CHANGES/1564.feature new file mode 100644 index 000000000..d5e6fed55 --- /dev/null +++ b/CHANGES/1564.feature @@ -0,0 +1 @@ +Added gunicorn_access_logformat field to customize access log format for api and content pods. diff --git a/apis/repo-manager.pulpproject.org/v1/pulp_types.go b/apis/repo-manager.pulpproject.org/v1/pulp_types.go index ba0c4ca83..6aaba8f31 100644 --- a/apis/repo-manager.pulpproject.org/v1/pulp_types.go +++ b/apis/repo-manager.pulpproject.org/v1/pulp_types.go @@ -435,6 +435,11 @@ type Api struct { // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number","urn:alm:descriptor:com.tectonic.ui:advanced"} GunicornWorkers int `json:"gunicorn_workers,omitempty"` + // For the gunicorn --access-logformat CLI command used to format the access logs. + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} + GunicornAccessLogformat string `json:"gunicorn_access_logformat,omitempty"` + // Resource requirements for the pulp api container. // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:resourceRequirements","urn:alm:descriptor:com.tectonic.ui:advanced"} @@ -531,6 +536,11 @@ type Content struct { // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number","urn:alm:descriptor:com.tectonic.ui:advanced"} GunicornWorkers int `json:"gunicorn_workers,omitempty"` + // For the gunicorn --access-logformat CLI command used to format the access logs. + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} + GunicornAccessLogformat string `json:"gunicorn_access_logformat,omitempty"` + // Periodic probe of container service readiness. // Container will be removed from service endpoints if the probe fails. // +kubebuilder:validation:Optional diff --git a/bundle/manifests/pulp-operator.clusterserviceversion.yaml b/bundle/manifests/pulp-operator.clusterserviceversion.yaml index 4b7da1916..c423683a4 100644 --- a/bundle/manifests/pulp-operator.clusterserviceversion.yaml +++ b/bundle/manifests/pulp-operator.clusterserviceversion.yaml @@ -216,6 +216,13 @@ spec: path: api.deployment_annotations x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: For the gunicorn --access-logformat CLI command used to format + the access logs. + displayName: Gunicorn Access Logformat + path: api.gunicorn_access_logformat + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: 'The timeout for the gunicorn process. Default: 90' displayName: Gunicorn Timeout path: api.gunicorn_timeout @@ -425,6 +432,13 @@ spec: path: content.deployment_annotations x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: For the gunicorn --access-logformat CLI command used to format + the access logs. + displayName: Gunicorn Access Logformat + path: content.gunicorn_access_logformat + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: 'The timeout for the gunicorn process. Default: 90' displayName: Gunicorn Timeout path: content.gunicorn_timeout diff --git a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml index 6fdd565cb..14edb98a5 100644 --- a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml +++ b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml @@ -1370,6 +1370,10 @@ spec: - name type: object type: array + gunicorn_access_logformat: + description: For the gunicorn --access-logformat CLI command used + to format the access logs. + type: string gunicorn_timeout: description: |- The timeout for the gunicorn process. @@ -4921,6 +4925,10 @@ spec: - name type: object type: array + gunicorn_access_logformat: + description: For the gunicorn --access-logformat CLI command used + to format the access logs. + type: string gunicorn_timeout: description: |- The timeout for the gunicorn process. diff --git a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml index 8892cf78f..4a8620ced 100644 --- a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml +++ b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml @@ -1370,6 +1370,10 @@ spec: - name type: object type: array + gunicorn_access_logformat: + description: For the gunicorn --access-logformat CLI command used + to format the access logs. + type: string gunicorn_timeout: description: |- The timeout for the gunicorn process. @@ -4921,6 +4925,10 @@ spec: - name type: object type: array + gunicorn_access_logformat: + description: For the gunicorn --access-logformat CLI command used + to format the access logs. + type: string gunicorn_timeout: description: |- The timeout for the gunicorn process. diff --git a/config/manifests/bases/pulp-operator.clusterserviceversion.yaml b/config/manifests/bases/pulp-operator.clusterserviceversion.yaml index 4c18abd07..dc0eb9894 100644 --- a/config/manifests/bases/pulp-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/pulp-operator.clusterserviceversion.yaml @@ -226,6 +226,13 @@ spec: path: api.deployment_annotations x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: For the gunicorn --access-logformat CLI command used to format + the access logs. + displayName: Gunicorn Access Logformat + path: api.gunicorn_access_logformat + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: 'The timeout for the gunicorn process. Default: 90' displayName: Gunicorn Timeout path: api.gunicorn_timeout @@ -435,6 +442,13 @@ spec: path: content.deployment_annotations x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: For the gunicorn --access-logformat CLI command used to format + the access logs. + displayName: Gunicorn Access Logformat + path: content.gunicorn_access_logformat + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: 'The timeout for the gunicorn process. Default: 90' displayName: Gunicorn Timeout path: content.gunicorn_timeout diff --git a/controllers/deployment.go b/controllers/deployment.go index 3920f227c..8bb921189 100644 --- a/controllers/deployment.go +++ b/controllers/deployment.go @@ -268,9 +268,21 @@ func (d *CommonDeployment) setEnvVars(resources any, pulpcoreType settings.Pulpc gunicornTimeout = "90" } + // get gunicornAccessLogformat defintion from CR + gunicornAccessLogformat := pulpcoreTypeField.FieldByName("GunicornAccessLogformat").String() + if gunicornAccessLogformat == "" { + if pulpcoreType == settings.CONTENT { + // aiohttp format for content pods using GunicornWebWorker + gunicornAccessLogformat = `%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"` + } else { + gunicornAccessLogformat = `pulp [%({correlation-id}o)s]: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"` + } + } + gunicornEnvVars := []corev1.EnvVar{ {Name: "PULP_GUNICORN_TIMEOUT", Value: gunicornTimeout}, {Name: "PULP_" + strings.ToUpper(string(pulpcoreType)) + "_WORKERS", Value: gunicornWorkers}, + {Name: "PULP_GUNICORN_ACCESS_LOGFORMAT", Value: gunicornAccessLogformat}, } envVars = append(envVars, gunicornEnvVars...) } @@ -992,12 +1004,13 @@ func pulpcoreApiContainerArgs(pulp pulpv1.Pulp) []string { then PULP_API_ENTRYPOINT=("pulpcore-api") else - PULP_API_ENTRYPOINT=("gunicorn" "pulpcore.app.wsgi:application" "--name" "pulp-api" "--access-logformat" "pulp [%({correlation-id}o)s]: %(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s \"%(f)s\" \"%(a)s\"") + PULP_API_ENTRYPOINT=("gunicorn" "pulpcore.app.wsgi:application" "--name" "pulp-api") fi exec "${PULP_API_ENTRYPOINT[@]}" \ --bind "` + gunicornBindAddress + `" \ --timeout "${PULP_GUNICORN_TIMEOUT}" \ --workers "${PULP_API_WORKERS}" \ +--access-logformat "${PULP_GUNICORN_ACCESS_LOGFORMAT}" \ --access-logfile -`, } } @@ -1019,6 +1032,7 @@ exec "${PULP_CONTENT_ENTRYPOINT[@]}" \ --bind "` + gunicornBindAddress + `" \ --timeout "${PULP_GUNICORN_TIMEOUT}" \ --workers "${PULP_CONTENT_WORKERS}" \ +--access-logformat "${PULP_GUNICORN_ACCESS_LOGFORMAT}" \ --access-logfile - `, } diff --git a/controllers/repo_manager/README.md b/controllers/repo_manager/README.md index cff5bf3cd..bb90f5a63 100644 --- a/controllers/repo_manager/README.md +++ b/controllers/repo_manager/README.md @@ -34,6 +34,7 @@ Api defines desired state of pulpcore-api resources | topology_spread_constraints | Topology rule(s) for the pods. | []corev1.TopologySpreadConstraint | false | | gunicorn_timeout | The timeout for the gunicorn process. Default: 90 | int | false | | gunicorn_workers | The number of gunicorn workers to use for the api. Default: 2 | int | false | +| gunicorn_access_logformat | For the gunicorn --access-logformat CLI command used to format the access logs. | string | false | | resource_requirements | Resource requirements for the pulp api container. | corev1.ResourceRequirements | false | | readinessProbe | Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. | *corev1.Probe | false | | livenessProbe | Periodic probe of container liveness. Container will be restarted if the probe fails. | *corev1.Probe | false | @@ -85,6 +86,7 @@ Content defines desired state of pulpcore-content resources | topology_spread_constraints | Topology rule(s) for the pods. | []corev1.TopologySpreadConstraint | false | | gunicorn_timeout | The timeout for the gunicorn process. Default: 90 | int | false | | gunicorn_workers | The number of gunicorn workers to use for the api. Default: 2 | int | false | +| gunicorn_access_logformat | For the gunicorn --access-logformat CLI command used to format the access logs. | string | false | | readinessProbe | Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. | *corev1.Probe | false | | livenessProbe | Periodic probe of container liveness. Container will be restarted if the probe fails. | *corev1.Probe | false | | pdb | PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods | *policy.PodDisruptionBudgetSpec | false | diff --git a/controllers/repo_manager/controller_test.go b/controllers/repo_manager/controller_test.go index 01646994d..4f283c842 100644 --- a/controllers/repo_manager/controller_test.go +++ b/controllers/repo_manager/controller_test.go @@ -183,6 +183,7 @@ var _ = Describe("Pulp controller", Ordered, func() { customEnvVar, {Name: "PULP_GUNICORN_TIMEOUT", Value: strconv.Itoa(90)}, {Name: "PULP_API_WORKERS", Value: strconv.Itoa(2)}, + {Name: "PULP_GUNICORN_ACCESS_LOGFORMAT", Value: `pulp [%({correlation-id}o)s]: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"`}, {Name: "POSTGRES_SERVICE_HOST", Value: PulpName + "-database-svc"}, {Name: "POSTGRES_SERVICE_PORT", Value: "5432"}, {Name: "REDIS_SERVICE_HOST", Value: PulpName + "-redis-svc." + PulpNamespace}, @@ -193,6 +194,7 @@ var _ = Describe("Pulp controller", Ordered, func() { customEnvVar, {Name: "PULP_GUNICORN_TIMEOUT", Value: strconv.Itoa(90)}, {Name: "PULP_CONTENT_WORKERS", Value: strconv.Itoa(2)}, + {Name: "PULP_GUNICORN_ACCESS_LOGFORMAT", Value: `%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"`}, {Name: "POSTGRES_SERVICE_HOST", Value: PulpName + "-database-svc"}, {Name: "POSTGRES_SERVICE_PORT", Value: "5432"}, {Name: "REDIS_SERVICE_HOST", Value: PulpName + "-redis-svc." + PulpNamespace}, @@ -626,12 +628,13 @@ var _ = Describe("Pulp controller", Ordered, func() { then PULP_API_ENTRYPOINT=("pulpcore-api") else - PULP_API_ENTRYPOINT=("gunicorn" "pulpcore.app.wsgi:application" "--name" "pulp-api" "--access-logformat" "pulp [%({correlation-id}o)s]: %(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s \"%(f)s\" \"%(a)s\"") + PULP_API_ENTRYPOINT=("gunicorn" "pulpcore.app.wsgi:application" "--name" "pulp-api") fi exec "${PULP_API_ENTRYPOINT[@]}" \ --bind "[::]:24817" \ --timeout "${PULP_GUNICORN_TIMEOUT}" \ --workers "${PULP_API_WORKERS}" \ +--access-logformat "${PULP_GUNICORN_ACCESS_LOGFORMAT}" \ --access-logfile -`, }, Env: envVarsApi, @@ -745,6 +748,7 @@ exec "${PULP_CONTENT_ENTRYPOINT[@]}" \ --bind "[::]:24816" \ --timeout "${PULP_GUNICORN_TIMEOUT}" \ --workers "${PULP_CONTENT_WORKERS}" \ +--access-logformat "${PULP_GUNICORN_ACCESS_LOGFORMAT}" \ --access-logfile - `, },