Skip to content

Commit

Permalink
Merge pull request #2400 from atlanhq/auditindexfieldlimit
Browse files Browse the repository at this point in the history
[master] entity_audits index Update field limits only if needed
  • Loading branch information
nikhilbonte21 authored Oct 30, 2023
2 parents d8bcd7d + 019944c commit 54908fb
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void createSession() throws AtlasException {
LOG.info("Create ES index for entity audits in ES Based Audit Repo");
createAuditIndex();
}
if (isFieldLimitDifferent()) {
if (shouldUpdateFieldLimitSetting()) {
LOG.info("Updating ES total field limit");
updateFieldLimit();
}
Expand Down Expand Up @@ -328,24 +328,25 @@ private boolean createAuditIndex() throws IOException {
return isSuccess(response);
}

private boolean isFieldLimitDifferent() {
JsonNode fieldLimit;
private boolean shouldUpdateFieldLimitSetting() {
JsonNode currentFieldLimit;
try {
fieldLimit = getIndexFieldLimit();
currentFieldLimit = getIndexFieldLimit();
} catch (IOException e) {
LOG.error("Problem while retrieving the index field limit!", e);
return false;
}
Integer fieldLimitFromConfigurationFile = configuration.getInt(TOTAL_FIELD_LIMIT);
return fieldLimit == null || fieldLimitFromConfigurationFile.equals(fieldLimit.intValue());
Integer fieldLimitFromConfigurationFile = configuration.getInt(TOTAL_FIELD_LIMIT, 0);
return currentFieldLimit == null || fieldLimitFromConfigurationFile > currentFieldLimit.asInt();
}

private JsonNode getIndexFieldLimit() throws IOException {
Request request = new Request("GET", INDEX_NAME + "/_settings");
Response response = lowLevelClient.performRequest(request);
ObjectMapper objectMapper = new ObjectMapper();
String fieldName = INDEX_NAME + ".settings.index.mapping.total_fields.limit";
return objectMapper.readTree(copyToString(response.getEntity().getContent(), Charset.defaultCharset())).get(fieldName);
String fieldPath = String.format("/%s/settings/index/mapping/total_fields/limit", INDEX_NAME);

return objectMapper.readTree(copyToString(response.getEntity().getContent(), Charset.defaultCharset())).at(fieldPath);
}

private void updateFieldLimit() {
Expand Down

0 comments on commit 54908fb

Please sign in to comment.