Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LocalNet] Switch validator logs to json #480

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ load("ext://secret", "secret_create_generic")
# A list of directories where changes trigger a hot-reload of the validator
hot_reload_dirs = ["app", "cmd", "tools", "x", "pkg"]

def merge_dicts(base, updates):
for k, v in updates.items():
if k in base and type(base[k]) == "dict" and type(v) == "dict":
# Assume nested dict and merge
for vk, vv in v.items():
base[k][vk] = vv
else:
# Replace or set the value
base[k] = v

# Create a localnet config file from defaults, and if a default configuration doesn't exist, populate it with default values
localnet_config_path = "localnet_config.yaml"
localnet_config_defaults = {
"validator": {"cleanupBeforeEachStart": True},
"validator": {
"cleanupBeforeEachStart": True,
"logs": {
"level": "info",
"format": "json",
},
},
"observability": {"enabled": True},
"relayminers": {"count": 1},
"gateways": {"count": 1},
Expand All @@ -19,12 +35,16 @@ localnet_config_defaults = {
"helm_chart_local_repo": {"enabled": False, "path": "../helm-charts"},
}
localnet_config_file = read_yaml(localnet_config_path, default=localnet_config_defaults)
# Initial empty config
localnet_config = {}
localnet_config.update(localnet_config_defaults)
localnet_config.update(localnet_config_file)
if (localnet_config_file != localnet_config) or (
not os.path.exists(localnet_config_path)
):
# Load the existing config file, if it exists, or use an empty dict as fallback
localnet_config_file = read_yaml(localnet_config_path, default={})
# Merge defaults into the localnet_config first
merge_dicts(localnet_config, localnet_config_defaults)
# Then merge file contents over defaults
merge_dicts(localnet_config, localnet_config_file)
# Check if there are differences or if the file doesn't exist
if (localnet_config_file != localnet_config) or (not os.path.exists(localnet_config_path)):
print("Updating " + localnet_config_path + " with defaults")
local("cat - > " + localnet_config_path, stdin=encode_yaml(localnet_config))

Expand All @@ -41,7 +61,6 @@ if localnet_config["helm_chart_local_repo"]["enabled"]:
# Observability
print("Observability enabled: " + str(localnet_config["observability"]["enabled"]))
if localnet_config["observability"]["enabled"]:
print("Observability enabled")
helm_repo(
"prometheus-community", "https://prometheus-community.github.io/helm-charts"
)
Expand Down Expand Up @@ -172,6 +191,10 @@ helm_resource(
"--values=./localnet/kubernetes/values-validator.yaml",
"--set=persistence.cleanupBeforeEachStart="
+ str(localnet_config["validator"]["cleanupBeforeEachStart"]),
"--set=logs.level="
+ str(localnet_config["validator"]["logs"]["level"]),
"--set=logs.format="
+ str(localnet_config["validator"]["logs"]["format"]),
"--set=serviceMonitor.enabled="
+ str(localnet_config["observability"]["enabled"]),
],
Expand Down
Loading