mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-08-23 21:46:21 +00:00
fix log
This commit is contained in:
+31
-15
@@ -105,33 +105,49 @@ server {
|
||||
}
|
||||
|
||||
location /metrics {
|
||||
default_type text/html;
|
||||
default_type text/html;
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
-- local okredis, errredis = red:connect(os.getenv("REDIS_HOST"), 6379)
|
||||
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
||||
|
||||
for i, res in ipairs(red:keys("*")) do
|
||||
ngx.log(ngx.ERR, res)
|
||||
|
||||
for i, res in ipairs(red:keys("*total*")) do
|
||||
if string.find(res, "chaos_node_jobs_total_on") then
|
||||
node = string.gsub(res, "chaos_node_jobs_total_on_", "")
|
||||
metric = "chaos_jobs_node_count{node=\"".. node .."\"}"
|
||||
local node = string.gsub(res, "chaos_node_jobs_total_on_", "")
|
||||
local metric = "chaos_jobs_node_count{node=\"".. node .."\"}"
|
||||
ngx.say(metric .. " " .. red:get(res))
|
||||
|
||||
elseif string.find(res, "deleted_pods_total_on") then
|
||||
namespace = string.gsub(res, "deleted_pods_total_on_", "")
|
||||
metric = "deleted_namespace_pods_count{namespace=\"".. namespace .."\"}"
|
||||
local namespace = string.gsub(res, "deleted_pods_total_on_", "")
|
||||
local metric = "deleted_namespace_pods_count{namespace=\"".. namespace .."\"}"
|
||||
ngx.say(metric .. " " .. red:get(res))
|
||||
|
||||
-- TO DO: Use improved regex...
|
||||
elseif not string.find(res, "programming_mode") and not string.find(res, "log:") and not string.find(res, "log_") then
|
||||
ngx.say(res .. " " .. red:get(res))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
local metrics = {
|
||||
'chaos_node_jobs_total',
|
||||
'deleted_pods_total',
|
||||
'fewer_replicas_seconds',
|
||||
'latest_fewer_replicas_seconds',
|
||||
'pods_not_running_on_selected_ns',
|
||||
'current_chaos_job_pod'
|
||||
}
|
||||
|
||||
local metric_name = ""
|
||||
local metric_value = ""
|
||||
|
||||
for key, value in ipairs(metrics) do
|
||||
metric_name = value
|
||||
|
||||
if (red:exists(metric_name) == 1) then
|
||||
metric_value = red:get(metric_name)
|
||||
ngx.say(metric_name .. " " .. metric_value)
|
||||
end
|
||||
end
|
||||
|
||||
for i, res in ipairs(red:keys("chaos_jobs_status*")) do
|
||||
ngx.say(res .. " " .. red:get(res))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ local http = require("socket.http")
|
||||
math.randomseed(os.clock()*100000000000)
|
||||
local rand = math.random(999, 9999)
|
||||
local arg = ngx.req.get_uri_args()
|
||||
local k8s_url = ""
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
|
||||
@@ -153,7 +153,8 @@ while True:
|
||||
|
||||
webtail_pods = []
|
||||
final_pod_list = []
|
||||
if r.exists(f"log_pod_regex:{logid}") and r.exists(f"logs_enabled:{logid}") and r.get("programming_mode") == "0":
|
||||
if r.exists(f"log_pod_regex:{logid}") and r.exists(f"logs_enabled:{logid}"):
|
||||
# and r.get("programming_mode") == "0":
|
||||
logging.info(f"[logid:{logid}] Found Redis keys for log tail")
|
||||
if r.get(f"logs_enabled:{logid}") == "1":
|
||||
logging.info(f"[logid:{logid}] Found regex log_pod_regex in Redis. Logs from all pods should be collected")
|
||||
@@ -203,15 +204,15 @@ while True:
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}|")
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}|")
|
||||
|
||||
if re.search(f"{pod_re}", pod.metadata.name):
|
||||
if re.search(f"{pod_re}", pod.metadata.name) or re.search(r"{pod_re}", pod.metadata.name):
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}| RESULT: OK")
|
||||
regex_key_name = "regex_cmp:{regexsha}:{regexsha}:{logid}:{pod.metadata.namespace}:{pod.metadata.name}"
|
||||
regex_key_name = f"regex_cmp:{regexsha}:{regexsha}:{logid}:{pod.metadata.namespace}:{pod.metadata.name}"
|
||||
|
||||
if re.search(f"{namespace_re}", pod.metadata.namespace):
|
||||
if re.search(f"{namespace_re}", pod.metadata.namespace) or re.search(r"{namespace_re}", pod.metadata.namespace):
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}| RESULT: OK")
|
||||
if re.search(f"{labels_re}", str(pod.metadata.labels)):
|
||||
if re.search(f"{labels_re}", str(pod.metadata.labels)) or re.search(r"{labels_re}", str(pod.metadata.labels)):
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}| RESULT: OK")
|
||||
if re.search(f"{annotations_re}", str(pod.metadata.annotations)):
|
||||
if re.search(f"{annotations_re}", str(pod.metadata.annotations)) or re.search(r"{annotations_re}", str(pod.metadata.annotations)):
|
||||
logging.info(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}| RESULT: OK")
|
||||
webtail_pods.append(pod)
|
||||
regex_match_info = f"[logid:{logid}] Taking logs from {pod.metadata.name}. It is compliant with the Regex {log_pod_regex}"
|
||||
|
||||
@@ -3,6 +3,8 @@ local ltn12 = require "ltn12"
|
||||
local json = require 'lunajson'
|
||||
local redis = require "resty.redis"
|
||||
|
||||
k8s_url = ""
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
else
|
||||
|
||||
@@ -4,6 +4,8 @@ local json = require 'lunajson'
|
||||
local redis = require "resty.redis"
|
||||
local incr = 0
|
||||
|
||||
k8s_url = ""
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
else
|
||||
|
||||
@@ -12,6 +12,8 @@ else
|
||||
ngx.log(ngx.ERR, errredis)
|
||||
end
|
||||
|
||||
local k8s_url = ""
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user