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

MESH-299 | Audit Search Logs #3974

Merged
merged 2 commits into from
Jan 14, 2025
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 @@ -315,8 +315,6 @@ public String toString() {
sb.append(", detail=").append(detail);
sb.append(", created=").append(created);
sb.append(", headers=").append(headers);


sb.append('}');

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -31,7 +32,7 @@ public EntityAuditSearchResult() { }
private Map<String, Object> aggregations;
private int count;
private int totalCount;
private Map<String, AtlasEntityHeader> linkedEntities;
private Map<String, AtlasEntityHeader> linkedEntities = new HashMap<>(0);

public List<EntityAuditEventV2> getEntityAudits() {
return entityAudits;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void setTotalCount(int totalCount) {

public Map<String, AtlasEntityHeader> getLinkedEntities() { return linkedEntities; }

public void setLinkedEntities(Map<String, AtlasEntityHeader> linkedEntities) { this.linkedEntities = linkedEntities; }
public void setLinkedEntities(Map<String, AtlasEntityHeader> linkedEntities) { this.linkedEntities = linkedEntities != null ? linkedEntities : new HashMap<>(0); }

@Override
public boolean equals(Object o) {
Expand All @@ -78,12 +79,13 @@ public boolean equals(Object o) {
return Objects.equals(entityAudits, that.entityAudits) &&
Objects.equals(aggregations, that.aggregations) &&
Objects.equals(count, that.count) &&
Objects.equals(totalCount, that.totalCount);
Objects.equals(totalCount, that.totalCount) &&
Objects.equals(linkedEntities, that.linkedEntities);
}

@Override
public int hashCode() {
return Objects.hash(entityAudits, aggregations, count, totalCount);
return Objects.hash(entityAudits, aggregations, count, totalCount, linkedEntities);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class ESBasedAuditRepository extends AbstractStorageBasedAuditRepository
private static final String DETAIL = "detail";
private static final String ENTITY = "entity";
private static final String bulkMetadata = String.format("{ \"index\" : { \"_index\" : \"%s\" } }%n", INDEX_NAME);
private static final Set<String> linkedAttributes = new HashSet<>(Arrays.asList(DOMAIN_GUIDS));
private static final Set<String> ALLOWED_LINKED_ATTRIBUTES = new HashSet<>(Arrays.asList(DOMAIN_GUIDS));

/*
* created → event creation time
Expand Down Expand Up @@ -227,10 +227,6 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
List<LinkedHashMap> hits_1 = (List<LinkedHashMap>) hits_0.get("hits");
Map<String, AtlasEntityHeader> existingLinkedEntities = searchResult.getLinkedEntities();

if (existingLinkedEntities == null) {
existingLinkedEntities = new HashMap<>();
}

for (LinkedHashMap hit : hits_1) {
Map source = (Map) hit.get("_source");
String entityGuid = (String) source.get(ENTITYID);
Expand Down Expand Up @@ -259,7 +255,7 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
Map<String, Object> attributes = (Map<String, Object>) detail.get("attributes");

for (Map.Entry<String, Object> entry: attributes.entrySet()) {
if (linkedAttributes.contains(entry.getKey())) {
if (ALLOWED_LINKED_ATTRIBUTES.contains(entry.getKey())) {
List<String> guids = (List<String>) entry.getValue();

if (guids != null && !guids.isEmpty()){
Expand All @@ -271,7 +267,7 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
existingLinkedEntities.put(guid, entityHeader);
}
} catch (AtlasBaseException e) {
throw new AtlasBaseException(e);
LOG.error("Error while fetching entity header for guid: {}", guid, e);
}
}
}
Expand Down
Loading