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

Hide remote reindex migration behind feature flag #20636

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-20636.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "f"
message = "Hide remote reindex migration behind a feature flag"

pulls = ["20636"]
issues = ["graylog-plugin-enterprise#8811"]
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ public interface MigrationActions {
void stopDatanodes();

void finishRemoteReindexMigration();

boolean isRemoteReindexMigrationEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.graylog2.cluster.nodes.NodeService;
import org.graylog2.datanode.DataNodeCommandService;
import org.graylog2.datanode.DatanodeStartType;
import org.graylog2.featureflag.FeatureFlags;
import org.graylog2.indexer.datanode.RemoteReindexRequest;
import org.graylog2.indexer.datanode.RemoteReindexingMigrationAdapter;
import org.graylog2.notifications.Notification;
Expand Down Expand Up @@ -59,6 +60,7 @@

public class MigrationActionsImpl implements MigrationActions {
private static final Logger LOG = LoggerFactory.getLogger(MigrationActionsImpl.class);
private static final String FEATURE_FLAG_REMOTE_REINDEX_MIGRATION = "remote_reindex_migration";

private final ClusterConfigService clusterConfigService;
private final ClusterProcessingControlFactory clusterProcessingControlFactory;
Expand All @@ -78,6 +80,8 @@ public class MigrationActionsImpl implements MigrationActions {

private final NotificationService notificationService;

private final FeatureFlags featureFlags;

@Inject
public MigrationActionsImpl(@Assisted MigrationStateMachineContext stateMachineContext,
final ClusterConfigService clusterConfigService, NodeService<DataNodeDto> nodeService,
Expand All @@ -89,7 +93,7 @@ public MigrationActionsImpl(@Assisted MigrationStateMachineContext stateMachineC
final DatanodeRestApiProxy datanodeProxy,
ElasticsearchVersionProvider searchVersionProvider,
@Named("elasticsearch_hosts") List<URI> elasticsearchHosts,
NotificationService notificationService) {
NotificationService notificationService, FeatureFlags featureFlags) {
this.stateMachineContext = stateMachineContext;
this.clusterConfigService = clusterConfigService;
this.nodeService = nodeService;
Expand All @@ -103,6 +107,7 @@ public MigrationActionsImpl(@Assisted MigrationStateMachineContext stateMachineC
this.searchVersionProvider = searchVersionProvider;
this.elasticsearchHosts = elasticsearchHosts;
this.notificationService = notificationService;
this.featureFlags = featureFlags;
}


Expand Down Expand Up @@ -336,4 +341,9 @@ public void stopDatanodes() {
public void finishRemoteReindexMigration() {
notificationService.destroyAllByType(Notification.Type.REMOTE_REINDEX_FINISHED);
}

@Override
public boolean isRemoteReindexMigrationEnabled() {
return featureFlags.isOn(FEATURE_FLAG_REMOTE_REINDEX_MIGRATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,45 @@ private static StateMachineConfig<MigrationState, MigrationStep> configureStates
.permit(MigrationStep.SELECT_MIGRATION, MigrationState.MIGRATION_WELCOME_PAGE, () -> LOG.info("Migration selected in menu, show welcome page"));

config.configure(MigrationState.MIGRATION_WELCOME_PAGE)
.permitIf(MigrationStep.SHOW_CA_CREATION, MigrationState.CA_CREATION_PAGE, migrationActions::caDoesNotExist)
.permitIf(MigrationStep.SHOW_RENEWAL_POLICY_CREATION, MigrationState.RENEWAL_POLICY_CREATION_PAGE, () -> !migrationActions.caDoesNotExist() && migrationActions.renewalPolicyDoesNotExist())
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion())
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion());
.permitIf(MigrationStep.SHOW_CA_CREATION, MigrationState.CA_CREATION_PAGE, () ->
(migrationActions.isRemoteReindexMigrationEnabled() || migrationActions.isCompatibleInPlaceMigrationVersion()) && migrationActions.caDoesNotExist()
)
.permitIf(MigrationStep.SHOW_RENEWAL_POLICY_CREATION, MigrationState.RENEWAL_POLICY_CREATION_PAGE, () -> {
if (!migrationActions.isRemoteReindexMigrationEnabled() && !migrationActions.isCompatibleInPlaceMigrationVersion()) {
return false;
}
return !migrationActions.caDoesNotExist() && migrationActions.renewalPolicyDoesNotExist();
})
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> {
if (!migrationActions.isRemoteReindexMigrationEnabled()) {
return false;
}
return migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion();
})
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> {
if (!migrationActions.isRemoteReindexMigrationEnabled() && !migrationActions.isCompatibleInPlaceMigrationVersion()) {
return false;
}
return migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion();
})
.permitIf(MigrationStep.SELECT_ROLLING_UPGRADE_MIGRATION, MigrationState.ROLLING_UPGRADE_MIGRATION_WELCOME_PAGE, () ->
!migrationActions.isRemoteReindexMigrationEnabled() && migrationActions.caAndRenewalPolicyExist());

config.configure(MigrationState.CA_CREATION_PAGE)
.permitIf(MigrationStep.SHOW_RENEWAL_POLICY_CREATION, MigrationState.RENEWAL_POLICY_CREATION_PAGE, () -> !migrationActions.caDoesNotExist() && migrationActions.renewalPolicyDoesNotExist())
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion())
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion());
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion() && migrationActions.isRemoteReindexMigrationEnabled())
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion())
.permitIf(MigrationStep.SELECT_ROLLING_UPGRADE_MIGRATION, MigrationState.ROLLING_UPGRADE_MIGRATION_WELCOME_PAGE, () -> !migrationActions.isRemoteReindexMigrationEnabled() && migrationActions.caAndRenewalPolicyExist());

config.configure(MigrationState.RENEWAL_POLICY_CREATION_PAGE)
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion())
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion());
.permitIf(MigrationStep.SHOW_MIGRATION_SELECTION, MigrationState.MIGRATION_SELECTION_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && migrationActions.isCompatibleInPlaceMigrationVersion() && migrationActions.isRemoteReindexMigrationEnabled())
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, () -> migrationActions.caAndRenewalPolicyExist() && !migrationActions.isCompatibleInPlaceMigrationVersion())
.permitIf(MigrationStep.SELECT_ROLLING_UPGRADE_MIGRATION, MigrationState.ROLLING_UPGRADE_MIGRATION_WELCOME_PAGE, () -> !migrationActions.isRemoteReindexMigrationEnabled() && migrationActions.caAndRenewalPolicyExist());

// Major decision - remote reindexing or rolling upgrade(in-place)?
config.configure(MigrationState.MIGRATION_SELECTION_PAGE)
.permitIf(MigrationStep.SELECT_ROLLING_UPGRADE_MIGRATION, MigrationState.ROLLING_UPGRADE_MIGRATION_WELCOME_PAGE, migrationActions::isCompatibleInPlaceMigrationVersion)
.permit(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE);
.permitIf(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION, MigrationState.REMOTE_REINDEX_WELCOME_PAGE, migrationActions::isRemoteReindexMigrationEnabled);

// remote reindexing branch of the migration
config.configure(MigrationState.REMOTE_REINDEX_WELCOME_PAGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ configurable_value_units=on

# New Report Creation UI
new_report_creation=on

# Enable remote-reindex migration to the datanode
remote_reindex_migration=off
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void stopDatanodes() {
public void finishRemoteReindexMigration() {
}

@Override
public boolean isRemoteReindexMigrationEnabled() {
return true;
}

@Override
public void runDirectoryCompatibilityCheck() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void testNewState() {

@Test
public void testWelcomePage() {
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
StateMachine<MigrationState, MigrationStep> stateMachine = getStateMachine(MigrationState.MIGRATION_WELCOME_PAGE);
assertThat(stateMachine.getState()).isEqualTo(MigrationState.MIGRATION_WELCOME_PAGE);
assertThat(stateMachine.getPermittedTriggers()).isEmpty();
Expand All @@ -65,6 +66,7 @@ public void testWelcomePage() {

@Test
public void testCaCreationPage() {
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.directoryCompatibilityCheckOk()).thenReturn(true);
StateMachine<MigrationState, MigrationStep> stateMachine = getStateMachine(MigrationState.MIGRATION_WELCOME_PAGE);
when(migrationActions.caDoesNotExist()).thenReturn(true);
Expand All @@ -79,8 +81,9 @@ public void testCaCreationPage() {
assertThat(stateMachine.getPermittedTriggers()).containsOnly(MigrationStep.SHOW_RENEWAL_POLICY_CREATION);
verify(migrationActions, times(1)).caDoesNotExist();
verify(migrationActions, times(1)).renewalPolicyDoesNotExist();
verify(migrationActions, times(2)).caAndRenewalPolicyExist();
verify(migrationActions, times(3)).caAndRenewalPolicyExist();
reset(migrationActions);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.caDoesNotExist()).thenReturn(false);
when(migrationActions.renewalPolicyDoesNotExist()).thenReturn(false);
when(migrationActions.caAndRenewalPolicyExist()).thenReturn(true);
Expand All @@ -90,6 +93,7 @@ public void testCaCreationPage() {
verify(migrationActions, times(1)).renewalPolicyDoesNotExist();
verify(migrationActions, times(2)).caAndRenewalPolicyExist();
reset(migrationActions);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.caDoesNotExist()).thenReturn(false);
when(migrationActions.renewalPolicyDoesNotExist()).thenReturn(false);
when(migrationActions.caAndRenewalPolicyExist()).thenReturn(true);
Expand All @@ -104,6 +108,7 @@ public void testCaCreationPage() {

@Test
public void testRenewalPolicyCreationPage() {
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.renewalPolicyDoesNotExist()).thenReturn(true);
StateMachine<MigrationState, MigrationStep> stateMachine = getStateMachine(MigrationState.CA_CREATION_PAGE);
stateMachine.fire(MigrationStep.SHOW_RENEWAL_POLICY_CREATION);
Expand All @@ -112,11 +117,13 @@ public void testRenewalPolicyCreationPage() {
assertThat(stateMachine.getPermittedTriggers()).isEmpty();
verify(migrationActions, times(2)).caAndRenewalPolicyExist();
reset(migrationActions);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.caAndRenewalPolicyExist()).thenReturn(true);
assertThat(stateMachine.getPermittedTriggers()).containsOnly(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION);
verify(migrationActions, times(2)).caAndRenewalPolicyExist();
verify(migrationActions, times(2)).isCompatibleInPlaceMigrationVersion();
reset(migrationActions);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.caAndRenewalPolicyExist()).thenReturn(true);
when(migrationActions.isCompatibleInPlaceMigrationVersion()).thenReturn(true);
assertThat(stateMachine.getPermittedTriggers()).containsOnly(MigrationStep.SHOW_MIGRATION_SELECTION);
Expand All @@ -127,16 +134,19 @@ public void testRenewalPolicyCreationPage() {

@Test
public void testMigrationSelectionPage() {
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
when(migrationActions.caAndRenewalPolicyExist()).thenReturn(true);
when(migrationActions.isCompatibleInPlaceMigrationVersion()).thenReturn(true);
StateMachine<MigrationState, MigrationStep> stateMachine = getStateMachine(MigrationState.CA_CREATION_PAGE);
stateMachine.fire(MigrationStep.SHOW_MIGRATION_SELECTION);
verify(migrationActions).caAndRenewalPolicyExist();
assertThat(stateMachine.getState()).isEqualTo(MigrationState.MIGRATION_SELECTION_PAGE);
reset(migrationActions);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
assertThat(stateMachine.getPermittedTriggers()).containsOnly(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION);
reset(migrationActions);
when(migrationActions.isCompatibleInPlaceMigrationVersion()).thenReturn(true);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
assertThat(stateMachine.getPermittedTriggers())
.containsOnly(MigrationStep.SELECT_ROLLING_UPGRADE_MIGRATION, MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION);
verify(migrationActions, times(1)).isCompatibleInPlaceMigrationVersion();
Expand All @@ -147,6 +157,7 @@ public void testMigrationSelectionPage() {
public void testRemoteReindexWelcomePage() {
StateMachine<MigrationState, MigrationStep> stateMachine = getStateMachine(MigrationState.MIGRATION_SELECTION_PAGE);
when(migrationActions.compatibleDatanodesRunning()).thenReturn(true);
when(migrationActions.isRemoteReindexMigrationEnabled()).thenReturn(true);
stateMachine.fire(MigrationStep.SELECT_REMOTE_REINDEX_MIGRATION);
assertThat(stateMachine.getState()).isEqualTo(MigrationState.REMOTE_REINDEX_WELCOME_PAGE);
verify(migrationActions).reindexUpgradeSelected();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import { useQuery } from '@tanstack/react-query';

import { qualifyUrl } from 'util/URLUtils';
import fetch from 'logic/rest/FetchProvider';
import ApiRoutes from 'routing/ApiRoutes';

const fetchClusterName = async () => fetch('GET', qualifyUrl(ApiRoutes.IndexerClusterApiController.info().url));

const useIsElasticsearch = (): boolean => {
const { data } = useQuery(
['cluster-name'],
fetchClusterName,
{
refetchInterval: 5000,
},
);

return data?.distribution === 'Elasticsearch';
};

export default useIsElasticsearch;
Loading
Loading