fixed wrong Prometheus metrics

This commit is contained in:
luckysideburn
2024-08-12 12:49:57 +00:00
parent 565e8ad202
commit 2fba2bcb8a
5 changed files with 40 additions and 8 deletions
+19 -1
View File
@@ -98,7 +98,7 @@ var latest_preset_name = "";
var latest_preset_lang = "";
var codename = getCodeName();
const codename_regex = /chaos-codename:\ [a-zA-Z_]*/g;
const chaos_job_regex = /chaos_jobs_status.*/g;
const chaos_job_regex = /chaos_jobs_pod_phase.*/g;
var codename_configured = false;
var chaos_jobs_status = new Map();
var current_color_mode = "light";
@@ -203,6 +203,23 @@ function getMetrics() {
oReq.send();
}
function getChaosJobsPodsPhase() {
var oReq = new XMLHttpRequest();
oReq.onload = function () {
var lines = this.responseText.split('\n');
for (var i = 0;i < lines.length;i++){
metric = lines[i].split(' ');
if (metric[0].match(chaos_job_regex)) {
metrics_split = metric[0].split(":");
chaos_jobs_status.set(metrics_split[1] + ":" + metrics_split[2] + ":" + metrics_split[3], metric[1]);
}
}
};;
oReq.open("GET", k8s_url + "/chaos_jobs_pod_phase");
oReq.send();
}
function scroll_backwards() {
if (chaos_logs_pos > 0){
chaos_logs_pos = chaos_logs_pos -1;
@@ -859,6 +876,7 @@ window.setInterval(function backgroundTasks() {
if (game_mode_switch || programming_mode_switch || log_tail_switch) {
getMetrics();
getChaosJobsPodsPhase();
updateMainMetricsChart();
}
+3 -5
View File
@@ -129,7 +129,7 @@ function savePreset(action) {
oReq.onreadystatechange = function () {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200 && (action == "apply" || action == "save-chaos-program")) {
if (latest_preset_lang == "k-inv") {
console.log("[SAVE-PRESET-CHAOSPROGRAM] Payload: " + $('#currentLoadTest').val());
// console.log("[SAVE-PRESET-CHAOSPROGRAM] Payload: " + $('#currentLoadTest').val());
if ($('#currentLoadTest').val() != "") {
presetBody = $('#currentLoadTest').val();
}
@@ -210,7 +210,6 @@ function drawChaosProgramFlow() {
else {
times = flow["experiments"][i]["loop"] + " times"
}
console.log(flow_html);
if (current_color_mode == "light") {
flow_html = flow_html + '<div class="row"><div class="alert alert-light alert-kinv" id="' + random_code + Math.floor(Math.random() * 9999) +'" role="alert" style="border-color: #000000; border-width: 1.5px;">Do ' + flow["experiments"][i]["name"] + ' ' + times + '</div></div>';
}
@@ -221,7 +220,6 @@ function drawChaosProgramFlow() {
flow_html = flow_html + '<img src="images/down-arrow.png" width="30" height="30" style="margin-bottom: 2%;">';
//console.log("Search " + search_job);
for (let [key, value] of chaos_jobs_status) {
if (key.search(search_job) != -1 ) {
if (current_color_mode == "light") {
@@ -250,7 +248,7 @@ function getSavedPresets() {
oReq.onreadystatechange = function () {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
if ((this.responseText.trim() != "nil") && (this.responseText.trim() != "")) {
console.log("[GET-PRESETS] Response from backend: <" + this.responseText.trim() + ">");
// console.log("[GET-PRESETS] Response from backend: <" + this.responseText.trim() + ">");
var savedPresets = this.responseText.split(",");
for (i = 0; i < savedPresets.length; i++) {
var currentPresetName = savedPresets[i].split("_")[1];
@@ -260,7 +258,7 @@ function getSavedPresets() {
// console.log("[GET-PRESETS] Change border color of buttonId: " + buttonId);
// console.log(document.getElementById(buttonId));
if (document.getElementById(buttonId) == null){
console.log("[GET-PRESETS] Appending button to loadButtonGroup. id: " + buttonId + " presetname: " + currentPresetName.trim());
// console.log("[GET-PRESETS] Appending button to loadButtonGroup. id: " + buttonId + " presetname: " + currentPresetName.trim());
latest_preset_lang = "k-inv";
createChaosProgramButton(currentPresetName.trim(), latest_preset_lang);
} else {
+12
View File
@@ -194,6 +194,18 @@ server {
}
}
location /chaos_jobs_pod_phase {
default_type text/html;
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
for i, res in ipairs(red:keys("chaos_jobs_pod_phase*")) do
ngx.say(res .. " " .. red:get(res))
end
}
}
location /kube/chaos/containers {
lua_need_request_body 'on';
access_by_lua_file "/usr/local/openresty/nginx/conf/kubeinvaders/chaos-containers.lua";
+5 -1
View File
@@ -163,5 +163,9 @@ while True:
codename = pod.metadata.labels.get('chaos-codename')
job_name = pod.metadata.labels.get('job-name')
exp_name = pod.metadata.labels.get('experiment-name')
r.set(f"chaos_jobs_status:{codename}:{exp_name}:{job_name}", pod.status.phase)
if pod.status.phase in ["Pending", "Running", "Succeeded"]:
r.set(f"chaos_jobs_status:{codename}:{exp_name}:{job_name}", 1.0)
else:
r.set(f"chaos_jobs_status:{codename}:{exp_name}:{job_name}", -1)
r.set(f"chaos_jobs_pod_phase:{codename}:{exp_name}:{job_name}", pod.status.phase)
time.sleep(1)
+1 -1
View File
@@ -119,7 +119,7 @@ for exp in parsed_yaml["experiments"]:
if 'additional-labels' in job_attrs and 'chaos-codename' in job_attrs['additional-labels']:
codename = job_attrs['additional-labels']['chaos-codename']
r.set(f"chaos_jobs_status:{codename}:{exp['name']}:{exp['job']}", "Created")
r.set(f"chaos_jobs_status:{codename}:{exp['name']}:{exp['job']}", 0.0)
if r.exists('chaos_node_jobs_total') == 1:
r.incr('chaos_node_jobs_total')