Class SamplingService

All Implemented Interfaces:
Closeable, AutoCloseable, ClusterStateListener, LifecycleComponent, SchedulerEngine.Listener, Releasable

public class SamplingService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener
  • Field Details

    • RANDOM_SAMPLING_FEATURE_FLAG

      public static final boolean RANDOM_SAMPLING_FEATURE_FLAG
    • TTL_POLL_INTERVAL_SETTING

      public static final Setting<TimeValue> TTL_POLL_INTERVAL_SETTING
  • Method Details

    • create

      public static SamplingService create(ScriptService scriptService, ClusterService clusterService, Settings settings)
    • maybeSample

      public void maybeSample(ProjectMetadata projectMetadata, IndexRequest indexRequest)
      Potentially samples the given indexRequest, depending on the existing sampling configuration.
      Parameters:
      projectMetadata - Used to get the sampling configuration
      indexRequest - The raw request to potentially sample
    • maybeSample

      public void maybeSample(ProjectMetadata projectMetadata, IndexRequest indexRequest, IngestDocument ingestDocument)
      Potentially samples the given indexRequest, depending on the existing sampling configuration. The request will be sampled against the sampling configurations of all indices it has been rerouted to (if it has been rerouted).
      Parameters:
      projectMetadata - Used to get the sampling configuration
      indexRequest - The raw request to potentially sample
      ingestDocument - The IngestDocument used for evaluating any conditionals that are part of the sample configuration
    • getSamplingConfiguration

      public SamplingConfiguration getSamplingConfiguration(ProjectMetadata projectMetadata, String indexName)
      Retrieves the sampling configuration for the specified index from the given project metadata.
      Parameters:
      projectMetadata - The project metadata containing sampling information.
      indexName - The name of the index or data stream for which to retrieve the sampling configuration.
      Returns:
      The SamplingConfiguration for the specified index, or null if none exists.
    • getLocalSample

      public List<SamplingService.RawDocument> getLocalSample(ProjectId projectId, String index)
      Gets the sample for the given projectId and index on this node only. The sample is not persistent.
      Parameters:
      projectId - The project that this sample is for
      index - The index that the sample is for
      Returns:
      The raw documents in the sample on this node, or an empty list if there are none
    • getLocalSampleStats

      public SamplingService.SampleStats getLocalSampleStats(ProjectId projectId, String index)
      Gets the sample stats for the given projectId and index on this node only. The stats are not persistent. They are reset when the node restarts for example.
      Parameters:
      projectId - The project that this sample is for
      index - The index that the sample is for
      Returns:
      Current stats on this node for this sample
    • throwIndexNotFoundExceptionIfNotDataStreamOrIndex

      public static void throwIndexNotFoundExceptionIfNotDataStreamOrIndex(IndexNameExpressionResolver indexNameExpressionResolver, ProjectResolver projectResolver, ClusterState state, IndicesRequest request)
    • atLeastOneSampleConfigured

      public boolean atLeastOneSampleConfigured(ProjectMetadata projectMetadata)
    • updateSampleConfiguration

      public void updateSampleConfiguration(ProjectId projectId, String index, SamplingConfiguration samplingConfiguration, TimeValue masterNodeTimeout, TimeValue ackTimeout, ActionListener<AcknowledgedResponse> listener)
    • deleteSampleConfiguration

      public void deleteSampleConfiguration(ProjectId projectId, String index, TimeValue masterNodeTimeout, TimeValue ackTimeout, ActionListener<AcknowledgedResponse> listener)
    • clusterChanged

      public void clusterChanged(ClusterChangedEvent event)
      Description copied from interface: ClusterStateListener
      Called when cluster state changes.

      Cluster states are applied one-by-one which means they can be a performance bottleneck. Implementations of this method should therefore be fast, so please consider forking work into the background rather than doing everything inline.

      Specified by:
      clusterChanged in interface ClusterStateListener
    • triggered

      public void triggered(SchedulerEngine.Event event)
      Specified by:
      triggered in interface SchedulerEngine.Listener
    • doStart

      protected void doStart()
      Description copied from class: AbstractLifecycleComponent
      Start this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.

      If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.

      Specified by:
      doStart in class AbstractLifecycleComponent
    • doStop

      protected void doStop()
      Description copied from class: AbstractLifecycleComponent
      Stop this component. Typically that means doing the reverse of whatever AbstractLifecycleComponent.doStart() does.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, after calling AbstractLifecycleComponent.doStart(), although it will not be called at all if this component did not successfully start.

      Specified by:
      doStop in class AbstractLifecycleComponent
    • doClose

      protected void doClose() throws IOException
      Description copied from class: AbstractLifecycleComponent
      Close this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.

      Specified by:
      doClose in class AbstractLifecycleComponent
      Throws:
      IOException