@@ -100,7 +100,7 @@ public SamplingService(
100100 this .updateSamplingConfigurationTaskQueue = clusterService .createTaskQueue (
101101 "update-sampling-configuration" ,
102102 Priority .NORMAL ,
103- new UpdateSamplingConfigurationExecutor (projectResolver , this )
103+ new UpdateSamplingConfigurationExecutor ()
104104 );
105105 }
106106
@@ -293,9 +293,10 @@ public void updateSampleConfiguration(
293293 ActionListener <AcknowledgedResponse > listener
294294 ) {
295295 // Early validation: check if adding a new configuration would exceed the limit
296- boolean maxConfigLimitBreached = checkMaxConfigLimitBreached (projectId , index );
296+ ClusterState clusterState = clusterService .state ();
297+ boolean maxConfigLimitBreached = checkMaxConfigLimitBreached (projectId , index , clusterState );
297298 if (maxConfigLimitBreached ) {
298- Integer maxConfigurations = MAX_CONFIGURATIONS_SETTING .get (clusterService . state () .getMetadata ().settings ());
299+ Integer maxConfigurations = MAX_CONFIGURATIONS_SETTING .get (clusterState .getMetadata ().settings ());
299300 listener .onFailure (
300301 new IllegalStateException (
301302 "Cannot add sampling configuration for index ["
@@ -349,8 +350,7 @@ private static Script getScript(String conditional) throws IOException {
349350
350351 // Checks whether the maximum number of sampling configurations has been reached for the given project.
351352 // If the limit is breached, it notifies the listener with an IllegalStateException and returns true.
352- private boolean checkMaxConfigLimitBreached (ProjectId projectId , String index ) {
353- ClusterState currentState = clusterService .state ();
353+ private static boolean checkMaxConfigLimitBreached (ProjectId projectId , String index , ClusterState currentState ) {
354354 Metadata currentMetadata = currentState .metadata ();
355355 ProjectMetadata projectMetadata = currentMetadata .getProject (projectId );
356356
@@ -789,13 +789,8 @@ static class UpdateSamplingConfigurationTask extends AckedBatchedClusterStateUpd
789789
790790 static class UpdateSamplingConfigurationExecutor extends SimpleBatchedAckListenerTaskExecutor <UpdateSamplingConfigurationTask > {
791791 private static final Logger logger = LogManager .getLogger (UpdateSamplingConfigurationExecutor .class );
792- private final ProjectResolver projectResolver ;
793- private final SamplingService samplingService ;
794792
795- UpdateSamplingConfigurationExecutor (ProjectResolver projectResolver , SamplingService samplingService ) {
796- this .projectResolver = projectResolver ;
797- this .samplingService = samplingService ;
798- }
793+ UpdateSamplingConfigurationExecutor () {}
799794
800795 @ Override
801796 public Tuple <ClusterState , ClusterStateAckListener > executeTask (
@@ -836,9 +831,10 @@ public Tuple<ClusterState, ClusterStateAckListener> executeTask(
836831
837832 Integer maxConfigurations = MAX_CONFIGURATIONS_SETTING .get (metadata .settings ());
838833 // check if adding a new configuration would exceed the limit
839- boolean maxConfigLimitBreached = samplingService . checkMaxConfigLimitBreached (
834+ boolean maxConfigLimitBreached = checkMaxConfigLimitBreached (
840835 updateSamplingConfigurationTask .projectId ,
841- updateSamplingConfigurationTask .indexName
836+ updateSamplingConfigurationTask .indexName ,
837+ clusterState
842838 );
843839 if (maxConfigLimitBreached ) {
844840 throw new IllegalStateException (
0 commit comments