aboutsummaryrefslogtreecommitdiffstats
path: root/csit.infra.dash/app/cdash/utils
diff options
context:
space:
mode:
Diffstat (limited to 'csit.infra.dash/app/cdash/utils')
-rw-r--r--csit.infra.dash/app/cdash/utils/constants.py97
-rw-r--r--csit.infra.dash/app/cdash/utils/utils.py130
2 files changed, 160 insertions, 67 deletions
diff --git a/csit.infra.dash/app/cdash/utils/constants.py b/csit.infra.dash/app/cdash/utils/constants.py
index 3db0d50f4f..bafa7b7f42 100644
--- a/csit.infra.dash/app/cdash/utils/constants.py
+++ b/csit.infra.dash/app/cdash/utils/constants.py
@@ -17,11 +17,75 @@
does not need to be hard coded here, but can be read from environment variables.
"""
+import os
import logging
from dash import html
+def get_str_from_env(env_var_name: str, default_value: str) -> str:
+ """Attempt to read string from environment variable, return that or default.
+
+ The environment variable must start with perfix "CSIT_".
+
+ If environment variable exists, but is empty (and default is not),
+ empty string is returned.
+
+ :param env_var_name: Base name of environment variable to attempt to read.
+ :param default_value: Value to return if the env var does not exist.
+ :type env_var_names: str
+ :type default_value: str
+ :returns: The value read, or default value.
+ :rtype: str
+ """
+ prefix = "CSIT_"
+ env_str = os.environ.get(prefix + env_var_name, None)
+ if env_str is not None:
+ return env_str
+ return default_value
+
+
+def get_int_from_env(env_var_name: str, default_value: int) -> int:
+ """Attempt to read int from environment variable, return that or default.
+
+ The environment variable must start with perfix "CSIT_".
+
+ String value is read, default is returned also if conversion fails.
+
+ :param env_var_name: Base name of environment variable to attempt to read.
+ :param default_value: Value to return if read or conversion fails.
+ :type env_var_names: str
+ :type default_value: int
+ :returns: The value read, or default value.
+ :rtype: int
+ """
+ try:
+ return int(get_str_from_env(env_var_name, str()))
+ except ValueError:
+ return default_value
+
+
+def get_bool_from_env(env_var_name: str, default_value: bool) -> bool:
+ """Attempt to read bool from environment variable, return that or default.
+
+ The environment variable must start with perfix "CSIT_".
+
+ :param env_var_name: Base name of environment variable to attempt to read.
+ :param default_value: Value to return if read or conversion fails.
+ :type env_var_names: str
+ :type default_value: bool
+ :returns: The value read, or default value.
+ :rtype: bool
+ """
+ env_str = get_str_from_env(env_var_name, str()).lower()
+ if env_str in ("true", "yes", "y", "1"):
+ return True
+ elif env_str in ("false", "no", "n", "0"):
+ return False
+ else:
+ return default_value
+
+
class Constants:
"""Constants used in CDash.
"""
@@ -29,14 +93,24 @@ class Constants:
############################################################################
# General, application wide constants.
+ # Select applications to start.
+ START_TRENDING = get_bool_from_env("START_TRENDING", True)
+ START_REPORT = get_bool_from_env("START_REPORT", True)
+ START_COMPARISONS = get_bool_from_env("START_COMPARISONS", True)
+ START_COVERAGE = get_bool_from_env("START_COVERAGE", True)
+ START_STATISTICS = get_bool_from_env("START_STATISTICS", True)
+ START_FAILURES = get_bool_from_env("START_FAILURES", True)
+ START_SEARCH = get_bool_from_env("START_SEARCH", True)
+ START_DOC = get_bool_from_env("START_DOC", True)
+
# Logging settings.
LOG_LEVEL = logging.INFO
LOG_FORMAT = "%(asctime)s: %(levelname)s: %(message)s"
LOG_DATE_FORMAT = "%Y/%m/%d %H:%M:%S"
# The application title.
- TITLE = "FD.io CSIT"
- BRAND = "CSIT-Dash"
+ TITLE = get_str_from_env("TITLE", "FD.io CSIT")
+ BRAND = get_str_from_env("BRAND", "CSIT-Dash")
# The application description.
DESCRIPTION = "Performance Dashboard"
@@ -45,14 +119,17 @@ class Constants:
EXTERNAL_STYLESHEETS = ["/static/dist/css/bootstrap.css", ]
# URL to Jenkins
- URL_JENKINS = "https://jenkins.fd.io/job/"
+ URL_CICD = get_str_from_env("URL_CICD", "https://jenkins.fd.io/job/")
# URL to logs
- URL_LOGS = "https://logs.fd.io/vex-yul-rot-jenkins-1/"
+ URL_LOGS = get_str_from_env(
+ "URL_LOGS", "https://logs.fd.io/vex-yul-rot-jenkins-1/"
+ )
# URL to the documentation
- URL_DOC_TRENDING = "https://csit.fd.io/cdocs/methodology/trending/analysis/"
- URL_DOC_REL_NOTES = "https://csit.fd.io/cdocs/release_notes/current/"
+ URL_DOC = get_str_from_env("URL_DOC", "https://csit.fd.io/cdocs/")
+ URL_DOC_TRENDING = URL_DOC + "methodology/trending/analysis/"
+ URL_DOC_REL_NOTES = URL_DOC + "release_notes/current/"
# Path and name of the file specifying the HTML layout of the dash
# application.
@@ -82,7 +159,7 @@ class Constants:
# now back to the past.
# TIME_PERIOD = None - means all data (max MAX_TIME_PERIOD days) is read.
# TIME_PERIOD = MAX_TIME_PERIOD - is the default value
- TIME_PERIOD = MAX_TIME_PERIOD # [days]
+ TIME_PERIOD = get_int_from_env("TIME_PERIOD", MAX_TIME_PERIOD) # [days]
############################################################################
# General, application wide, layout affecting constants.
@@ -467,3 +544,9 @@ class Constants:
SEARCH_DOWNLOAD_FILE_NAME = "search_data.csv"
############################################################################
+ # Documentation.
+
+ # The title.
+ DOC_TITLE = "Documentation"
+
+ ############################################################################
diff --git a/csit.infra.dash/app/cdash/utils/utils.py b/csit.infra.dash/app/cdash/utils/utils.py
index 306b4f60d1..e203dfbccd 100644
--- a/csit.infra.dash/app/cdash/utils/utils.py
+++ b/csit.infra.dash/app/cdash/utils/utils.py
@@ -480,37 +480,42 @@ def navbar_trending(active: tuple):
:returns: Navigation bar.
:rtype: dbc.NavbarSimple
"""
+ children = list()
+ if C.START_TRENDING:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.TREND_TITLE,
+ active=active[0],
+ external_link=True,
+ href="/trending"
+ )))
+ if C.START_FAILURES:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.NEWS_TITLE,
+ active=active[1],
+ external_link=True,
+ href="/news"
+ )))
+ if C.START_STATISTICS:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.STATS_TITLE,
+ active=active[2],
+ external_link=True,
+ href="/stats"
+ )))
+ if C.START_SEARCH:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.SEARCH_TITLE,
+ active=active[3],
+ external_link=True,
+ href="/search"
+ )))
+ if C.START_DOC:
+ children.append(dbc.NavItem(dbc.NavLink(
+ "Documentation",
+ id="btn-documentation",
+ )))
return dbc.NavbarSimple(
- children=[
- dbc.NavItem(dbc.NavLink(
- C.TREND_TITLE,
- active=active[0],
- external_link=True,
- href="/trending"
- )),
- dbc.NavItem(dbc.NavLink(
- C.NEWS_TITLE,
- active=active[1],
- external_link=True,
- href="/news"
- )),
- dbc.NavItem(dbc.NavLink(
- C.STATS_TITLE,
- active=active[2],
- external_link=True,
- href="/stats"
- )),
- dbc.NavItem(dbc.NavLink(
- C.SEARCH_TITLE,
- active=active[3],
- external_link=True,
- href="/search"
- )),
- dbc.NavItem(dbc.NavLink(
- "Documentation",
- id="btn-documentation",
- ))
- ],
+ children=children,
id="navbarsimple-main",
brand=C.BRAND,
brand_href="/",
@@ -529,38 +534,43 @@ def navbar_report(active: tuple):
:returns: Navigation bar.
:rtype: dbc.NavbarSimple
"""
+ children = list()
+ if C.START_REPORT:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.REPORT_TITLE,
+ active=active[0],
+ external_link=True,
+ href="/report"
+ )))
+ if C.START_COMPARISONS:
+ children.append(dbc.NavItem(dbc.NavLink(
+ "Comparisons",
+ active=active[1],
+ external_link=True,
+ href="/comparisons"
+ )))
+ if C.START_COVERAGE:
+ children.append(dbc.NavItem(dbc.NavLink(
+ "Coverage Data",
+ active=active[2],
+ external_link=True,
+ href="/coverage"
+ )))
+ if C.START_SEARCH:
+ children.append(dbc.NavItem(dbc.NavLink(
+ C.SEARCH_TITLE,
+ active=active[3],
+ external_link=True,
+ href="/search"
+ )))
+ if C.START_DOC:
+ children.append(dbc.NavItem(dbc.NavLink(
+ "Documentation",
+ id="btn-documentation",
+ )))
return dbc.NavbarSimple(
+ children=children,
id="navbarsimple-main",
- children=[
- dbc.NavItem(dbc.NavLink(
- C.REPORT_TITLE,
- active=active[0],
- external_link=True,
- href="/report"
- )),
- dbc.NavItem(dbc.NavLink(
- "Comparisons",
- active=active[1],
- external_link=True,
- href="/comparisons"
- )),
- dbc.NavItem(dbc.NavLink(
- "Coverage Data",
- active=active[2],
- external_link=True,
- href="/coverage"
- )),
- dbc.NavItem(dbc.NavLink(
- C.SEARCH_TITLE,
- active=active[3],
- external_link=True,
- href="/search"
- )),
- dbc.NavItem(dbc.NavLink(
- "Documentation",
- id="btn-documentation",
- ))
- ],
brand=C.BRAND,
brand_href="/",
brand_external_link=True,