Skip to content

Commit e64b547

Browse files
committed
add file for config and constants
1 parent 74fe2bf commit e64b547

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/warnet/constants.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import os
2+
from importlib.resources import files
3+
from pathlib import Path
4+
5+
# Constants used throughout the project
6+
# Storing as constants for now but we might want a more sophisticated config management
7+
# at some point.
8+
SUPPORTED_TAGS = ["27.0", "26.0", "25.1", "24.2", "23.2", "22.2"]
9+
DEFAULT_TAG = SUPPORTED_TAGS[0]
10+
WEIGHTED_TAGS = [
11+
tag for index, tag in enumerate(reversed(SUPPORTED_TAGS)) for _ in range(index + 1)
12+
]
13+
14+
DEFAULT_NAMESPACE = "warnet"
15+
HELM_COMMAND = "helm upgrade --install --create-namespace"
16+
17+
# Directories and files for non-python assets, e.g., helm charts, example scenarios, default configs
18+
SRC_DIR = files("warnet")
19+
RESOURCES_DIR = files("resources")
20+
NETWORK_DIR = RESOURCES_DIR.joinpath("networks")
21+
SCENARIOS_DIR = RESOURCES_DIR.joinpath("scenarios")
22+
CHARTS_DIR = RESOURCES_DIR.joinpath("charts")
23+
MANIFESTS_DIR = RESOURCES_DIR.joinpath("manifests")
24+
NETWORK_FILE = "network.yaml"
25+
DEFAULTS_FILE = "node-defaults.yaml"
26+
NAMESPACES_FILE = "namespaces.yaml"
27+
28+
# Helm charts
29+
BITCOIN_CHART_LOCATION = str(CHARTS_DIR.joinpath("bitcoincore"))
30+
FORK_OBSERVER_CHART = str(CHARTS_DIR.joinpath("fork-observer"))
31+
NAMESPACES_CHART_LOCATION = CHARTS_DIR.joinpath("namespaces")
32+
DEFAULT_NETWORK = Path("6_node_bitcoin")
33+
DEFAULT_NAMESPACES = Path("two_namespaces_two_users")
34+
35+
# Kubeconfig related stuffs
36+
KUBECONFIG = os.environ.get("KUBECONFIG", os.path.expanduser("~/.kube/config"))
37+
38+
# TODO: all of this logging stuff should be a helm chart
39+
LOGGING_CONFIG = {
40+
"version": 1,
41+
"disable_existing_loggers": False,
42+
"formatters": {
43+
"simple": {
44+
"format": "%(asctime)s | %(levelname)-7s | %(name)-8s | %(message)s",
45+
"datefmt": "%Y-%m-%d %H:%M:%S",
46+
},
47+
"detailed": {
48+
"format": "%(asctime)s | %(levelname)-7s | [%(module)21s:%(lineno)4d] | %(message)s",
49+
"datefmt": "%Y-%m-%d %H:%M:%S",
50+
},
51+
},
52+
"handlers": {
53+
"stdout": {
54+
"class": "logging.StreamHandler",
55+
"level": "DEBUG",
56+
"formatter": "simple",
57+
"stream": "ext://sys.stdout",
58+
},
59+
"stderr": {
60+
"class": "logging.StreamHandler",
61+
"level": "WARNING",
62+
"formatter": "simple",
63+
"stream": "ext://sys.stderr",
64+
},
65+
"file": {
66+
"class": "logging.handlers.RotatingFileHandler",
67+
"level": "DEBUG",
68+
"formatter": "detailed",
69+
"filename": "warnet.log",
70+
"maxBytes": 16000000,
71+
"backupCount": 3,
72+
},
73+
},
74+
"loggers": {
75+
"root": {"level": "DEBUG", "handlers": ["stdout", "stderr", "file"]},
76+
"urllib3.connectionpool": {"level": "WARNING", "propagate": 1},
77+
"kubernetes.client.rest": {"level": "WARNING", "propagate": 1},
78+
"werkzeug": {"level": "WARNING", "propagate": 1},
79+
},
80+
}
81+
82+
# Helm commands for logging setup
83+
# TODO: also lots of hardcode stuff in these helm commands, will need to fix this when moving to helm charts
84+
LOGGING_HELM_COMMANDS = [
85+
"helm repo add grafana https://grafana.github.io/helm-charts",
86+
"helm repo add prometheus-community https://prometheus-community.github.io/helm-charts",
87+
"helm repo update",
88+
f"helm upgrade --install --namespace warnet-logging --create-namespace --values {MANIFESTS_DIR}/loki_values.yaml loki grafana/loki --version 5.47.2",
89+
"helm upgrade --install --namespace warnet-logging promtail grafana/promtail",
90+
"helm upgrade --install --namespace warnet-logging prometheus prometheus-community/kube-prometheus-stack --namespace warnet-logging --set grafana.enabled=false",
91+
f"helm upgrade --install --namespace warnet-logging loki-grafana grafana/grafana --values {MANIFESTS_DIR}/grafana_values.yaml",
92+
]

0 commit comments

Comments
 (0)