diff --git a/html5/index.html b/html5/index.html
index 824482b..969dfe6 100644
--- a/html5/index.html
+++ b/html5/index.html
@@ -232,7 +232,7 @@ experiments:
-
+
@@ -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() {
diff --git a/html5/kubeinvaders.js b/html5/kubeinvaders.js
index 56422a2..6e7ab0a 100644
--- a/html5/kubeinvaders.js
+++ b/html5/kubeinvaders.js
@@ -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.');
diff --git a/scripts/chaos-containers.lua b/scripts/chaos-containers.lua
index 21a692f..88de915 100644
--- a/scripts/chaos-containers.lua
+++ b/scripts/chaos-containers.lua
@@ -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
\ No newline at end of file
diff --git a/scripts/logs_loop/start.py b/scripts/logs_loop/start.py
index 4bfcc87..6d6fd0a 100644
--- a/scripts/logs_loop/start.py
+++ b/scripts/logs_loop/start.py
@@ -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")