mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-08-23 21:46:21 +00:00
added code for web tail
This commit is contained in:
+9
-1
@@ -232,7 +232,7 @@ experiments:
|
||||
</div>
|
||||
<div class="row" style="margin-top: 1%;">
|
||||
<div class="col text-center">
|
||||
<button type="button" id="logConsoleButton" class="btn btn-light" onclick="startLogConsole()">Enable Logs Tail</button>
|
||||
<button type="button" id="logConsoleButton" class="btn btn-light" onclick="startLogConsole()">Start Logs Tail</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 1%;">
|
||||
@@ -294,6 +294,14 @@ experiments:
|
||||
programming_mode_buttons.style.display = "none";
|
||||
game_screen.style.display = "none";
|
||||
game_buttons.style.display = "none";
|
||||
|
||||
if (log_tail_switch) {
|
||||
$("#logConsoleButton").text("Start Logs Tail");
|
||||
log_tail_switch = false;
|
||||
} else {
|
||||
$("#logConsoleButton").text("Stop Logs Tail");
|
||||
log_tail_switch = true;
|
||||
}
|
||||
}
|
||||
|
||||
function startGameMode() {
|
||||
|
||||
+31
-2
@@ -28,7 +28,7 @@ var game_buttons = document.getElementById("game-buttons");
|
||||
var game_screen = document.getElementById("game-screen");
|
||||
var chaos_program_screen = document.getElementById("chaos-program-screen");
|
||||
var programming_mode_buttons = document.getElementById("programming-mode-buttons");
|
||||
|
||||
var log_tail_switch = false;
|
||||
// nodes list from kubernetes
|
||||
var nodes = [];
|
||||
|
||||
@@ -195,9 +195,37 @@ function getCurrentChaosContainer() {
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
function setLogRegex() {
|
||||
if (log_tail_switch) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("GET", "https://" + clu_endpoint + "/kube/chaos/containers?action=disabled_logs_tail", true);
|
||||
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
console.log("logs tails disabled");
|
||||
}
|
||||
};;
|
||||
|
||||
oReq.send()
|
||||
|
||||
} else {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=enabled_logs_tail", true);
|
||||
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
console.log("logs tails enabled");
|
||||
}
|
||||
};;
|
||||
|
||||
oReq.setRequestHeader("Content-Type", "application/json");
|
||||
oReq.send($('#logConsoleRegex').val())
|
||||
}
|
||||
}
|
||||
|
||||
function setLogRegex() {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=set_log_pod_regex", true);
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=enabled_logs_tail", true);
|
||||
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
@@ -209,6 +237,7 @@ function setLogRegex() {
|
||||
oReq.send($('#logConsoleRegex').val())
|
||||
}
|
||||
|
||||
|
||||
function setChaosContainer() {
|
||||
if (!IsJsonString($('#currentChaosContainerJsonTextArea').val())) {
|
||||
$('#alert_placeholder2').text('JSON syntax not valid.');
|
||||
|
||||
@@ -33,9 +33,14 @@ elseif ngx.var.request_method == "POST" and action == 'set' then
|
||||
red:set("chaos_container", body_data)
|
||||
ngx.say("New chaos container definition has been configured in Redis")
|
||||
return ngx.exit(ngx.status)
|
||||
elseif ngx.var.request_method == "POST" and action == "set_log_pod_regex" then
|
||||
elseif ngx.var.request_method == "POST" and action == "enabled_logs_tail" then
|
||||
local body_data = ngx.req.get_body_data()
|
||||
red:set("log_pod_regex", body_data)
|
||||
red:set("logs_enabled", "1")
|
||||
ngx.say("New container definition has been saved in Redis")
|
||||
return ngx.exit(ngx.status)
|
||||
elseif ngx.var.request_method == "POST" and action == "disabled_logs_tail" then
|
||||
red:set("logs_enabled", "0")
|
||||
ngx.say("New container definition has been saved in Redis")
|
||||
return ngx.exit(ngx.status)
|
||||
end
|
||||
+13
-12
@@ -49,18 +49,19 @@ namespace = "kubeinvaders"
|
||||
while True:
|
||||
webtail_pods = []
|
||||
final_pod_list = []
|
||||
if r.exists("log_pod_regex"):
|
||||
logging.info("Found regex log_pod_regex in Redis. Logs from all pods should be collected")
|
||||
log_pod_regex = r.get("log_pod_regex")
|
||||
try:
|
||||
api_response = api_instance.list_pod_for_all_namespaces()
|
||||
except ApiException as e:
|
||||
logging.info(e)
|
||||
logging.info(f"Going to search pod compliant with the regex on {len(api_response.items)} pods")
|
||||
for pod in api_response.items:
|
||||
if re.search(f"{log_pod_regex}", pod.metadata.name):
|
||||
webtail_pods.append(pod)
|
||||
logging.info(f"Taking log of {pod.metadata.name} because it is compliant with the regex {log_pod_regex}")
|
||||
if r.exists("log_pod_regex") and r.exists('logs_enabled')
|
||||
if r.get("logs_enabled") == 1:
|
||||
logging.info("Found regex log_pod_regex in Redis. Logs from all pods should be collected")
|
||||
log_pod_regex = r.get("log_pod_regex")
|
||||
try:
|
||||
api_response = api_instance.list_pod_for_all_namespaces()
|
||||
except ApiException as e:
|
||||
logging.info(e)
|
||||
logging.info(f"Going to search pod compliant with the regex on {len(api_response.items)} pods")
|
||||
for pod in api_response.items:
|
||||
if re.search(f"{log_pod_regex}", pod.metadata.name):
|
||||
webtail_pods.append(pod)
|
||||
logging.info(f"Taking log of {pod.metadata.name} because it is compliant with the regex {log_pod_regex}")
|
||||
|
||||
try:
|
||||
api_response = api_instance.list_namespaced_pod(namespace="kubeinvaders")
|
||||
|
||||
Reference in New Issue
Block a user