-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement grafana setup and prometheus support for all nodes (#120
) Co-authored-by: Shreyas S Bhat <[email protected]>
- Loading branch information
1 parent
8252d03
commit 9a6d95b
Showing
12 changed files
with
255 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
def prometheus_grafana_service(plan, service_name, image, port, command, build_file = None): | ||
files = { | ||
"/app": "configs", | ||
} | ||
if build_file != None: | ||
files["/build"] = build_file | ||
|
||
service = plan.add_service( | ||
name = service_name, | ||
config = ServiceConfig( | ||
image = image, | ||
files = files, | ||
ports = { | ||
"polkadot": PortSpec(port, transport_protocol = "TCP"), | ||
}, | ||
public_ports = { | ||
"polkadot": PortSpec(port, transport_protocol = "TCP"), | ||
}, | ||
entrypoint = command, | ||
), | ||
) | ||
|
||
return service | ||
|
||
def launch_grafana(plan, args): | ||
command = ["/run.sh"] | ||
prometheus_grafana_service(plan, "grafana", "grafana/grafana-dev:10.3.0-147071", 3000, command, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
SERVICE_NAME = "prometheus" | ||
PROMETHEUS_DEFAULT_SCRAPE_INTERVAL = "5s" | ||
METRICS_INFO_ADDITIONAL_CONFIG_KEY = "config" | ||
IMAGE_NAME = "prom/prometheus:latest" | ||
HTTP_PORT_ID = "http" | ||
HTTP_PORT_NUMBER = 9090 | ||
CONFIG_FILENAME = "prometheus-config.yml" | ||
CONFIG_DIR_MOUNTPOINT_ON_PROMETHEUS = "/config" | ||
|
||
shared_utils = import_module("./utils.star") | ||
|
||
USED_PORTS = { | ||
HTTP_PORT_ID: shared_utils.new_port_spec( | ||
HTTP_PORT_NUMBER, | ||
"TCP", | ||
"http", | ||
), | ||
} | ||
|
||
def launch_prometheus( | ||
plan, | ||
args, | ||
service_details, | ||
config_template): | ||
template_data = new_config_template_data( | ||
plan, | ||
args, | ||
service_details, | ||
) | ||
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", | ||
) | ||
|
||
config = get_config(config_files_artifact_name) | ||
prometheus_service = plan.add_service(SERVICE_NAME, config) | ||
|
||
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, | ||
public_ports = USED_PORTS, | ||
files = {CONFIG_DIR_MOUNTPOINT_ON_PROMETHEUS: config_files_artifact_name}, | ||
cmd = [ | ||
"--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", | ||
], | ||
) | ||
|
||
def new_config_template_data(plan, args, service_details): | ||
metrics_jobs = [] | ||
|
||
relay_nodes = args["relaychain"]["nodes"] | ||
for node in relay_nodes: | ||
if node["prometheus"] == True: | ||
endpoint = "{0}:{1}".format(service_details["relaychains"]["relay_service_{}".format(node["name"])].ip_address, service_details["relaychains"]["relay_service_{}".format(node["name"])].ports["prometheus"].number) | ||
|
||
metrics_jobs.append( | ||
new_metrics_job( | ||
job_name = "relay_service_{}".format(node["name"]), | ||
endpoint = endpoint, | ||
scrape_interval = "5s", | ||
), | ||
) | ||
plan.print(node["prometheus"]) | ||
|
||
for parachain in args["para"]: | ||
for node in args["para"][parachain]["nodes"]: | ||
if node["prometheus"] == True: | ||
endpoint = "{0}:{1}".format(service_details["parachains"][parachain.lower()]["parachain_{}".format(node["name"])].ip_address, service_details["parachains"][parachain.lower()]["parachain_{}".format(node["name"])].ports["prometheus"].number) | ||
|
||
metrics_jobs.append( | ||
new_metrics_job( | ||
job_name = "parachain_{}_{}".format(parachain, node["name"]), | ||
endpoint = endpoint, | ||
scrape_interval = "5s", | ||
), | ||
) | ||
|
||
return { | ||
"MetricsJobs": metrics_jobs, | ||
} | ||
|
||
def new_metrics_job( | ||
job_name, | ||
endpoint, | ||
scrape_interval = PROMETHEUS_DEFAULT_SCRAPE_INTERVAL): | ||
return { | ||
"Name": job_name, | ||
"Endpoint": endpoint, | ||
"ScrapeInterval": scrape_interval, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
global: | ||
scrape_interval: 15s | ||
evaluation_interval: 15s | ||
scrape_configs: | ||
- job_name: "prometheus" | ||
scrape_interval: 5s | ||
static_configs: | ||
- targets: ["localhost:9090"] | ||
{{- range $job := .MetricsJobs }} | ||
- job_name: "{{ $job.Name }}" | ||
{{- if $job.ScrapeInterval }} | ||
scrape_interval: {{ $job.ScrapeInterval }} | ||
{{- end }} | ||
static_configs: | ||
- targets: ['{{ $job.Endpoint }}'] | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
NOT_PROVIDED_APPLICATION_PROTOCOL = "" | ||
NOT_PROVIDED_WAIT = "not-provided-wait" | ||
|
||
def new_template_and_data(template, template_data_json): | ||
return struct(template = template, data = template_data_json) | ||
|
||
def path_join(*args): | ||
joined_path = "/".join(args) | ||
return joined_path.replace("//", "/") | ||
|
||
def path_base(path): | ||
split_path = path.split("/") | ||
return split_path[-1] | ||
|
||
def path_dir(path): | ||
split_path = path.split("/") | ||
if len(split_path) <= 1: | ||
return "." | ||
split_path = split_path[:-1] | ||
return "/".join(split_path) or "/" | ||
|
||
def new_port_spec( | ||
number, | ||
transport_protocol, | ||
application_protocol = NOT_PROVIDED_APPLICATION_PROTOCOL, | ||
wait = NOT_PROVIDED_WAIT): | ||
if wait == NOT_PROVIDED_WAIT: | ||
return PortSpec( | ||
number = number, | ||
transport_protocol = transport_protocol, | ||
application_protocol = application_protocol, | ||
) | ||
|
||
return PortSpec( | ||
number = number, | ||
transport_protocol = transport_protocol, | ||
application_protocol = application_protocol, | ||
wait = wait, | ||
) | ||
|
||
def read_file_from_service(plan, service_name, filename): | ||
output = plan.exec( | ||
service_name = service_name, | ||
recipe = ExecRecipe( | ||
command = ["/bin/sh", "-c", "cat {} | tr -d '\n'".format(filename)], | ||
), | ||
) | ||
return output["output"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.