Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metrics ability to the lua bouncer #80

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

add metrics ability to the lua bouncer #80

wants to merge 30 commits into from

Conversation

sabban
Copy link
Contributor

@sabban sabban commented Oct 7, 2024

  • add metrics ability to Lua bouncer
  • add some better code management with live and stream mode
  • improve the used cache format; each value is now on the form: decision_cache/$remediation/$origin
  • origin is infered from each decision
  • HTTP requests fully comply with what the console expects
  • The values sent are now deltas

For now, further tests are needed, especially for captcha

Updates:

  • live mode should be fixed
  • get rid of METRICS_PERIOD configuration item
  • add labels for IP types (ipv4, ipv6)

lib/plugins/crowdsec/metrics.lua Outdated Show resolved Hide resolved
lib/plugins/crowdsec/metrics.lua Outdated Show resolved Hide resolved
ngx.log(ngx.INFO, "no labels")
end

key = key .. "/" .. utils.table_to_string(labels)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to show in a comment what a key look like please?

for _, key in ipairs(keys) do
if utils.starts_with(key, "decision_cache/") then
local decision_string = stream.cache:get(key)
local t = utils.split_on_delimiter(decision_string,"/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you show in a comment what are different part of the decision, else it is a mess to understand the rest of the code

lib/plugins/crowdsec/metrics.lua Outdated Show resolved Hide resolved
lib/crowdsec.lua Outdated Show resolved Hide resolved
lib/crowdsec.lua Outdated Show resolved Hide resolved
lib/crowdsec.lua Show resolved Hide resolved
lib/crowdsec.lua Outdated Show resolved Hide resolved
ngx.log(ngx.DEBUG, "timer started: " .. tostring(runtime.timer_started) .. " in worker " .. tostring(ngx.worker.id()))
if runtime.timer_started == false and runtime.conf["MODE"] == "stream" then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did the check on "stream" mode has been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has not been removed you will find it in:

if runtime.conf["MODE"] == "stream" then
   ngx.log(ngx.INFO, "stream mode")
   SetupStream()
end

The metrics code doesn't depend on mode, so that's why it is not ran under a check with stream mode

Copy link
Contributor

@AlteredCoder AlteredCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful with all ngx.INFO messages.
One question, what happens if the remote LAPI doesn't support metrics ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants