-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add index mode to get data stream API #122486
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
Changes from 5 commits
ed79e17
8839217
b2c06f7
dac32e1
993d962
ddb2cb6
9300e9b
1b2a428
9813ac6
b902777
2ed217c
f76b5c6
a63bcd5
f75ed49
4ecb0d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 122486 | ||
summary: Add index mode to get data stream API | ||
area: Data streams | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.health.ClusterStateHealth; | ||
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; | ||
import org.elasticsearch.cluster.metadata.DataStream; | ||
import org.elasticsearch.cluster.metadata.DataStreamFailureStoreSettings; | ||
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetentionSettings; | ||
|
@@ -39,6 +40,9 @@ | |
import org.elasticsearch.core.Tuple; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexMode; | ||
import org.elasticsearch.index.IndexSettingProvider; | ||
import org.elasticsearch.index.IndexSettingProviders; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.indices.SystemDataStreamDescriptor; | ||
import org.elasticsearch.indices.SystemIndices; | ||
import org.elasticsearch.injection.guice.Inject; | ||
|
@@ -52,6 +56,7 @@ | |
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -67,6 +72,7 @@ public class TransportGetDataStreamsAction extends TransportMasterNodeReadAction | |
private final ClusterSettings clusterSettings; | ||
private final DataStreamGlobalRetentionSettings globalRetentionSettings; | ||
private final DataStreamFailureStoreSettings dataStreamFailureStoreSettings; | ||
private final IndexSettingProviders indexSettingProviders; | ||
private final Client client; | ||
|
||
@Inject | ||
|
@@ -79,6 +85,7 @@ public TransportGetDataStreamsAction( | |
SystemIndices systemIndices, | ||
DataStreamGlobalRetentionSettings globalRetentionSettings, | ||
DataStreamFailureStoreSettings dataStreamFailureStoreSettings, | ||
IndexSettingProviders indexSettingProviders, | ||
Client client | ||
) { | ||
super( | ||
|
@@ -96,6 +103,7 @@ public TransportGetDataStreamsAction( | |
this.globalRetentionSettings = globalRetentionSettings; | ||
clusterSettings = clusterService.getClusterSettings(); | ||
this.dataStreamFailureStoreSettings = dataStreamFailureStoreSettings; | ||
this.indexSettingProviders = indexSettingProviders; | ||
this.client = new OriginSettingClient(client, "stack"); | ||
} | ||
|
||
|
@@ -128,6 +136,7 @@ public void onResponse(DataStreamsStatsAction.Response response) { | |
clusterSettings, | ||
globalRetentionSettings, | ||
dataStreamFailureStoreSettings, | ||
indexSettingProviders, | ||
maxTimestamps | ||
) | ||
); | ||
|
@@ -148,12 +157,43 @@ public void onFailure(Exception e) { | |
clusterSettings, | ||
globalRetentionSettings, | ||
dataStreamFailureStoreSettings, | ||
indexSettingProviders, | ||
null | ||
) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Resolves the index mode ("index.mode" setting) for the given data stream, from the template or additional setting providers | ||
*/ | ||
@Nullable | ||
static IndexMode resolveMode( | ||
ClusterState state, | ||
IndexSettingProviders indexSettingProviders, | ||
DataStream dataStream, | ||
Settings settings, | ||
ComposableIndexTemplate indexTemplate | ||
) { | ||
IndexMode indexMode = state.metadata().retrieveIndexModeFromTemplate(indexTemplate); | ||
for (IndexSettingProvider provider : indexSettingProviders.getIndexSettingProviders()) { | ||
Settings addlSettinsg = provider.getAdditionalIndexSettings( | ||
MetadataIndexTemplateService.VALIDATE_INDEX_NAME, | ||
dataStream.getName(), | ||
indexMode, | ||
state.metadata(), | ||
Instant.now(), | ||
settings, | ||
List.of() | ||
); | ||
var rawMode = addlSettinsg.get(IndexSettings.MODE.getKey()); | ||
if (rawMode != null) { | ||
indexMode = Enum.valueOf(IndexMode.class, rawMode.toUpperCase(Locale.ROOT)); | ||
} | ||
} | ||
return indexMode; | ||
} | ||
|
||
static GetDataStreamAction.Response innerOperation( | ||
ClusterState state, | ||
GetDataStreamAction.Request request, | ||
|
@@ -162,6 +202,7 @@ static GetDataStreamAction.Response innerOperation( | |
ClusterSettings clusterSettings, | ||
DataStreamGlobalRetentionSettings globalRetentionSettings, | ||
DataStreamFailureStoreSettings dataStreamFailureStoreSettings, | ||
IndexSettingProviders indexSettingProviders, | ||
@Nullable Map<String, Long> maxTimestamps | ||
) { | ||
List<DataStream> dataStreams = getDataStreams(state, indexNameExpressionResolver, request); | ||
|
@@ -174,6 +215,7 @@ static GetDataStreamAction.Response innerOperation( | |
final String indexTemplate; | ||
boolean indexTemplatePreferIlmValue = true; | ||
String ilmPolicyName = null; | ||
IndexMode indexMode = dataStream.getIndexMode(); | ||
if (dataStream.isSystem()) { | ||
SystemDataStreamDescriptor dataStreamDescriptor = systemIndices.findMatchingDataStreamDescriptor(dataStream.getName()); | ||
indexTemplate = dataStreamDescriptor != null ? dataStreamDescriptor.getDataStreamName() : null; | ||
|
@@ -183,13 +225,31 @@ static GetDataStreamAction.Response innerOperation( | |
dataStreamDescriptor.getComponentTemplates() | ||
); | ||
ilmPolicyName = settings.get(IndexMetadata.LIFECYCLE_NAME); | ||
if (indexMode == null) { | ||
indexMode = resolveMode( | ||
state, | ||
indexSettingProviders, | ||
dataStream, | ||
settings, | ||
dataStreamDescriptor.getComposableIndexTemplate() | ||
); | ||
} | ||
indexTemplatePreferIlmValue = PREFER_ILM_SETTING.get(settings); | ||
} | ||
} else { | ||
indexTemplate = MetadataIndexTemplateService.findV2Template(state.metadata(), dataStream.getName(), false); | ||
if (indexTemplate != null) { | ||
Settings settings = MetadataIndexTemplateService.resolveSettings(state.metadata(), indexTemplate); | ||
ilmPolicyName = settings.get(IndexMetadata.LIFECYCLE_NAME); | ||
if (indexMode == null && state.metadata().templatesV2().get(indexTemplate) != null) { | ||
indexMode = resolveMode( | ||
state, | ||
indexSettingProviders, | ||
dataStream, | ||
settings, | ||
state.metadata().templatesV2().get(indexTemplate) | ||
); | ||
} | ||
indexTemplatePreferIlmValue = PREFER_ILM_SETTING.get(settings); | ||
} else { | ||
LOGGER.warn( | ||
|
@@ -281,7 +341,9 @@ public int compareTo(IndexInfo o) { | |
timeSeries, | ||
backingIndicesSettingsValues, | ||
indexTemplatePreferIlmValue, | ||
maxTimestamps == null ? null : maxTimestamps.get(dataStream.getName()) | ||
maxTimestamps == null ? null : maxTimestamps.get(dataStream.getName()), | ||
// Default to standard mode if not specified; should we set this to "unset" or "unspecified" instead? | ||
indexMode == null ? IndexMode.STANDARD.getName() : indexMode.getName() | ||
Comment on lines
+349
to
+350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the paranoid case for when we can't resolve it from the data stream template. I can only think of when a data stream gets restored from a snapshot without a template (so we wouldn't be able to resolve anything). |
||
) | ||
); | ||
} | ||
|
@@ -310,7 +372,11 @@ private static void collectIndexSettingsValues( | |
} else { | ||
managedBy = ManagedBy.UNMANAGED; | ||
} | ||
backingIndicesSettingsValues.put(index, new IndexProperties(preferIlm, indexMetadata.getLifecyclePolicyName(), managedBy)); | ||
String indexMode = IndexSettings.MODE.get(indexMetadata.getSettings()).getName(); | ||
backingIndicesSettingsValues.put( | ||
index, | ||
new IndexProperties(preferIlm, indexMetadata.getLifecyclePolicyName(), managedBy, indexMode) | ||
); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my curiosity, why do we favor the value in settings provider over the index template?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The settings provider can override settings at index creation time (it essentially has higher precedence over the template(s))