8000 Revert "Append the tags" by gauravakto · Pull Request #2732 · akto-api-security/akto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Revert "Append the tags" #2732

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

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
16 changes: 5 additions & 11 deletions libs/dao/src/main/java/com/akto/dto/traffic/CollectionTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import java.util.Objects;

import com.akto.dao.context.Context;
import com.fasterxml.jackson.core.JsonProcessingException;
Copy link
Preview
Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Several imports (JsonProcessingException, ObjectMapper, BasicDBObject) are not used. Consider removing them to keep the code clean.

Copilot uses AI. Check for mistakes.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.mongodb.BasicDBObject;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -39,17 +43,7 @@ public enum TagSource {

@Override
public int hashCode() {
Copy link
Preview
Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom equals override was removed but hashCode remains overridden, breaking the equals/hashCode contract. Reintroduce a matching equals method or remove the custom hashCode to maintain consistency.

Copilot uses AI. Check for mistakes.

return Objects.hash(keyName, value, source);
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
CollectionTags that = (CollectionTags) obj;
return Objects.equals(keyName, that.keyName) &&
Objects.equals(value, that.value) &&
source == that.source;
return Objects.hash(lastUpdatedTs, keyName, value, source);
}


Expand Down
23 changes: 14 additions & 9 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
< B035 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,20 @@ public static void createCollectionSimple(int vxlanId) {
);
}

private static List<CollectionTags> getFilteredTags(List<CollectionTags> tags) {
if(tags == null || tags.isEmpty()) {
return Collections.emptyList();
private static List<CollectionTags> getPreservedTags(ApiCollection apiCollection, List<CollectionTags> tags) {
// Replace only the KUBERNETES source tags
List<CollectionTags> preservedTags = new ArrayList<>();
if (apiCollection!= null && apiCollection.getTagsList() != null) {
for (CollectionTags tag : apiCollection.getTagsList()) {
if (!CollectionTags.TagSource.KUBERNETES.equals(tag.getSource())) {
preservedTags.add(tag);
}
}
}
List<String> igNoreList = Arrays.asList("pod-template-hash");
// Ignore tags from the ignore list
tags.removeIf(tag -> tag.getKeyName() != null && igNoreList.contains(tag.getKeyName()));

return tags;
// Merge preserved tags with input tags
preservedTags.addAll(tags);
return preservedTags;
}

public static void createCollectionSimpleForVpc(int vxlanId, String vpcId, List<CollectionTags> tags) {
Expand Down Expand Up @@ -516,7 +521,7 @@ public static void createCollectionSimpleForVpc(int vxlanId, String vpcId, List<

if (tags != null && !tags.isEmpty()) {
// Update the entire tagsList
update = Updates.combine(update, Updates.addEachToSet(ApiCollection.TAGS_STRING, getFilteredTags(tags)));
update = Updates.combine(update, Updates.set(ApiCollection.TAGS_STRING, getPreservedTags(apiCollection, tags)));
}

ApiCollectionsDao.instance.getMCollection().updateOne(
Expand Down Expand Up @@ -565,7 +570,7 @@ public static void createCollectionForHostAndVpc(String host, int id, String vpc
}

if(tags != null && !tags.isEmpty()) {
updates = Updates.combine(updates, Updates.addEachToSet(ApiCollection.TAGS_STRING, getFilteredTags(tags)));
updates = Updates.combine(updates, Updates.set(ApiCollection.TAGS_STRING, getPreservedTags(apiCollection, tags)));
}

ApiCollectionsDao.instance.getMCollection().findOneAndUpdate(Filters.eq(ApiCollection.HOST_NAME, host), updates, updateOptions);
Expand Down
Loading
0