Skip to content

Commit

Permalink
Add Zuul Log Levels to CRD
Browse files Browse the repository at this point in the history
This change add Zuul Log Level to Zuul logs definition

Change-Id: I3176280a2932d55d124295d0e7dd3fb3fe5b9c87
  • Loading branch information
fserucas committed Oct 11, 2023
1 parent c4e91ce commit 05706cb
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

## [Alpha-2]

- [X] Add Zuul Log Levels to CRD
- [X] Add Zuul Bootstrap Zuul Tenant Config subcommand to sfconfig cli
- [X] Create ADR for sfconfig binary
- [X] issue disk space metrics Matthieu Huin
Expand Down
29 changes: 29 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ type ZuulExecutorSpec struct {
Storage StorageSpec `json:"storage,omitempty"`
// How many executor pods to run
Replicas int32 `json:"replicas,omitempty"`
// Specify the Log Level of the zuul-executor service.
// Valid values are:
// - "INFO" (default)
// - "WARN"
// - "DEBUG"
// Changing this value will restart the service.
// +optional
LogLevel LogLevel `json:"logLevel,omitempty"`
}

type ZuulWebSpec struct {
// Specify the Log Level of the zuul-web launcher service.
// Valid values are:
// - "INFO" (default)
// - "WARN"
// - "DEBUG"
// Changing this value will restart the service.
// +optional
LogLevel LogLevel `json:"logLevel,omitempty"`
}

// Spec for the scheduler microservice
Expand All @@ -129,6 +148,14 @@ type ZuulSchedulerSpec struct {
Storage StorageSpec `json:"storage,omitempty"`
// The address to forward statsd metrics to (optional), in the form "host:port"
StatsdTarget string `json:"statsdTarget,omitempty"`
// Specify the Log Level of the zuul-scheduler service.
// Valid values are:
// - "INFO" (default)
// - "WARN"
// - "DEBUG"
// Changing this value will restart the service.
// +optional
LogLevel LogLevel `json:"logLevel,omitempty"`
}

// TODO: make sure to update the GetConnectionsName when adding new connection type.
Expand All @@ -145,6 +172,8 @@ type ZuulSpec struct {
Executor ZuulExecutorSpec `json:"executor,omitempty"`
// Configuration of the scheduler microservice
Scheduler ZuulSchedulerSpec `json:"scheduler,omitempty"`
// Configuration of the web microservice
Web ZuulWebSpec `json:"web,omitempty"`
}

func GetConnectionsName(spec *ZuulSpec) []string {
Expand Down
16 changes: 16 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func EnsureCR(env *utils.ENV, sfconfig *config.SFConfig) {
Puburl: "https://gerrit." + sfconfig.FQDN,
},
}

cr.Spec.StorageClassName = "topolvm-provisioner"
logserverVolumeSize, _ := resource.ParseQuantity("2Gi")
cr.Spec.Logserver.Storage.Size = logserverVolumeSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ spec:
executor:
description: Configuration of the executor microservices
properties:
logLevel:
description: 'Specify the Log Level of the zuul-executor service.
Valid values are: - "INFO" (default) - "WARN" - "DEBUG"
Changing this value will restart the service.'
enum:
- INFO
- WARN
- DEBUG
type: string
replicas:
description: How many executor pods to run
format: int32
Expand Down Expand Up @@ -461,6 +470,15 @@ spec:
scheduler:
description: Configuration of the scheduler microservice
properties:
logLevel:
description: 'Specify the Log Level of the zuul-scheduler
service. Valid values are: - "INFO" (default) - "WARN" -
"DEBUG" Changing this value will restart the service.'
enum:
- INFO
- WARN
- DEBUG
type: string
statsdTarget:
description: The address to forward statsd metrics to (optional),
in the form "host:port"
Expand Down Expand Up @@ -489,6 +507,19 @@ spec:
- size
type: object
type: object
web:
description: Configuration of the web microservice
properties:
logLevel:
description: 'Specify the Log Level of the zuul-web launcher
service. Valid values are: - "INFO" (default) - "WARN" -
"DEBUG" Changing this value will restart the service.'
enum:
- INFO
- WARN
- DEBUG
type: string
type: object
type: object
required:
- fqdn
Expand Down
37 changes: 37 additions & 0 deletions controllers/static/zuul/logging.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 1
formatters:
console:
class: 'zuul.lib.logutil.MultiLineFormatter'
format: '%(levelname)7s %(name)s: %(message)s'
handlers:
console:
class: logging.StreamHandler
formatter: console
level: {{.LogLevel}}
stream: ext://sys.stdout
loggers:
zuul.GerritConnection.io:
handlers:
- console
level: {{ .LogLevel }}
propagate: 0
sqlalchemy.engine:
handlers:
- console
level: {{ .LogLevel }}
propagate: 0
connection:
handlers:
- console
level: {{ .LogLevel }}
propagate: 0
zuul:
handlers:
- console
level: {{ .LogLevel }}
propagate: 0
root:
handlers:
- console
level: {{ .LogLevel }}

3 changes: 3 additions & 0 deletions controllers/static/zuul/zuul.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ tls_key=/tls/client/tls.key

[scheduler]
tenant_config=/var/lib/zuul/main.yaml
log_config=/var/lib/zuul/zuul-scheduler-logging.yaml

[web]
listen_address=0.0.0.0
log_config=/var/lib/zuul/zuul-web-logging.yaml

[executor]
private_key_file=/var/lib/zuul-ssh/..data/priv
# Remove /etc/pki when https://review.opendev.org/c/zuul/zuul/+/884781 is released
trusted_ro_paths=/etc/pki
untrusted_ro_paths=/etc/pki
log_config=/var/lib/zuul/zuul-executor-logging.yaml

[auth zuul_client]
driver=HS256
Expand Down
71 changes: 70 additions & 1 deletion controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var zuulStatsdMappingConfig string
//go:embed static/zuul/generate-tenant-config.sh
var zuulGenerateTenantConfig string

//go:embed static/zuul/logging.yaml.tmpl
var zuulLoggingConfig string

// Common config sections for all Zuul components
var commonIniConfigSections = []string{"zookeeper", "keystore", "database"}

Expand All @@ -55,6 +58,14 @@ func isStatefulset(service string) bool {
return service == "zuul-scheduler" || service == "zuul-executor" || service == "zuul-merger"
}

func mkZuulLoggingMount(service string) apiv1.VolumeMount {
return apiv1.VolumeMount{
Name: "zuul-logging-config",
MountPath: "/var/lib/zuul/" + service + "-logging.yaml",
SubPath: service + "-logging.yaml",
}
}

func (r *SFController) mkZuulContainer(service string) []apiv1.Container {
volumes := []apiv1.VolumeMount{
{
Expand Down Expand Up @@ -95,8 +106,10 @@ func (r *SFController) mkZuulContainer(service string) []apiv1.Container {
MountPath: "/usr/local/bin/generate-zuul-tenant-yaml.sh"},
)
envs = append(envs, r.getTenantsEnvs()...)

}

volumes = append(volumes, mkZuulLoggingMount(service))

command := []string{
"sh", "-c",
fmt.Sprintf("exec %s -f -d", service),
Expand All @@ -117,6 +130,7 @@ func mkZuulVolumes(service string) []apiv1.Volume {
base.MkVolumeSecret("ca-cert"),
base.MkVolumeSecret("zuul-config"),
base.MkVolumeSecret("zookeeper-client-tls"),
base.MkVolumeCM("zuul-logging-config", "zuul-logging-config-map"),
{
Name: "zuul-ssh-key",
VolumeSource: apiv1.VolumeSource{
Expand Down Expand Up @@ -180,6 +194,56 @@ func (r *SFController) mkInitSchedulerConfigContainer() apiv1.Container {
return container
}

func (r *SFController) setZuulLoggingfile() {
loggingData := make(map[string]string)

zuulExecutorLogLevel := sfv1.InfoLogLevel
zuulSchedulerLogLevel := sfv1.InfoLogLevel
zuulWebLogLevel := sfv1.InfoLogLevel
zuulMergerLogLevel := sfv1.InfoLogLevel

if r.cr.Spec.Zuul.Executor.LogLevel != "" {
zuulExecutorLogLevel = r.cr.Spec.Zuul.Executor.LogLevel
}
if r.cr.Spec.Zuul.Scheduler.LogLevel != "" {
zuulSchedulerLogLevel = r.cr.Spec.Zuul.Scheduler.LogLevel
}
if r.cr.Spec.Zuul.Web.LogLevel != "" {
zuulWebLogLevel = r.cr.Spec.Zuul.Web.LogLevel
}
// TODO: Uncomment when Zuul Merger is added
//if r.cr.Spec.Zuul.Merger.LogLevel != "" {
// zuulMerverLogLevel = r.cr.Spec.Zuul.Web.LogLevel
//}

loggingData["zuul-executor-logging.yaml"], _ = utils.ParseString(zuulLoggingConfig, struct {
LogLevel string
}{string(zuulExecutorLogLevel)})

loggingData["zuul-scheduler-logging.yaml"], _ = utils.ParseString(zuulLoggingConfig, struct {
LogLevel string
}{string(zuulSchedulerLogLevel)})

loggingData["zuul-web-logging.yaml"], _ = utils.ParseString(zuulLoggingConfig, struct {
LogLevel string
}{string(zuulWebLogLevel)})

loggingData["zuul-merger-logging.yaml"], _ = utils.ParseString(zuulLoggingConfig, struct {
LogLevel string
}{string(zuulMergerLogLevel)})

r.EnsureConfigMap("zuul-logging", loggingData)

}

func (r *SFController) getZuulLoggingString(service string) string {
var loggingcm apiv1.ConfigMap
if !r.GetM("zuul-logging-config-map", &loggingcm) {
return ""
}
return loggingcm.Data[service+"-logging.yaml"]
}

func (r *SFController) EnsureZuulScheduler(initContainers []apiv1.Container, cfg *ini.File) bool {
sections := utils.IniGetSectionNamesByPrefix(cfg, "connection")
authSections := utils.IniGetSectionNamesByPrefix(cfg, "auth")
Expand All @@ -193,6 +257,7 @@ func (r *SFController) EnsureZuulScheduler(initContainers []apiv1.Container, cfg
"zuul-image": ZuulImage("zuul-scheduler"),
"statsd_mapping": utils.Checksum([]byte(zuulStatsdMappingConfig)),
"serial": "3",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-scheduler"))),
}

if r.isConfigRepoSet() {
Expand All @@ -218,6 +283,7 @@ func (r *SFController) EnsureZuulScheduler(initContainers []apiv1.Container, cfg

schedulerToolingData := make(map[string]string)
schedulerToolingData["generate-zuul-tenant-yaml.sh"] = zuulGenerateTenantConfig

r.EnsureConfigMap("zuul-scheduler-tooling", schedulerToolingData)

zsVolumes := mkZuulVolumes("zuul-scheduler")
Expand Down Expand Up @@ -261,6 +327,7 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool {
"zuul-image": ZuulImage("zuul-executor"),
"replicas": strconv.Itoa(int(r.cr.Spec.Zuul.Executor.Replicas)),
"serial": "1",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-executor"))),
}

ze := r.mkHeadlessSatefulSet("zuul-executor", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Scheduler.Storage), int32(r.cr.Spec.Zuul.Executor.Replicas), apiv1.ReadWriteOnce)
Expand Down Expand Up @@ -307,6 +374,7 @@ func (r *SFController) EnsureZuulWeb(cfg *ini.File) bool {
"zuul-component-config": utils.IniSectionsChecksum(cfg, sections),
"zuul-image": ZuulImage("zuul-web"),
"serial": "1",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-web"))),
}

zw := base.MkDeployment("zuul-web", r.ns, "")
Expand Down Expand Up @@ -353,6 +421,7 @@ func (r *SFController) EnsureZuulComponentsFrontServices() {
func (r *SFController) EnsureZuulComponents(initContainers []apiv1.Container, cfg *ini.File) bool {

zuulServices := map[string]bool{}
r.setZuulLoggingfile()
zuulServices["scheduler"] = r.EnsureZuulScheduler(initContainers, cfg)
zuulServices["executor"] = r.EnsureZuulExecutor(cfg)
zuulServices["web"] = r.EnsureZuulWeb(cfg)
Expand Down

0 comments on commit 05706cb

Please sign in to comment.