-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add Sampling Configuration Actions #135651
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
Draft
seanzatzdev
wants to merge
13
commits into
elastic:main
Choose a base branch
from
seanzatzdev:sampling_config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f52bef
Add PutSamplingConfigurationAction to wrap requests
seanzatzdev 76e740f
Add PutSamplingConfigurationAction to wrap requests
seanzatzdev 404d6aa
Add GetSamplingConfigurationAction
seanzatzdev 02dd784
Add GetSamplingConfigurationAction
seanzatzdev 12ba96c
Update server/src/main/java/org/elasticsearch/action/admin/indices/sa…
seanzatzdev aaf1c89
nit fixes
seanzatzdev 490dd22
Add additional get actions
seanzatzdev 868e835
Add DeleteSamplingConfigurationAction
seanzatzdev dbfff2f
Merge branch 'main' into sampling_config
seanzatzdev cb39ad1
add put sampling config rest endpoint
seanzatzdev 2b166ca
Merge branch 'main' into sampling_config
seanzatzdev 19deb88
fix typo
seanzatzdev fa38fbf
[CI] Auto commit changes from spotless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
.../java/org/elasticsearch/action/admin/indices/sampling/GetSamplingConfigurationAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.sampling; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Action type for retrieving sampling configurations. | ||
* <p> | ||
* This action allows clients to get the current sampling configurations | ||
* that have been set on one or more indices. The response contains a mapping | ||
* from index names to their corresponding {@link SamplingConfiguration} objects. | ||
* </p> | ||
* | ||
* @see SamplingConfiguration | ||
* @see PutSamplingConfigurationAction | ||
*/ | ||
public class GetSamplingConfigurationAction extends ActionType<GetSamplingConfigurationAction.Response> { | ||
|
||
/** | ||
* Singleton instance of the GetSamplingConfigurationAction. | ||
* This provides a shared reference to the action type throughout the application. | ||
*/ | ||
public static final GetSamplingConfigurationAction INSTANCE = new GetSamplingConfigurationAction(); | ||
|
||
/** | ||
* The name identifier for this action type used in the transport layer. | ||
* Format follows the pattern: "indices:admin/sampling/config/get" | ||
*/ | ||
public static final String NAME = "indices:admin/sampling/config/get"; | ||
|
||
private GetSamplingConfigurationAction() { | ||
super(NAME); | ||
} | ||
|
||
/** | ||
* Response object containing a map from index names to their sampling configurations. | ||
* <p> | ||
* This response encapsulates a map where keys are index names and values are | ||
* their corresponding sampling configurations. If an index has no sampling | ||
* configuration, it will not be present in the map. | ||
* </p> | ||
*/ | ||
public static class Response extends ActionResponse { | ||
private final Map<String, SamplingConfiguration> indexToSamplingConfigMap; | ||
|
||
/** | ||
* Constructs a new Response with the given index-to-configuration mapping. | ||
* | ||
* @param indexToSamplingConfigMap a map from index names to their sampling configurations. | ||
*/ | ||
public Response(Map<String, SamplingConfiguration> indexToSamplingConfigMap) { | ||
this.indexToSamplingConfigMap = indexToSamplingConfigMap; | ||
} | ||
|
||
/** | ||
* Constructs a new Response by deserializing from a StreamInput. | ||
* <p> | ||
* This constructor is used during deserialization when the response is received | ||
* over the transport layer. It reads the map of index names to sampling configurations | ||
* from the input stream. | ||
* </p> | ||
* | ||
* @param in the stream input to read from | ||
* @throws IOException if an I/O error occurs during deserialization | ||
*/ | ||
public Response(StreamInput in) throws IOException { | ||
this.indexToSamplingConfigMap = in.readMap(StreamInput::readString, SamplingConfiguration::new); | ||
} | ||
|
||
/** | ||
* Returns the mapping of index names to their sampling configurations. | ||
* <p> | ||
* The returned map contains all indices that have sampling configurations. | ||
* Indices without sampling configurations will not be present in this map. | ||
* </p> | ||
* | ||
* @return the index-to-sampling-configuration map | ||
*/ | ||
public Map<String, SamplingConfiguration> getIndexToSamplingConfigMap() { | ||
return indexToSamplingConfigMap; | ||
} | ||
|
||
/** | ||
* Serializes this response to a StreamOutput. | ||
* <p> | ||
* This method writes the index-to-configuration map to the output stream | ||
* so it can be transmitted over the transport layer. Each index name is | ||
* written as a string, followed by its corresponding sampling configuration. | ||
* </p> | ||
* | ||
* @param out the stream output to write to | ||
* @throws IOException if an I/O error occurs during serialization | ||
*/ | ||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeMap(indexToSamplingConfigMap, StreamOutput::writeString, (stream, config) -> config.writeTo(stream)); | ||
} | ||
|
||
/** | ||
* Determines whether this response is equal to another object. | ||
* <p> | ||
* Two Response objects are considered equal if they contain the same | ||
* index-to-sampling-configuration mappings. | ||
* </p> | ||
* | ||
* @param o the object to compare with this response | ||
* @return true if the objects are equal, false otherwise | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Response that = (Response) o; | ||
return Objects.equals(indexToSamplingConfigMap, that.indexToSamplingConfigMap); | ||
} | ||
|
||
/** | ||
* Returns the hash code for this response. | ||
* <p> | ||
* The hash code is computed based on the index-to-sampling-configuration map, | ||
* ensuring that equal responses have the same hash code. | ||
* </p> | ||
* | ||
* @return the hash code value for this response | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(indexToSamplingConfigMap); | ||
} | ||
} | ||
} |
224 changes: 224 additions & 0 deletions
224
.../java/org/elasticsearch/action/admin/indices/sampling/PutSamplingConfigurationAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.sampling; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.IndicesRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.core.Nullable; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.tasks.CancellableTask; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.tasks.TaskId; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Action for configuring sampling settings on indices. | ||
* <p> | ||
* This action allows administrators to configure sampling parameters for one or more indices, | ||
* including sampling rate, maximum number of samples, maximum size constraints, time-to-live | ||
* settings, and conditional sampling criteria. | ||
* </p> | ||
* <p> | ||
* The action name is "indices:admin/sampling/config/update" and it returns an {@link AcknowledgedResponse} | ||
* to indicate whether the configuration was successfully applied. | ||
* </p> | ||
*/ | ||
public class PutSamplingConfigurationAction extends ActionType<AcknowledgedResponse> { | ||
/** | ||
* The action name used to identify this action in the transport layer. | ||
*/ | ||
public static final String NAME = "indices:admin/sampling/config/update"; | ||
|
||
/** | ||
* Singleton instance of this action type. | ||
*/ | ||
public static final PutSamplingConfigurationAction INSTANCE = new PutSamplingConfigurationAction(); | ||
|
||
/** | ||
* Constructs a new PutSamplingConfigurationAction with the predefined action name. | ||
*/ | ||
public PutSamplingConfigurationAction() { | ||
super(NAME); | ||
} | ||
|
||
/** | ||
* Request class for configuring sampling settings on indices. | ||
* <p> | ||
* This request encapsulates all the parameters needed to configure sampling on one or more indices, | ||
* including the sampling configuration itself and the target indices. It implements | ||
* {@link IndicesRequest.Replaceable} to support index name resolution and expansion. | ||
* </p> | ||
*/ | ||
public static class Request extends AcknowledgedRequest<PutSamplingConfigurationAction.Request> implements IndicesRequest.Replaceable { | ||
private final SamplingConfiguration samplingConfiguration; | ||
private String[] indices = Strings.EMPTY_ARRAY; | ||
|
||
/** | ||
* Constructs a new request with the specified sampling configuration parameters. | ||
* | ||
* @param rate the sampling rate as a double between 0.0 and 1.0 | ||
* @param maxSamples the maximum number of samples to collect, or null for the default | ||
* @param maxSize the maximum size of samples to collect, or null for the default | ||
* @param timeToLive the time-to-live for sampling data, or null for the default | ||
* @param condition the conditional expression for sampling, or null for unconditional sampling | ||
* @param masterNodeTimeout the timeout for master node operations, or null for default | ||
* @param ackTimeout the timeout for acknowledgment, or null for default | ||
*/ | ||
public Request( | ||
double rate, | ||
@Nullable Integer maxSamples, | ||
@Nullable ByteSizeValue maxSize, | ||
@Nullable TimeValue timeToLive, | ||
@Nullable String condition, | ||
@Nullable TimeValue masterNodeTimeout, | ||
@Nullable TimeValue ackTimeout | ||
) { | ||
super(masterNodeTimeout, ackTimeout); | ||
this.samplingConfiguration = new SamplingConfiguration(rate, maxSamples, maxSize, timeToLive, condition); | ||
} | ||
|
||
/** | ||
* Constructs a new request by deserializing from a stream input. | ||
* | ||
* @param in the stream input to read from | ||
* @throws IOException if an I/O error occurs during deserialization | ||
*/ | ||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.indices = in.readStringArray(); | ||
this.samplingConfiguration = new SamplingConfiguration(in); | ||
} | ||
|
||
/** | ||
* Serializes this request to a stream output. | ||
* | ||
* @param out the stream output to write to | ||
* @throws IOException if an I/O error occurs during serialization | ||
*/ | ||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeStringArray(indices); | ||
samplingConfiguration.writeTo(out); | ||
} | ||
|
||
/** | ||
* Returns the array of target indices for this sampling configuration request. | ||
* | ||
* @return an array of index names, never null but may be empty | ||
*/ | ||
@Override | ||
public String[] indices() { | ||
return indices; | ||
} | ||
|
||
/** | ||
* Sets the target indices for this sampling configuration request. | ||
* | ||
* @param dataStreamNames the names of indices or data streams to target | ||
seanzatzdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
* @return this request instance for method chaining | ||
*/ | ||
@Override | ||
public Request indices(String... dataStreamNames) { | ||
this.indices = dataStreamNames; | ||
return this; | ||
} | ||
|
||
/** | ||
* Indicates whether this request should include data streams in addition to regular indices. | ||
* | ||
* @return true to include data streams | ||
*/ | ||
@Override | ||
public boolean includeDataStreams() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Returns the indices options for this request, which control how index names are resolved and expanded. | ||
* | ||
* @return the indices options, configured to be lenient and expand both open and closed indices | ||
*/ | ||
@Override | ||
public IndicesOptions indicesOptions() { | ||
return IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED; | ||
} | ||
|
||
/** | ||
* Creates a cancellable task for tracking the execution of this request. | ||
* | ||
* @param id the unique task identifier | ||
* @param type the task type | ||
* @param action the action name | ||
* @param parentTaskId the parent task identifier, or null if this is a root task | ||
* @param headers the request headers | ||
* @return a new cancellable task instance | ||
*/ | ||
@Override | ||
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { | ||
return new CancellableTask(id, type, action, "", parentTaskId, headers); | ||
seanzatzdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Returns the sampling configuration encapsulated by this request. | ||
* | ||
* @return the sampling configuration | ||
*/ | ||
public SamplingConfiguration getSampleConfiguration() { | ||
return samplingConfiguration; | ||
} | ||
|
||
/** | ||
* Compares this request with another object for equality. | ||
* <p> | ||
* Two requests are considered equal if they have the same target indices and | ||
* sampling configuration parameters. | ||
* </p> | ||
* | ||
* @param o the object to compare with | ||
* @return true if the objects are equal, false otherwise | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Request that = (Request) o; | ||
return Arrays.equals(indices, that.indices) | ||
&& Objects.equals(samplingConfiguration, that.samplingConfiguration) | ||
&& Objects.equals(masterNodeTimeout(), that.masterNodeTimeout()) | ||
&& Objects.equals(ackTimeout(), that.ackTimeout()); | ||
} | ||
|
||
/** | ||
* Returns the hash code for this request. | ||
* <p> | ||
* The hash code is computed based on the target indices, sampling configuration, | ||
* master node timeout, and acknowledgment timeout. | ||
* </p> | ||
* | ||
* @return the hash code value | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(Arrays.hashCode(indices), samplingConfiguration, masterNodeTimeout(), ackTimeout()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.