Skip to content

Morgana future/fix/configuration parsing error mmap log buffer size #2428

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MorganaFuture
Copy link
Contributor

@MorganaFuture MorganaFuture commented May 21, 2025

What
This PR introduces a JSON-based configuration system for the Tempesta FW logger daemon with:

  • A dedicated TfwLoggerConfig class for logger settings
  • JSON configuration file support via Boost's property_tree
  • Two operation modes: daemon (background) and handle (foreground for debugging)
  • Support for a logger_config attribute in the access_log directive
  • Updates to Tempesta scripts for compatibility
  • Backward compatibility with existing configuration
  • Add tests

Why
The Tempesta logger configuration is currently scattered across multiple parameters, making it hard to manage. A dedicated JSON file provides a cleaner approach that separates logger settings from the main configuration. This structured format improves error handling and simplifies troubleshooting with the new foreground mode.

Links
#2313

@MorganaFuture MorganaFuture force-pushed the morganaFuture/fix/configuration_parsing_error_mmap_log_buffer_size branch 6 times, most recently from dd475f2 to ed8f747 Compare May 21, 2025 14:30
@MorganaFuture MorganaFuture force-pushed the morganaFuture/fix/configuration_parsing_error_mmap_log_buffer_size branch 3 times, most recently from 6665ef6 to 11122b7 Compare May 22, 2025 13:29
@MorganaFuture MorganaFuture marked this pull request as ready for review May 23, 2025 09:15
Copy link
Contributor

@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

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

A lot of logic was removed with no any comments, just as part of file recreation. Maybe it's better to recreate the PR from #2363 and redo all the changes with small commits with good messages - I affraid we'll just lose some of the logic.

mmap_password=$(get_opt_value "$line" "mmap_password")

[[ -n "$mmap_log" && -n "$mmap_host" ]] ||
error "if mmaps enabled in access log, there have to be mmap_host and mmap_log options"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the wiki as requested in #2313 (comment)

P.S. I see the new wiki page in https://github.com/tempesta-tech/tempesta/wiki/TFW-Logger and we had a discussion on it

@@ -0,0 +1,71 @@
# Tempesta FW
#
# Copyright (C) 2024 Tempesta Technologies, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Copyright (C) 2024 Tempesta Technologies, Inc.
# Copyright (C) 2025 Tempesta Technologies, Inc.

logger/Makefile Outdated
@@ -21,7 +21,7 @@ CLICKHOUSE_BUILD_DIR := $(CLICKHOUSE_DIR)/build
CLICKHOUSE_REPO_URL := https://github.com/ClickHouse/clickhouse-cpp.git
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the copyright year in all the modified files. Git hub hook should do this automatically, so check your settings

logger/Makefile Outdated
Comment on lines 36 to 37
SRCS := tfw_logger.cc mmap_buffer.cc clickhouse.cc tfw_logger_config.cc
OBJS := $(SRCS:.cc=.o)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SRCS := tfw_logger.cc mmap_buffer.cc clickhouse.cc tfw_logger_config.cc
OBJS := $(SRCS:.cc=.o)
OBJS := $(patsubst %.cc, %.o, $(wildcard *.cc))

if (fd < 0) {
spdlog::error("Failed to open device");
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Bunch of logic is removed, it seems mostly about daemonization, but I'm not sure that only that logic - it's hard to compare the files line by line. It seems due to my comment #2363 (comment) , which is wrong - in some of our projects we use docker, which doesn't need daemon(), but once we tried to manage with systemctl, we needed the daemonization mode. @althusky can provide more details on this

Copy link
Contributor

Choose a reason for hiding this comment

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

pid file also removed. By the way, it seems https://github.com/tempesta-tech/escudo/blob/main/manager/main.cc#L73 implements them in a more accurate way, so it could be better to borrow the code from there

void override_clickhouse_max_wait(int ms) { clickhouse_.max_wait = std::chrono::milliseconds(ms); }

private:
fs::path log_path_{"/var/log/tempesta/tfw_logger.log"}; // Log file path
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably it's not a good place for the default path, other defaults live in tfw_logger.cc

void override_clickhouse_user(const std::string& user) { clickhouse_.user = user; }
void override_clickhouse_password(const std::string& password) { clickhouse_.password = password; }
void override_clickhouse_max_events(size_t events) { clickhouse_.max_events = events; }
void override_clickhouse_max_wait(int ms) { clickhouse_.max_wait = std::chrono::milliseconds(ms); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Too wide lines and other coding style violations, e.g. everything in single line

if (!default_config.save_to_file(config_path)) {
throw Except("Failed to create default configuration file");
}
}
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 this and TfwLoggerConfig::save_to_file? We can jsut create a default file and keep in the repo - it will be easier for users to learn from the default file, probably with comments, and we don't need extra C++ programming. At least we do this for Tempesta FW itself

if (clickhouse_.max_events == 0) {
throw std::runtime_error("max_events must be greater than 0");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

even for C++ we usually organize the code to read it from bottom to top, i.e. the calee parse_from_ptree must be above the caller TfwLoggerConfig::load_from_file

@MorganaFuture MorganaFuture force-pushed the morganaFuture/fix/configuration_parsing_error_mmap_log_buffer_size branch 5 times, most recently from c399c84 to 548ae7b Compare May 26, 2025 10:11
- Move all logger-related files to dedicated logger/ directory
- Improve project structure organization
- No functional changes in this commit
@MorganaFuture MorganaFuture force-pushed the morganaFuture/fix/configuration_parsing_error_mmap_log_buffer_size branch from 548ae7b to cb84d27 Compare May 26, 2025 13:15
- Move all logger-related files to dedicated logger/ directory
- Improve project structure organization
- No functional changes in this commit
@MorganaFuture MorganaFuture force-pushed the morganaFuture/fix/configuration_parsing_error_mmap_log_buffer_size branch from cb84d27 to 262c2df Compare May 26, 2025 13:17
@MorganaFuture MorganaFuture marked this pull request as draft May 26, 2025 13:46
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.

2 participants