Skip to content

Commit

Permalink
fix logging flag in stan config (#1975)
Browse files Browse the repository at this point in the history
* fix logging flag in stan config

* add test cases for stan logging toggle flag

---------

Co-authored-by: Daniel Hoherd <daniel.hoherd@gmail.com>
  • Loading branch information
pgvishnuram and danielhoherd committed Oct 10, 2023
1 parent 25cff33 commit a088980
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
8 changes: 6 additions & 2 deletions charts/stan/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ data:
{{- else }}
id: {{ template "stan.name" . }}
{{- end }}
{{- if .Values.stan.logging.debug }}
sd: true
{{- end }}
{{- if .Values.stan.logging.trace }}
sv: true
{{- end }}
{{- if eq .Values.store.type "sql" }}
store: "sql"
sql_options {
Expand All @@ -38,8 +44,6 @@ data:
store: "file"
dir: {{ .Values.store.file.path }}
{{- end }}
sd: true
sv: true
{{- if .Values.store.cluster.enabled }}
cluster {
node_id: $POD_NAME
Expand Down
2 changes: 1 addition & 1 deletion charts/stan/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ stan:

logging:
debug: true
trace:
trace: false

# In case of NATS not being embedded then
# an URL for NATS is required.
Expand Down
40 changes: 40 additions & 0 deletions tests/chart_tests/test_stan_sts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tests.chart_tests.helm_template_generator import render_chart
import pytest
from tests import supported_k8s_versions, get_containers_by_name
import re


@pytest.mark.parametrize(
Expand Down Expand Up @@ -246,3 +247,42 @@ def test_stan_statefulset_with_private_registry(self, kube_version):
assert container["image"].startswith(
private_registry
), f"Container named '{name}' does not use registry '{private_registry}': {container}"

def test_stan_configmap_with_logging_defaults(self, kube_version):
"""Test that stan configmap with logging defaults."""
docs = render_chart(
kube_version=kube_version,
show_only=["charts/stan/templates/configmap.yaml"],
values={},
)

assert len(docs) == 1
doc = docs[0]
assert doc["kind"] == "ConfigMap"
assert doc["apiVersion"] == "v1"
config = doc["data"]["stan.conf"]
sd_match = re.search(r"sd:\s+(.*?)\n", config)
sd = sd_match.group(1)
assert sd == "true"

def test_stan_configmap_with_logging_overrides(self, kube_version):
"""Test that stan configmap with logging defaults."""
docs = render_chart(
kube_version=kube_version,
show_only=["charts/stan/templates/configmap.yaml"],
values={
"stan": {"stan": {"logging": {"trace": "true"}}},
},
)

assert len(docs) == 1
doc = docs[0]
assert doc["kind"] == "ConfigMap"
assert doc["apiVersion"] == "v1"
config = doc["data"]["stan.conf"]
sd_match = re.search(r"sd:\s+(.*?)\n", config)
sv_match = re.search(r"sv:\s+(.*?)\n", config)
sd = sd_match.group(1)
sv = sv_match.group(1)
assert sd == "true"
assert sv == "true"

0 comments on commit a088980

Please sign in to comment.