Skip to content

roles: add log_requests option #211

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

p0rtale
Copy link

@p0rtale p0rtale commented Jun 23, 2025

Currently, HTTP requests are logged at the default level log.info, which can create noise (e.g. for metrics endpoints).
This change allows setting custom log levels (e.g. log.verbose) for incoming requests.

Example:

roles_cfg:
  roles.httpd:
    default:
      listen: 8081
      log_requests: log.verbose
  roles.metrics-export:
    http:
    - endpoints:
      - path: /metrics
        format: prometheus

Closes TNTP-3229

Copy link
Contributor

@a1div0 a1div0 left a comment

Choose a reason for hiding this comment

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

Нужно покрыть минимум одним тестом

@p0rtale p0rtale changed the title roles: add log_requests support Add log_requests support to roles.httpd and set default to false Jun 23, 2025
@p0rtale p0rtale requested a review from a1div0 June 23, 2025 13:28
Copy link
Contributor

@themilchenko themilchenko left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! Please fix some non-critical comments:

  • Amend commits into one if it is about one feature or bug. For example in your case it should be in one commit, because it is all about log_requests option.
  • Prefer prefix with logical module name in commit title, so it can be something like roles: add log_requests option.
  • Add CHANGELOG entry with info about added functional.

http/server.lua Outdated
log_requests = true,
log_requests = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to change default behavior?

Copy link
Author

Choose a reason for hiding this comment

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

To reduce log noise by default. Many endpoints (like metrics) don't need info-level logging

Copy link
Contributor

@themilchenko themilchenko Jun 24, 2025

Choose a reason for hiding this comment

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

Anyway I think that default log level of http server should be info. For example we can have routes of server that user should see in log file in info level.

If we need to decrease its level in case of metrics-export-role, it will be better to have related option for only /metrics route or set it in config here (in httpd role) globally.

Copy link
Contributor

@a1div0 a1div0 Jun 24, 2025

Choose a reason for hiding this comment

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

Merge request appeared in response to a request from the operation workers to remove logging of requests to metrics. Now the idea is to reduce the importance of logging requests from "info" to "debug", remembering that there are audit logs and that it will be possible to change this behavior through configuration settings.

https://jira.vk.team/browse/TNTP-3229

Copy link
Contributor

Choose a reason for hiding this comment

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

Now the idea is to reduce the importance of logging requests from "info" to "debug"

To be honest, I didn't get a motivation of it. Why does default info level not satisfy us? Maybe we can provide non-default level we want manually or even for separate route (for /metrics as an example)?

Copy link
Member

@DifferentialOrange DifferentialOrange Jun 25, 2025

Choose a reason for hiding this comment

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

I agree that for now changing the log level for a server (or for a \metrics handle) show be the option with the same default as it behaves now. Changing the default is a separate question of breaking backward compatibility that must be processed separately (after some discussion regarding whether or not we should actually do it).

Copy link
Contributor

@a1div0 a1div0 Jun 25, 2025

Choose a reason for hiding this comment

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

The main motivation is to avoid clogging the logs at the Info level with this by default:
image

It just interferes with debugging and investigations. Regarding backward compatibility, it is probably worth discussing what can break. As far as I know, in the 3rd version this is only used in metrics.

See TNTP-3229

@p0rtale p0rtale force-pushed the httpd-log-requests branch 2 times, most recently from 1b6f75a to f8b959c Compare June 25, 2025 08:02
@p0rtale p0rtale requested a review from themilchenko June 25, 2025 08:06
@themilchenko
Copy link
Contributor

Please, add note about new parameter somewhere here.

@p0rtale p0rtale force-pushed the httpd-log-requests branch from f8b959c to b6b1e67 Compare June 25, 2025 12:56
@p0rtale p0rtale changed the title Add log_requests support to roles.httpd and set default to false roles: add log_requests option Jun 25, 2025
roles/httpd.lua Outdated
@@ -76,6 +76,7 @@ end
-- it into new() function.
local function parse_params(node)
return {
log_requests = node.log_requests,
Copy link
Member

@DifferentialOrange DifferentialOrange Jun 25, 2025

Choose a reason for hiding this comment

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

parse_params supports functions and booleans for log_requests, but doesn't support strings. So it won't work this way with Tarantool 3 config.

Let's support it then. And we also should add an integration tests to check that it works. And since the string parsing is on us, I think we may use verbose instead of log.verbose and so on.

Copy link
Member

@DifferentialOrange DifferentialOrange left a comment

Choose a reason for hiding this comment

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

Current solution doesn't seem to work.

@p0rtale p0rtale force-pushed the httpd-log-requests branch 3 times, most recently from 952b1c5 to 6051421 Compare June 29, 2025 22:47
Comment on lines +82 to +86
if level == "info" then
log_requests = log.info
elseif level == "verbose" then
log_requests = log.verbose
elseif level == "debug" then
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Does it make sense to log regular requests at levels above info like warn, crit or error? Those levels are typically reserved for exceptional or error situations, not for normal request logging.

@p0rtale p0rtale force-pushed the httpd-log-requests branch from 6051421 to 1e813fb Compare June 30, 2025 09:02
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.

4 participants