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

feat: use prometheus kurtosis package #399

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
77 changes: 9 additions & 68 deletions src/prometheus/prometheus_launcher.star
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions src/static_files/static_files.star
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 0 additions & 15 deletions static_files/prometheus-config/prometheus.yml.tmpl

This file was deleted.