Skip to content

Commit f6d575d

Browse files
committed
add WORKERD_ENABLE_ALL_AUTOGATES env variable
1 parent 987e1dd commit f6d575d

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/workerd/server/server.c++

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <workerd/io/worker-interface.h>
2626
#include <workerd/io/worker.h>
2727
#include <workerd/server/actor-id-impl.h>
28-
#include <workerd/util/autogate.h>
2928
#include <workerd/util/http-util.h>
3029
#include <workerd/util/mimetype.h>
3130
#include <workerd/util/use-perfetto-categories.h>

src/workerd/server/workerd.c++

+14-2
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ class CliMain final: public SchemaFileImpl::ErrorReporter {
754754
"<const-name>", CLI_METHOD(setConstName));
755755
}
756756

757+
bool shouldEnableAllAutogates() {
758+
return getenv("WORKERD_ENABLE_ALL_AUTOGATES") != nullptr;
759+
}
760+
757761
kj::MainBuilder& addServeOrTestOptions(kj::MainBuilder& builder) {
758762
return builder
759763
.addOptionWithArg({'d', "directory-path"}, CLI_METHOD(overrideDirectory), "<name>=<path>",
@@ -1077,7 +1081,11 @@ class CliMain final: public SchemaFileImpl::ErrorReporter {
10771081
mod.setPythonModule("def test():\n pass");
10781082
config = configBuilder.asReader();
10791083
configOwner = kj::mv(builder);
1080-
util::Autogate::initAutogate(getConfig().getAutogates());
1084+
if (shouldEnableAllAutogates()) {
1085+
util::Autogate::initAllAutogates();
1086+
} else {
1087+
util::Autogate::initAutogate(getConfig().getAutogates());
1088+
}
10811089
}
10821090

10831091
void watch() {
@@ -1160,7 +1168,11 @@ class CliMain final: public SchemaFileImpl::ErrorReporter {
11601168
// We'll fail at getConfig() if there are multiple top level Config objects.
11611169
// The error message says that you have to specify which config to use, but
11621170
// it's not clear that there is any mechanism to do that.
1163-
util::Autogate::initAutogate(getConfig().getAutogates());
1171+
if (shouldEnableAllAutogates()) {
1172+
util::Autogate::initAllAutogates();
1173+
} else {
1174+
util::Autogate::initAutogate(getConfig().getAutogates());
1175+
}
11641176
}
11651177

11661178
void setConstName(kj::StringPtr name) {

src/workerd/util/autogate.c++

+15
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ void Autogate::deinitAutogate() {
6666
globalAutogate = kj::none;
6767
}
6868

69+
void Autogate::initAllAutogates() {
70+
capnp::MallocMessageBuilder message;
71+
auto orphanage = message.getOrphanage();
72+
auto gatesOrphan =
73+
orphanage.newOrphan<capnp::List<capnp::Text>>(static_cast<size_t>(AutogateKey::NumOfKeys));
74+
auto gates = gatesOrphan.get();
75+
76+
for (auto i = AutogateKey(0); i < AutogateKey::NumOfKeys;
77+
i = AutogateKey(static_cast<size_t>(i) + 1)) {
78+
gates.set(static_cast<size_t>(i), kj::str("workerd-autogate-", i));
79+
}
80+
81+
Autogate::initAutogate(gates.asReader());
82+
}
83+
6984
void Autogate::initAutogateNamesForTest(std::initializer_list<kj::StringPtr> gateNames) {
7085
capnp::MallocMessageBuilder message;
7186
auto orphanage = message.getOrphanage();

src/workerd/util/autogate.h

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class Autogate {
4545
// Convenience method for bin-tests to invoke initAutogate() with an appropriate config.
4646
static void initAutogateNamesForTest(std::initializer_list<kj::StringPtr> gateNames);
4747

48+
// Initializes all autogates, enabling all features.
49+
//
50+
// This is used by the --all-autogates flag in the CLI to enable all gates regardless
51+
// of what's specified in the config file. This can be useful during development to test
52+
// features that are behind autogates.
53+
//
54+
// CAUTION: Be aware that enabling all gates may expose you to experimental features
55+
// that aren't ready for production use. Use with care in production environments.
56+
static void initAllAutogates();
57+
4858
// Destroys an initialized global Autogate instance. Used only for testing.
4959
static void deinitAutogate();
5060

0 commit comments

Comments
 (0)