Skip to content

Commit b897565

Browse files
David Huynh (Infra)meta-codesync[bot]
authored andcommitted
Add a standalone option for additional-config-params
Summary: Adds a new `--additional-config-params` CLI option for standalone mcrouter. This option accepts the same `name:value,name:value` format as `--config-params`, but is merged into `config_params` *after* the normal config params have been resolved from flavors and command-line overrides. On key conflicts, the additional params take precedence. This is useful for workflows that need to inject extra config params without replacing the ones already set via `--config-params` or flavors — for example, overriding a single param in a wrapper script while preserving the rest. The parsing applies `substituteTemplates` for template variable expansion, validates that each pair has a non-empty key and a colon separator, and gracefully handles trailing or consecutive commas. Reviewed By: lenar-f Differential Revision: D93257027 fbshipit-source-id: ad844594cb1357b0b1d3d4d231614fdb4aa02dd9
1 parent 828ca3d commit b897565

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

third-party/mcrouter/src/mcrouter/StandaloneUtils.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <vector>
2020

2121
#include <folly/Conv.h>
22+
#include <folly/String.h>
2223
#include <folly/system/HardwareConcurrency.h>
2324

2425
#include "mcrouter/CarbonRouterInstance.h"
@@ -27,6 +28,7 @@
2728
#include "mcrouter/Server.h"
2829
#include "mcrouter/StandaloneConfig.h"
2930
#include "mcrouter/config.h"
31+
#include "mcrouter/lib/fbi/cpp/util.h"
3032
#include "mcrouter/options.h"
3133
#include "mcrouter/standalone_options.h"
3234
#include "mcrouter/stats.h"
@@ -105,6 +107,10 @@ void printUsage(const char* option, const char* description) {
105107
printUsage(
106108
" --service-name",
107109
"Set the service name for standalone mcrouter. Default is \"mcrouter\".");
110+
printUsage(
111+
" --additional-config-params",
112+
"Additional config params merged after --config-params. "
113+
"Same format: 'name1:value1,name2:value2'. Overrides on conflict.");
108114

109115
fprintf(stderr, "\nRETURN VALUE\n");
110116
printUsage("2", "On a problem that might be resolved by restarting later.");
@@ -246,6 +252,7 @@ CmdLineOptions parseCmdLineOptions(int argc, char** argv, std::string pkgName) {
246252
{"validate-config", 2, nullptr, 0},
247253
{"proxy-threads", 1, nullptr, 0},
248254
{"service-name", 1, nullptr, 0},
255+
{"additional-config-params", 1, nullptr, 0},
249256

250257
// Deprecated or not supported
251258
{"gets", 0, nullptr, 0},
@@ -379,6 +386,10 @@ CmdLineOptions parseCmdLineOptions(int argc, char** argv, std::string pkgName) {
379386
} else if (strcmp("service-name", longOptions[longIndex].name) == 0) {
380387
// setup service name for standalone mcrouter
381388
res.serviceName = optarg;
389+
} else if (
390+
strcmp("additional-config-params", longOptions[longIndex].name) ==
391+
0) {
392+
res.additionalConfigParams = optarg;
382393
} else {
383394
res.unrecognizedOptions.insert(argv[optind - 1]);
384395
}
@@ -459,6 +470,31 @@ void setupStandaloneMcrouter(
459470
auto standaloneErrors =
460471
standaloneOptions.updateFromDict(standaloneOptionsDict);
461472

473+
// Merge additional-config-params into config_params.
474+
// Additional params take precedence over existing config_params.
475+
if (!cmdLineOpts.additionalConfigParams.empty()) {
476+
auto substituted =
477+
options::substituteTemplates(cmdLineOpts.additionalConfigParams);
478+
std::vector<folly::StringPiece> pairs;
479+
folly::split(',', substituted, pairs);
480+
for (const auto& pair : pairs) {
481+
if (pair.empty()) {
482+
continue;
483+
}
484+
std::string key;
485+
std::string value;
486+
checkLogic(
487+
folly::split(':', pair, key, value),
488+
"Invalid additional-config-params pair: '{}'. Expected name:value.",
489+
pair);
490+
checkLogic(
491+
!key.empty(),
492+
"Empty key in additional-config-params pair: '{}'.",
493+
pair);
494+
libmcrouterOptions.config_params[key] = std::move(value);
495+
}
496+
}
497+
462498
if (standaloneOptions.core_multiplier > 0) {
463499
auto c = folly::available_concurrency();
464500
if (!standaloneOptions.core_multiplier_threshold ||

third-party/mcrouter/src/mcrouter/StandaloneUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ struct CmdLineOptions {
7979

8080
// the service name we want to override
8181
std::string serviceName;
82+
83+
// additional config params to merge into config_params after resolution.
84+
// Same format as --config-params: "name1:value1,name2:value2"
85+
std::string additionalConfigParams;
8286
};
8387

8488
/**

0 commit comments

Comments
 (0)