Skip to content

Commit

Permalink
features: revoke_license also revoke trial license
Browse files Browse the repository at this point in the history
Have `revoke_license` revoke the builtin trial license as well for more
convenient testing.
  • Loading branch information
pgellert committed Oct 28, 2024
1 parent cad7c7d commit 7702ed1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/v/features/feature_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <chrono>
#include <memory>
#include <optional>

// The feature table is closely related to cluster and uses many types from it
using namespace cluster;
Expand Down Expand Up @@ -717,6 +718,7 @@ void feature_table::set_builtin_trial_license(
model::timestamp cluster_creation_timestamp) {
_builtin_trial_license = make_builtin_trial_license(
model::to_time_point(cluster_creation_timestamp));
_builtin_trial_license_initialized = true;

if (ss::this_shard_id() == 0) {
vlog(
Expand All @@ -727,7 +729,10 @@ void feature_table::set_builtin_trial_license(
}
}

void feature_table::revoke_license() { _license = std::nullopt; }
void feature_table::revoke_license() {
_license = std::nullopt;
_builtin_trial_license = std::nullopt;
}

const std::optional<security::license>& feature_table::get_license() const {
return _license ? _license : _builtin_trial_license;
Expand All @@ -745,9 +750,9 @@ bool feature_table::should_sanction() const {
return _builtin_trial_license->is_expired();
}

// We are yet to initialize _builtin_trial_license on cluster creation, be
// permissive in the meantime
return false;
// While we are yet to initialize _builtin_trial_license on cluster
// creation, be permissive
return _builtin_trial_license_initialized;
}

void feature_table::testing_activate_all() {
Expand Down
4 changes: 4 additions & 0 deletions src/v/features/feature_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ class feature_table {
// Built in trial license to fall back to if there is no license set
std::optional<security::license> _builtin_trial_license;

// Whether _builtin_trial_license has ever been initialized
// Used for implementing revoking the trial license for testing
bool _builtin_trial_license_initialized{false};

model::offset _applied_offset{};

// feature_manager is a friend so that they can initialize
Expand Down
4 changes: 4 additions & 0 deletions src/v/features/tests/feature_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ FIXTURE_TEST(feature_table_trial_license_test, feature_table_fixture) {
BOOST_CHECK_EQUAL(ft.get_license().has_value(), true);
BOOST_CHECK_EQUAL(ft.get_license()->is_expired(), false);
BOOST_CHECK_EQUAL(ft.should_sanction(), false);

ft.revoke_license();
BOOST_CHECK_EQUAL(ft.get_license().has_value(), false);
BOOST_CHECK_EQUAL(ft.should_sanction(), true);
}

SEASTAR_THREAD_TEST_CASE(feature_table_probe_expiry_metric_test) {
Expand Down

0 comments on commit 7702ed1

Please sign in to comment.