From c41a989e95f0c5bcb96987ef55fb673330132b6b Mon Sep 17 00:00:00 2001 From: Tedi Mitiku Date: Tue, 12 Dec 2023 17:45:37 -0500 Subject: [PATCH] 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. --- main.star | 4 - src/prometheus/prometheus_launcher.star | 77 +++---------------- src/static_files/static_files.star | 5 -- .../prometheus-config/prometheus.yml.tmpl | 15 ---- 4 files changed, 9 insertions(+), 92 deletions(-) delete mode 100644 static_files/prometheus-config/prometheus.yml.tmpl diff --git a/main.star b/main.star index 6da3fd1a3..cbaad6b05 100644 --- a/main.star +++ b/main.star @@ -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, diff --git a/src/prometheus/prometheus_launcher.star b/src/prometheus/prometheus_launcher.star index aa0519ca6..61a6b9366 100644 --- a/src/prometheus/prometheus_launcher.star +++ b/src/prometheus/prometheus_launcher.star @@ -1,8 +1,5 @@ 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( diff --git a/src/static_files/static_files.star b/src/static_files/static_files.star index e3d71982a..1050edf55 100644 --- a/src/static_files/static_files.star +++ b/src/static_files/static_files.star @@ -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" diff --git a/static_files/prometheus-config/prometheus.yml.tmpl b/static_files/prometheus-config/prometheus.yml.tmpl deleted file mode 100644 index 6e65bb500..000000000 --- a/static_files/prometheus-config/prometheus.yml.tmpl +++ /dev/null @@ -1,15 +0,0 @@ -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 }}