1313import org .elasticsearch .action .admin .indices .sampling .SamplingMetadata ;
1414import org .elasticsearch .action .index .IndexRequest ;
1515import org .elasticsearch .cluster .ClusterChangedEvent ;
16- import org .elasticsearch .cluster .ClusterState ;
1716import org .elasticsearch .cluster .ClusterStateListener ;
18- import org .elasticsearch .cluster .ClusterStateUpdateTask ;
1917import org .elasticsearch .cluster .metadata .ProjectId ;
2018import org .elasticsearch .cluster .metadata .ProjectMetadata ;
2119import org .elasticsearch .cluster .project .ProjectResolver ;
2220import org .elasticsearch .cluster .service .ClusterService ;
23- import org .elasticsearch .common .Priority ;
2421import org .elasticsearch .common .bytes .BytesReference ;
2522import org .elasticsearch .common .io .stream .StreamInput ;
2623import org .elasticsearch .common .io .stream .StreamOutput ;
4845import java .util .Map ;
4946import java .util .Objects ;
5047import java .util .concurrent .ConcurrentHashMap ;
51- import java .util .concurrent .atomic .AtomicBoolean ;
5248import java .util .concurrent .atomic .AtomicInteger ;
5349import java .util .concurrent .atomic .LongAdder ;
5450import java .util .function .LongSupplier ;
@@ -62,7 +58,6 @@ public class SamplingService implements ClusterStateListener {
6258 private final ProjectResolver projectResolver ;
6359 private final LongSupplier relativeMillisTimeSupplier ;
6460 private final LongSupplier statsTimeSupplier = System ::nanoTime ;
65- private final AtomicBoolean firstCall = new AtomicBoolean (true );
6661 /*
6762 * This Map contains the samples that exist on this node. They are not persisted to disk. They are stored as SoftReferences so that
6863 * sampling does not contribute to a node running out of memory. The idea is that access to samples is desirable, but not critical. We
@@ -245,28 +240,6 @@ public SampleStats getLocalSampleStats(ProjectId projectId, String index) {
245240
246241 public boolean atLeastOneSampleConfigured () {
247242 if (RANDOM_SAMPLING_FEATURE_FLAG ) {
248- if (firstCall .get ()) {
249- clusterService .submitUnbatchedStateUpdateTask ("blocking-task" , new ClusterStateUpdateTask (Priority .IMMEDIATE ) {
250- @ Override
251- public ClusterState execute (ClusterState currentState ) throws Exception {
252- ProjectMetadata .Builder projectMetadataBuilder = ProjectMetadata .builder (
253- currentState .metadata ().getProject (ProjectId .DEFAULT )
254- );
255- SamplingMetadata samplingMetadata = new SamplingMetadata (
256- Map .of ("test" , new SamplingConfiguration (1.0d , 50 , null , null , null ))
257- );
258- projectMetadataBuilder .putCustom (SamplingMetadata .TYPE , samplingMetadata );
259- ClusterState newState = new ClusterState .Builder (currentState ).putProjectMetadata (projectMetadataBuilder ).build ();
260- return newState ;
261- }
262-
263- @ Override
264- public void onFailure (Exception e ) {
265- assert false : e .getMessage ();
266- }
267- });
268- firstCall .set (false );
269- }
270243 SamplingMetadata samplingMetadata = clusterService .state ()
271244 .projectState (projectResolver .getProjectId ())
272245 .metadata ()
0 commit comments