Skip to content

Commit

Permalink
Added logLevel field for components (#2302)
Browse files Browse the repository at this point in the history
* Added logLevel field for components

* Add changelog

* Fix tests

* Rename 2298.txt to 2302.txt

* Address comments

* Fix tests

* Fix helm tests

* Address comments

* Add client and server loglevels

* Fix bats

* Update changelog

* Fix bats tests
  • Loading branch information
Ganeshrockz committed Jul 28, 2023
1 parent b6d3e61 commit 89ee905
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .changelog/2302.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```release-note:improvement
Add support to provide the logLevel flag via helm for multiple low level components. Introduces the following fields
1. `global.acls.logLevel`
2. `global.tls.logLevel`
3. `global.federation.logLevel`
4. `global.gossipEncryption.logLevel`
5. `server.logLevel`
6. `client.logLevel`
7. `meshGateway.logLevel`
8. `ingressGateways.logLevel`
9. `terminatingGateways.logLevel`
10. `telemetryCollector.logLevel`
```
6 changes: 6 additions & 0 deletions charts/consul/templates/client-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ data:
"auto_reload_config": true
{{- end }}
}
log-level.json: |-
{
{{- if .Values.client.logLevel }}
"log_level": "{{ .Values.client.logLevel | upper }}"
{{- end }}
}
extra-from-values.json: |-
{{ tpl .Values.client.extraConfig . | trimAll "\"" | indent 4 }}
central-config.json: |-
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/create-federation-secret-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
- "-ec"
- |
consul-k8s-control-plane create-federation-secret \
-log-level={{ .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.global.federation.logLevel }} \
-log-json={{ .Values.global.logJSON }} \
{{- if (or .Values.global.gossipEncryption.autoGenerate (and .Values.global.gossipEncryption.secretName .Values.global.gossipEncryption.secretKey)) }}
-gossip-key-file=/consul/gossip/gossip.key \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
-namespace={{ .Release.Namespace }} \
-secret-name={{ template "consul.fullname" . }}-gossip-encryption-key \
-secret-key="key" \
-log-level={{ .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.global.gossipEncryption.logLevel }} \
-log-json={{ .Values.global.logJSON }}
resources:
requests:
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/templates/ingress-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ spec:
-gateway-kind="ingress-gateway" \
-proxy-id-file=/consul/service/proxy-id \
-service-name={{ template "consul.fullname" $root }}-{{ .name }} \
-log-level={{ default $root.Values.global.logLevel }} \
-log-level={{ default $root.Values.global.logLevel $root.Values.ingressGateways.logLevel }} \
-log-json={{ $root.Values.global.logJSON }}
volumeMounts:
- name: consul-service
Expand Down Expand Up @@ -319,7 +319,7 @@ spec:
{{- if $root.Values.global.adminPartitions.enabled }}
- -service-partition={{ $root.Values.global.adminPartitions.name }}
{{- end }}
- -log-level={{ default $root.Values.global.logLevel }}
- -log-level={{ default $root.Values.global.logLevel $root.Values.ingressGateways.logLevel }}
- -log-json={{ $root.Values.global.logJSON }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
- -telemetry-prom-scrape-path=/metrics
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/templates/mesh-gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ spec:
-gateway-kind="mesh-gateway" \
-proxy-id-file=/consul/service/proxy-id \
-service-name={{ .Values.meshGateway.consulServiceName }} \
-log-level={{ default .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.meshGateway.logLevel }} \
-log-json={{ .Values.global.logJSON }}
volumeMounts:
- name: consul-service
Expand Down Expand Up @@ -267,7 +267,7 @@ spec:
{{- if .Values.global.adminPartitions.enabled }}
- -service-partition={{ .Values.global.adminPartitions.name }}
{{- end }}
- -log-level={{ default .Values.global.logLevel }}
- -log-level={{ default .Values.global.logLevel .Values.meshGateway.logLevel }}
- -log-json={{ .Values.global.logJSON }}
{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableGatewayMetrics) }}
- -telemetry-prom-scrape-path=/metrics
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/server-acl-init-cleanup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
- consul-k8s-control-plane
args:
- delete-completed-job
- -log-level={{ .Values.global.logLevel }}
- -log-level={{ default .Values.global.logLevel .Values.global.acls.logLevel }}
- -log-json={{ .Values.global.logJSON }}
- -k8s-namespace={{ .Release.Namespace }}
- {{ template "consul.fullname" . }}-server-acl-init
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ spec:
CONSUL_FULLNAME="{{template "consul.fullname" . }}"
consul-k8s-control-plane server-acl-init \
-log-level={{ .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.global.acls.logLevel}} \
-log-json={{ .Values.global.logJSON }} \
-resource-prefix=${CONSUL_FULLNAME} \
-k8s-namespace={{ .Release.Namespace }} \
Expand Down
3 changes: 3 additions & 0 deletions charts/consul/templates/server-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ data:
},
"datacenter": "{{ .Values.global.datacenter }}",
"data_dir": "/consul/data",
{{- if .Values.server.logLevel }}
"log_level": "{{ .Values.server.logLevel | upper }}",
{{- end }}
"domain": "{{ .Values.global.domain }}",
"limits": {
"request_limits": {
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/templates/telemetry-collector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ spec:
- -ec
- |-
consul-k8s-control-plane connect-init -pod-name=${POD_NAME} -pod-namespace=${POD_NAMESPACE} \
-log-level={{ default .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.telemetryCollector.logLevel }} \
-log-json={{ .Values.global.logJSON }} \
-service-account-name="consul-telemetry-collector" \
-service-name="" \
Expand Down Expand Up @@ -303,7 +303,7 @@ spec:
{{- if .Values.global.metrics.enabled }}
- -telemetry-prom-scrape-path=/metrics
{{- end }}
- -log-level={{ default .Values.global.logLevel }}
- -log-level={{ default .Values.global.logLevel .Values.telemetryCollector.logLevel }}
- -log-json={{ .Values.global.logJSON }}
- -envoy-concurrency=2
{{- if and .Values.externalServers.enabled .Values.externalServers.skipServerWatch }}
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/templates/terminating-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ spec:
-gateway-kind="terminating-gateway" \
-proxy-id-file=/consul/service/proxy-id \
-service-name={{ .name }} \
-log-level={{ default $root.Values.global.logLevel }} \
-log-level={{ default $root.Values.global.logLevel $root.Values.terminatingGateways.logLevel }} \
-log-json={{ $root.Values.global.logJSON }}
volumeMounts:
- name: consul-service
Expand Down Expand Up @@ -300,7 +300,7 @@ spec:
{{- if $root.Values.global.adminPartitions.enabled }}
- -service-partition={{ $root.Values.global.adminPartitions.name }}
{{- end }}
- -log-level={{ default $root.Values.global.logLevel }}
- -log-level={{ default $root.Values.global.logLevel $root.Values.terminatingGateways.logLevel }}
- -log-json={{ $root.Values.global.logJSON }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
- -telemetry-prom-scrape-path=/metrics
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/tls-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
# and use * at the start of the dns name when setting -additional-dnsname.
set -o noglob
consul-k8s-control-plane tls-init \
-log-level={{ .Values.global.logLevel }} \
-log-level={{ default .Values.global.logLevel .Values.global.tls.logLevel }} \
-log-json={{ .Values.global.logJSON }} \
-domain={{ .Values.global.domain }} \
-days=730 \
Expand Down
26 changes: 26 additions & 0 deletions charts/consul/test/unit/client-config-configmap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ load _helpers

[ "${actual}" = null ]
}

#--------------------------------------------------------------------
# logLevel

@test "client/ConfigMap: client.logLevel is empty" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-config-configmap.yaml \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr)

[ "${actual}" = "null" ]
}

@test "client/ConfigMap: client.logLevel is non empty" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-config-configmap.yaml \
--set 'client.enabled=true' \
--set 'client.logLevel=DEBUG' \
. | tee /dev/stderr |
yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr)

[ "${actual}" = "DEBUG" ]
}
6 changes: 3 additions & 3 deletions charts/consul/test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ load _helpers
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = f9be2829fed80a127e3752e10be32f29c2f9ca0ea548abcf3d4fc2c985cb7201 ]
[ "${actual}" = 4fa9ddc3abc4c79eafccb19e5beef80006b7c9736b867d8873554ca03f42a6b3 ]
}

@test "client/DaemonSet: config-checksum annotation changes when extraConfig is provided" {
Expand All @@ -632,7 +632,7 @@ load _helpers
--set 'client.extraConfig="{\"hello\": \"world\"}"' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = e9fb5f0b4ff4e36a89e8ca2dc1aed2072306e0dd6d4cc60b3edf155cf8dbe2e9 ]
[ "${actual}" = 42b99932385e7a0580b134fe36a9bda405aab2e375593326677b9838708f0796 ]
}

@test "client/DaemonSet: config-checksum annotation changes when connectInject.enabled=true" {
Expand All @@ -643,7 +643,7 @@ load _helpers
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = f9be2829fed80a127e3752e10be32f29c2f9ca0ea548abcf3d4fc2c985cb7201 ]
[ "${actual}" = 4fa9ddc3abc4c79eafccb19e5beef80006b7c9736b867d8873554ca03f42a6b3 ]
}

#--------------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions charts/consul/test/unit/create-federation-secret-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,41 @@ load _helpers
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# logLevel

@test "createFederationSecret/Job: logLevel is not set by default" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/create-federation-secret-job.yaml \
--set 'global.federation.enabled=true' \
--set 'meshGateway.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'global.federation.createFederationSecret=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=info"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "createFederationSecret/Job: override the global.logLevel flag with global.federation.logLevel" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/create-federation-secret-job.yaml \
--set 'global.federation.enabled=true' \
--set 'meshGateway.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'global.federation.createFederationSecret=true' \
--set 'global.federation.logLevel=debug' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=debug"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
30 changes: 30 additions & 0 deletions charts/consul/test/unit/gossip-encryption-autogenerate-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,33 @@ load _helpers
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# logLevel

@test "gossipEncryptionAutogenerate/Job: uses the global.logLevel flag by default" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=info"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "gossipEncryptionAutogenerate/Job: overrides the global.logLevel flag when global.gossipEncryption.logLevel is set" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
--set 'global.gossipEncryption.logLevel=debug' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=debug"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
61 changes: 61 additions & 0 deletions charts/consul/test/unit/ingress-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1504,3 +1504,64 @@ key2: value2' \
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# logLevel

@test "ingressGateways/Deployment: use global.logLevel by default" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.initContainers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=info"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "ingressGateways/Deployment: override global.logLevel when ingressGateways.logLevel is set" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'ingressGateways.logLevel=warn' \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.initContainers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=warn"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "ingressGateways/Deployment: use global.logLevel by default for dataplane container" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].args' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=info"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "ingressGateways/Deployment: override global.logLevel when ingressGateways.logLevel is set for dataplane container" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'ingressGateways.logLevel=trace' \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].args' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-log-level=trace"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
Loading

0 comments on commit 89ee905

Please sign in to comment.