Commit c41a989e authored by Tedi Mitiku's avatar Tedi Mitiku Committed by GitHub

feat: use prometheus kurtosis package (#399)

Moves setup of prometheus server into a kurtosis package to simplify
`launch_prometheus` logic. Now `launch_prometheus` logic only configures
metrics jobs as opposed to configuring metrics jobs and configuring +
starting a prometheus server.

I've verified this works by ensuring grafana dashboards are displaying
metrics.
parent d2755b01
......@@ -66,9 +66,6 @@ def run(plan, args={}):
grafana_dashboards_config_template = read_file(
static_files.GRAFANA_DASHBOARD_PROVIDERS_CONFIG_TEMPLATE_FILEPATH
)
prometheus_config_template = read_file(
static_files.PROMETHEUS_CONFIG_TEMPLATE_FILEPATH
)
prometheus_additional_metrics_jobs = []
plan.print("Read the prometheus, grafana templates")
......@@ -379,7 +376,6 @@ def run(plan, args={}):
plan.print("Launching prometheus...")
prometheus_private_url = prometheus.launch_prometheus(
plan,
prometheus_config_template,
all_el_client_contexts,
all_cl_client_contexts,
prometheus_additional_metrics_jobs,
......
shared_utils = import_module("../shared_utils/shared_utils.star")
SERVICE_NAME = "prometheus"
PROMETHEUS_DEFAULT_SCRAPE_INTERVAL = "15s"
prometheus = import_module("github.com/kurtosis-tech/prometheus-package/main.star")
EXECUTION_CLIENT_TYPE = "execution"
BEACON_CLIENT_TYPE = "beacon"
......@@ -13,22 +10,7 @@ METRICS_INFO_URL_KEY = "url"
METRICS_INFO_PATH_KEY = "path"
METRICS_INFO_ADDITIONAL_CONFIG_KEY = "config"
# TODO(old) I'm not sure if we should use latest version or ping an specific version instead
IMAGE_NAME = "prom/prometheus:latest"
HTTP_PORT_ID = "http"
HTTP_PORT_NUMBER = 9090
CONFIG_FILENAME = "prometheus-config.yml"
CONFIG_DIR_MOUNTPOINT_ON_PROMETHEUS = "/config"
USED_PORTS = {
HTTP_PORT_ID: shared_utils.new_port_spec(
HTTP_PORT_NUMBER,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
)
}
PROMETHEUS_DEFAULT_SCRAPE_INTERVAL = "15s"
# The min/max CPU/memory that prometheus can use
MIN_CPU = 10
......@@ -39,65 +21,25 @@ MAX_MEMORY = 2048
def launch_prometheus(
plan,
config_template,
el_client_contexts,
cl_client_contexts,
additional_metrics_jobs,
ethereum_metrics_exporter_contexts,
):
template_data = new_config_template_data(
metrics_jobs = get_metrics_jobs(
el_client_contexts,
cl_client_contexts,
additional_metrics_jobs,
ethereum_metrics_exporter_contexts,
)
template_and_data = shared_utils.new_template_and_data(
config_template, template_data
)
template_and_data_by_rel_dest_filepath = {}
template_and_data_by_rel_dest_filepath[CONFIG_FILENAME] = template_and_data
config_files_artifact_name = plan.render_templates(
template_and_data_by_rel_dest_filepath, "prometheus-config"
prometheus_url = prometheus.run(
plan, metrics_jobs, MIN_CPU, MAX_CPU, MIN_MEMORY, MAX_MEMORY
)
config = get_config(config_files_artifact_name)
prometheus_service = plan.add_service(SERVICE_NAME, config)
return prometheus_url
private_ip_address = prometheus_service.ip_address
prometheus_service_http_port = prometheus_service.ports[HTTP_PORT_ID].number
return "http://{0}:{1}".format(private_ip_address, prometheus_service_http_port)
def get_config(config_files_artifact_name):
config_file_path = shared_utils.path_join(
CONFIG_DIR_MOUNTPOINT_ON_PROMETHEUS, shared_utils.path_base(CONFIG_FILENAME)
)
return ServiceConfig(
image=IMAGE_NAME,
ports=USED_PORTS,
files={CONFIG_DIR_MOUNTPOINT_ON_PROMETHEUS: config_files_artifact_name},
cmd=[
# You can check all the cli flags starting the container and going to the flags section
# in Prometheus admin page "{{prometheusPublicURL}}/flags" section
"--config.file=" + config_file_path,
"--storage.tsdb.path=/prometheus",
"--storage.tsdb.retention.time=1d",
"--storage.tsdb.retention.size=512MB",
"--storage.tsdb.wal-compression",
"--web.console.libraries=/etc/prometheus/console_libraries",
"--web.console.templates=/etc/prometheus/consoles",
"--web.enable-lifecycle",
],
min_cpu=MIN_CPU,
max_cpu=MAX_CPU,
min_memory=MIN_MEMORY,
max_memory=MAX_MEMORY,
)
def new_config_template_data(
def get_metrics_jobs(
el_client_contexts,
cl_client_contexts,
additional_metrics_jobs,
......@@ -222,9 +164,8 @@ def new_config_template_data(
if job == None:
continue
metrics_jobs.append(job)
return {
"MetricsJobs": metrics_jobs,
}
return metrics_jobs
def new_metrics_job(
......
......@@ -11,11 +11,6 @@ EL_FORKMON_CONFIG_TEMPLATE_FILEPATH = (
STATIC_FILES_DIRPATH + "/el-forkmon-config/config.toml.tmpl"
)
# Prometheus config
PROMETHEUS_CONFIG_TEMPLATE_FILEPATH = (
STATIC_FILES_DIRPATH + "/prometheus-config/prometheus.yml.tmpl"
)
# Validator Ranges config
VALIDATOR_RANGES_CONFIG_TEMPLATE_FILEPATH = (
STATIC_FILES_DIRPATH + "/validator-ranges/config.yaml.tmpl"
......
global:
scrape_interval: 15s
scrape_configs:
{{- range $job := .MetricsJobs }}
- job_name: "{{ $job.Name }}"
metrics_path: "{{ $job.MetricsPath }}"
{{- if $job.ScrapeInterval }}
scrape_interval: {{ $job.ScrapeInterval }}
{{- end }}
static_configs:
- targets: ['{{ $job.Endpoint }}']
labels:{{ range $labelName, $labelValue := $job.Labels }}
{{ $labelName }}: "{{ $labelValue }}"
{{- end }}
{{- end }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment