mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-02 13:33:11 +00:00
feat: add basic prometheus dynamic target scaffolding
This commit is contained in:
parent
807f3428ee
commit
c4d1a0681e
43
src/prometheus.bash
Normal file
43
src/prometheus.bash
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o pipefail
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
|
||||
_prom_output=${PROM_TARGETS_DIR:-$(clh_output_folder "prometheus")}
|
||||
|
||||
prom_add() {
|
||||
local metrics_port="$1"\
|
||||
experiment_type="$2"\
|
||||
experiment_id="$3"\
|
||||
node="$4"\
|
||||
node_type="$5"
|
||||
|
||||
mkdir -p "${_prom_output}"
|
||||
|
||||
cat > "${_prom_output}/${metrics_port}-${experiment_type}-${experiment_id}-${node}-${node_type}.json" <<EOF
|
||||
{
|
||||
"targets": ["host.docker.internal:${metrics_port}"],
|
||||
"labels": {
|
||||
"job": "${experiment_type}",
|
||||
"experiment_id": "${experiment_id}",
|
||||
"node": "${node}",
|
||||
"node_type": "${node_type}"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
prom_remove() {
|
||||
local metrics_port="$1"\
|
||||
experiment_type="$2"\
|
||||
experiment_id="$3"\
|
||||
node="$4"\
|
||||
node_type="$5"
|
||||
|
||||
rm "${_prom_output}/${metrics_port}-${experiment_type}-${experiment_id}-${node}-${node_type}.json" || true
|
||||
}
|
||||
37
test/test_prometheus.bats
Normal file
37
test/test_prometheus.bats
Normal file
@ -0,0 +1,37 @@
|
||||
setup() {
|
||||
load test_helper/common_setup
|
||||
common_setup
|
||||
|
||||
# shellcheck source=./src/prometheus.bash
|
||||
source "${LIB_SRC}/prometheus.bash"
|
||||
}
|
||||
|
||||
contains() {
|
||||
local file="$1" pattern="$2"
|
||||
grep -F "$pattern" "$file" > /dev/null
|
||||
}
|
||||
|
||||
@test "should create prometheus configurations on start callback" {
|
||||
prom_add "8290" "experiment" "84858" "node-1" "codex"
|
||||
|
||||
config_file="${_prom_output}/8290-experiment-84858-node-1-codex.json"
|
||||
|
||||
assert [ -f "${config_file}" ]
|
||||
|
||||
assert contains "${config_file}" '"targets": ["host.docker.internal:8290"]'
|
||||
assert contains "${config_file}" '"job": "experiment"'
|
||||
assert contains "${config_file}" '"experiment_id": "84858"'
|
||||
assert contains "${config_file}" '"node": "node-1"'
|
||||
assert contains "${config_file}" '"node_type": "codex"'
|
||||
}
|
||||
|
||||
@test "should remove prometheus configurations on stop callback" {
|
||||
prom_add "8290" "experiment" "84858" "node-1" "codex"
|
||||
|
||||
config_file="${_prom_output}/8290-experiment-84858-node-1-codex.json"
|
||||
assert [ -f "${config_file}" ]
|
||||
|
||||
prom_remove "8290" "experiment" "84858" "node-1" "codex"
|
||||
|
||||
assert [ ! -f "${config_file}" ]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user