bneradt commented on code in PR #13807:
URL: https://github.com/apache/trafficserver/pull/13807#discussion_r4201420906
##########
plugins/experimental/jax_fingerprint/plugin.cc:
##########
@@ -384,69 +357,49 @@ TSPluginInit(int argc, char const **argv)
return;
}
- auto owned_config = std::make_unique<PluginConfig>();
- owned_config->plugin_type = PluginType::GLOBAL;
-
- if (!read_config_option(argc, argv, *owned_config)) {
- TSError("[%s] Failed to parse options.", PLUGIN_NAME);
+ if (argc != 2) {
+ TSError("[%s] Usage: %s <config.yaml>", PLUGIN_NAME, argv[0]);
return;
}
- if (!owned_config->log_filename.empty()) {
- if (!create_log_file(owned_config->log_filename,
owned_config->log_handle)) {
- TSError("[%s] Failed to create log.", PLUGIN_NAME);
- return;
- } else {
- Dbg(dbg_ctl, "Created log file.");
- }
+ PluginConfigs configs;
+ if (!load_config_file(argv[1], PluginType::GLOBAL, configs)) {
+ TSError("[%s] Failed to load configuration from %s.", PLUGIN_NAME,
argv[1]);
+ return;
}
- // Reserve the index before registering the log field, so that every failure
exit happens while the
- // configuration is still owned here and nothing has taken a reference to it
yet.
- if (reserve_user_arg(*owned_config) == TS_ERROR) {
- TSError("[%s] Failed to reserve user arg index.", PLUGIN_NAME);
+ if (!prepare_configs(configs)) {
return;
}
- // A global plugin's configuration lives for the life of the process: the
log field callback and the
- // continuation below both keep a reference to it, so release it from the
unique_ptr here.
- PluginConfig *config = owned_config.release();
-
- if (!config->log_symbol.empty()) {
- std::string name = "jax_fingerprint-";
- name += config->method.name;
- TSLogFieldRegister(
- name.c_str(), config->log_symbol, TS_LOG_TYPE_STRING,
- [config](TSHttpTxn txnp, char *buf) -> int {
- void *container;
- if (config->method.type == Method::Type::CONNECTION_BASED) {
- container = TSHttpSsnClientVConnGet(TSHttpTxnSsnGet(txnp));
- } else {
- container = txnp;
- }
- JAxContext *ctx = get_user_arg(container, *config);
- if (ctx) {
- return TSLogStringMarshal(buf, ctx->get_fingerprint());
- } else {
- return TSLogStringMarshal(buf, "-");
- }
- },
- TSLogIntUnmarshal);
- }
+ g_global_state.config_filename = argv[1];
- TSCont cont = TSContCreate(main_handler, nullptr);
- TSContDataSet(cont, config);
- if (config->method.on_client_hello) {
- TSHttpHookAdd(TS_SSL_CLIENT_HELLO_HOOK, cont);
- }
- if (config->standalone) {
- TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
- }
- if (config->method.type == Method::Type::CONNECTION_BASED) {
- TSHttpHookAdd(TS_VCONN_CLOSE_HOOK, cont);
- } else {
- TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, cont);
+ // Global configurations live for the life of the process: the log field
callbacks and the
+ // continuations below keep references to them, so release them from their
unique_ptrs here.
+ for (auto &owned_config : configs) {
+ PluginConfig *config = owned_config.release();
+ g_global_state.configs.push_back(config);
Review Comment:
Fixed in e2678aa11d. Each plugin.config line now gets its own reload state
(its config filename and entries), attached to that line's lifecycle message
continuation, so each line re-reads and validates only its own file. Reload log
messages now name the file. The reload autest now loads a second
`jax_fingerprint.so jax_fingerprint_ja4h.yaml` line and checks that both files
reload, alongside the existing rejection check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]