Skip to content
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

[Backport 2.11-with-features] Use a common constant to specify the version for log type mappings #708 #777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.opensearch.OpenSearchStatusException;
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.cluster.routing.Preference;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.action.ActionListener;
import org.opensearch.action.DocWriteRequest;
import org.opensearch.action.admin.indices.create.CreateIndexRequest;
Expand Down Expand Up @@ -78,8 +80,6 @@ public class LogTypeService {

public static final String LOG_TYPE_MAPPING_VERSION_META_FIELD = "schema_version";

public static final int LOG_TYPE_MAPPING_VERSION = 1; // must match version in log_type_config_mapping.json

public static final int MAX_LOG_TYPE_COUNT = 100;

private static volatile boolean isConfigIndexInitialized;
Expand All @@ -94,6 +94,8 @@ public class LogTypeService {

private String defaultSchemaField;

public int logTypeMappingVersion;

@Inject
public LogTypeService(Client client, ClusterService clusterService, NamedXContentRegistry xContentRegistry, BuiltinLogTypeLoader builtinLogTypeLoader) {
this.client = client;
Expand All @@ -106,6 +108,7 @@ public LogTypeService(Client client, ClusterService clusterService, NamedXConten
DEFAULT_MAPPING_SCHEMA,
newDefaultSchema -> this.defaultSchemaField = newDefaultSchema
);
setLogTypeMappingVersion();
}

public void getAllLogTypes(ActionListener<List<String>> listener) {
Expand Down Expand Up @@ -484,7 +487,7 @@ public void onFailure(Exception e) {
});
} else {
IndexMetadata metadata = state.getMetadata().index(LOG_TYPE_INDEX);
if (getConfigIndexMappingVersion(metadata) < LOG_TYPE_MAPPING_VERSION) {
if (getConfigIndexMappingVersion(metadata) < logTypeMappingVersion) {
// The index already exists but doesn't have our mapping
client.admin()
.indices()
Expand Down Expand Up @@ -772,8 +775,13 @@ public Map<String, String> getRuleFieldMappingsForBuiltinLogType(String builtinL
}
}


public String getDefaultSchemaField() {
return defaultSchemaField;
}

public void setLogTypeMappingVersion() {
Map<String, Object> logTypeConfigAsMap =
XContentHelper.convertToMap(JsonXContent.jsonXContent, logTypeIndexMapping(), false);
this.logTypeMappingVersion = (int)((Map)logTypeConfigAsMap.get("_meta")).get("schema_version");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public void testIndexMappings() throws ExecutionException, InterruptedException

}


public void testSetLogTypeMappingSchema() {
int expectedVersion = 2;
int version = logTypeService.logTypeMappingVersion;
assertEquals(expectedVersion, version);
}

private void indexFieldMappings(List<FieldMappingDoc> fieldMappingDocs) {
PlainActionFuture<Void> fut = new PlainActionFuture<>();
Expand Down
Loading