Skip to content
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

Introduce a TQL2-only mode #4840

Merged
merged 9 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/tenzir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ jobs:
with:
ssh-private-key: ${{ secrets.TENZIR_PLUGINS_DEPLOY_KEY }}
- name: Require contrib/tenzir-plugins to be downstream of current `main`
if: github.event_name == 'pull_request' && github.base_ref == 'refs/heads/main'
run: |
git submodule update --init contrib/tenzir-plugins
git -C contrib/tenzir-plugins fetch origin main
Expand All @@ -358,15 +357,13 @@ jobs:
$(git -C contrib/tenzir-plugins rev-parse HEAD) \
$(git -C contrib/tenzir-plugins rev-parse origin/main)
- name: Generate a token
if: github.event_name == 'pull_request' && github.base_ref == 'refs/heads/main'
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.TENZIR_AUTOBUMPER_APP_ID }}
private-key: ${{ secrets.TENZIR_AUTOBUMPER_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Require an open PR for a submodule bump
if: github.event_name == 'pull_request' && github.base_ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
Expand Down
6 changes: 6 additions & 0 deletions changelog/next/features/4840--tql2-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Start your Tenzir Node with `tenzir-node --tql2` or set the `TENZIR_TQL2=true`
environment variable to enable TQL2-only mode for your node. In this mode, all
pipelines will run as TQL2, with the old TQL1 pipelines only being available
through the `legacy` operator. In Q1 2025, this option will be enabled by
default, and later in 2025 the `legacy` operator and TQL1 support will be
removed entirely.
2 changes: 1 addition & 1 deletion contrib/tenzir-plugins
3 changes: 1 addition & 2 deletions libtenzir/builtins/commands/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ auto exec_command(const invocation& inv, caf::actor_system& sys) -> bool {
cfg.implicit_events_source
= caf::get_or(inv.options, "tenzir.exec.implicit-events-source",
cfg.implicit_events_source);
cfg.tql2 = caf::get_or(inv.options, "tenzir.exec.tql2", cfg.tql2);
cfg.tql2 = caf::get_or(inv.options, "tenzir.tql2", cfg.tql2);
cfg.strict = caf::get_or(inv.options, "tenzir.exec.strict", cfg.strict);
auto filename = std::string{};
auto content = std::string{};
Expand Down Expand Up @@ -157,7 +157,6 @@ class plugin final : public virtual command_plugin {
.add<std::string>("implicit-events-source",
"implicit source for pipelines starting with events "
"(default: 'from stdin read json'")
.add<bool>("tql2", "use TQL version 2 (experimental)")
.add<bool>("strict",
"return a non-zero exit code if any warnings occured"));
auto factory = command::factory{
Expand Down
4 changes: 2 additions & 2 deletions libtenzir/builtins/connectors/email.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class plugin final : public virtual saver_plugin<saver> {

class save_plugin final
: public virtual operator_plugin2<saver_adapter<saver>> {
auto
make(invocation inv, session ctx) const -> failure_or<operator_ptr> override {
auto make(invocation inv, session ctx) const
-> failure_or<operator_ptr> override {
auto args = saver_args{};
auto endpoint = std::optional<std::string>{default_smtp_server};
auto to = located<std::string>{};
Expand Down
28 changes: 14 additions & 14 deletions libtenzir/builtins/functions/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class time_ final : public function_plugin {
return "tql2.time";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto expr = ast::expression{};
TRY(argument_parser2::function("time")
.positional("x", expr, "string")
Expand Down Expand Up @@ -83,8 +83,8 @@ class since_epoch final : public function_plugin {
return "since_epoch";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto expr = ast::expression{};
TRY(argument_parser2::function(name())
.positional("x", expr, "time")
Expand Down Expand Up @@ -179,8 +179,8 @@ class year_month_day final : public function_plugin {
return std::string{to_string(ymd_subtype_)};
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto expr = ast::expression{};
TRY(argument_parser2::function(name())
.positional("x", expr, "time")
Expand Down Expand Up @@ -243,8 +243,8 @@ class as_secs final : public function_plugin {
return "as_secs";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto expr = ast::expression{};
TRY(argument_parser2::function(name())
.positional("x", expr, "duration")
Expand Down Expand Up @@ -293,8 +293,8 @@ class now final : public function_plugin {
return "tql2.now";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
TRY(argument_parser2::function("now").parse(inv, ctx));
return function_use::make([](evaluator eval, session ctx) -> series {
TENZIR_UNUSED(ctx);
Expand All @@ -314,8 +314,8 @@ class format_time : public virtual function_plugin {
return "tql2.format_time";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto subject_expr = ast::expression{};
auto format = located<std::string>{};
auto locale = std::optional<located<std::string>>{};
Expand Down Expand Up @@ -367,8 +367,8 @@ class parse_time : public virtual function_plugin {
return "tql2.parse_time";
}

auto make_function(invocation inv,
session ctx) const -> failure_or<function_ptr> override {
auto make_function(invocation inv, session ctx) const
-> failure_or<function_ptr> override {
auto subject_expr = ast::expression{};
auto format = located<std::string>{};
auto locale = std::optional<located<std::string>>{};
Expand Down
6 changes: 4 additions & 2 deletions libtenzir/builtins/operators/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class version_operator final : public crtp_operator<version_operator> {
public:
version_operator() = default;

auto operator()(operator_control_plane&) const -> generator<table_slice> {
auto operator()(operator_control_plane& ctrl) const
-> generator<table_slice> {
auto builder = series_builder{type{
"tenzir.version",
record_type{
Expand Down Expand Up @@ -75,7 +76,8 @@ class version_operator final : public crtp_operator<version_operator> {
event.field("minor", tenzir::version::minor);
event.field("patch", tenzir::version::patch);
auto features = event.field("features").list();
for (const auto& feature : tenzir_features()) {
for (const auto& feature :
tenzir_features(check(to<record>(content(ctrl.self().config()))))) {
features.data(feature);
}
auto build = event.field("build").record();
Expand Down
13 changes: 9 additions & 4 deletions libtenzir/include/tenzir/connect_to_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ auto get_retry_delay(const caf::settings& settings)
auto get_deadline(caf::timespan timeout)
-> std::optional<std::chrono::steady_clock::time_point>;

[[nodiscard]] auto check_version(const record& remote_version) -> bool;
[[nodiscard]] auto
check_version(const record& remote_version, const record& cfg) -> bool;

} // namespace details

Expand All @@ -43,8 +44,9 @@ void connect_to_node(caf::typed_event_based_actor<Sigs...>* self,
// Fetch values from config.
const auto& opts = content(self->system().config());
auto node_endpoint = details::get_node_endpoint(opts);
if (!node_endpoint)
if (!node_endpoint) {
return callback(std::move(node_endpoint.error()));
}
auto timeout = node_connection_timeout(opts);
auto connector
= self->spawn(tenzir::connector, details::get_retry_delay(opts),
Expand All @@ -59,9 +61,12 @@ void connect_to_node(caf::typed_event_based_actor<Sigs...>* self,
(void)connector;
self->request(node, timeout, atom::get_v, atom::version_v)
.then(
[callback, node = std::move(node)](record& remote_version) mutable {
[self, callback,
node = std::move(node)](record& remote_version) mutable {
// TODO: Refactor this (also in .cpp).
(void)details::check_version(remote_version);
(void)details::check_version(
remote_version,
check(to<record>(content(self->system().config()))));
callback(std::move(node));
},
[=](caf::error& error) {
Expand Down
4 changes: 2 additions & 2 deletions libtenzir/include/tenzir/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
namespace tenzir {

/// Puts the version information into a record.
record retrieve_versions();
auto retrieve_versions(const record& cfg) -> record;

/// Returns a list of features supported by this build of the node.
std::vector<std::string> tenzir_features();
auto tenzir_features(const record& cfg) -> std::vector<std::string>;

} // namespace tenzir
10 changes: 7 additions & 3 deletions libtenzir/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void add_root_opts(command& cmd) {
"forbid unsafe location overrides for pipelines with the "
"'local' and 'remote' keywords, e.g., remotely reading from "
"a file");
cmd.options.add<bool>("?tenzir", "tql2", "use TQL2 by default");
cmd.options.add<std::string>("?tenzir", "console-verbosity",
"output verbosity level on the "
"console");
Expand Down Expand Up @@ -199,8 +200,9 @@ make_application(std::string_view path) {
// Add additional commands from plugins.
for (const auto* plugin : plugins::get<command_plugin>()) {
auto [cmd, cmd_factory] = plugin->make_command();
if (!cmd || cmd_factory.empty())
if (!cmd || cmd_factory.empty()) {
continue;
}
root->add_subcommand(std::move(cmd));
root_factory.insert(std::make_move_iterator(cmd_factory.begin()),
std::make_move_iterator(cmd_factory.end()));
Expand All @@ -213,9 +215,10 @@ make_application(std::string_view path) {

void render_error(const command& root, const caf::error& err,
std::ostream& os) {
if (!err || err == ec::silent)
if (!err || err == ec::silent) {
// The user most likely killed the process via CTRL+C, print nothing.
return;
}
const auto pretty_diagnostics = true;
os << render(err, pretty_diagnostics) << '\n';
if (err.category() == caf::type_id_v<tenzir::ec>) {
Expand All @@ -229,8 +232,9 @@ void render_error(const command& root, const caf::error& err,
auto ctx = err.context();
if (ctx.match_element<std::string>(1)) {
auto name = ctx.get_as<std::string>(1);
if (auto cmd = resolve(root, name))
if (auto cmd = resolve(root, name)) {
helptext(*cmd, os);
}
} else {
TENZIR_ASSERT(
!"User visible error contexts must consist of strings!");
Expand Down
Loading
Loading