Skip to content

Commit

Permalink
Merge pull request #956: [ingest-server] strip '.*' from wildcard prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
je-ik authored Jan 23, 2025
2 parents 68d7878 + 9754a65 commit 13bd095
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ public void listAttributes(

try {
Metrics.LIST_REQUESTS.increment();
if (request.getEntity().isEmpty()
|| request.getKey().isEmpty()
|| request.getWildcardPrefix().isEmpty()) {
final String wildcardPrefix =
request.getWildcardPrefix().endsWith(".*")
? request.getWildcardPrefix().substring(0, request.getWildcardPrefix().length() - 2)
: request.getWildcardPrefix();

if (request.getEntity().isEmpty() || request.getKey().isEmpty() || wildcardPrefix.isEmpty()) {
throw new Status(400, "Missing some required fields");
}

Expand All @@ -133,24 +136,24 @@ public void listAttributes(

AttributeDescriptor<Object> wildcard =
entity
.findAttribute(request.getWildcardPrefix() + ".*")
.findAttribute(wildcardPrefix + ".*")
.orElseThrow(
() ->
new Status(
404,
"Entity "
+ request.getEntity()
+ " does not have wildcard attribute "
+ request.getWildcardPrefix()));
+ wildcardPrefix));

RandomAccessReader reader = instantiateReader(wildcard);

Rpc.ListResponse.Builder response = Rpc.ListResponse.newBuilder().setStatus(200);
Predicate<KeyValue<Object>> filterPredicate =
request.getWildcardPrefix().equals(wildcard.toAttributePrefix())
|| request.getWildcardPrefix().equals(wildcard.toAttributePrefix(false))
wildcardPrefix.equals(wildcard.toAttributePrefix())
|| wildcardPrefix.equals(wildcard.toAttributePrefix(false))
? ign -> true
: kv -> kv.getAttribute().startsWith(request.getWildcardPrefix());
: kv -> kv.getAttribute().startsWith(wildcardPrefix);
List<KeyValue<Object>> kvs = processListRequest(request, wildcard, reader, filterPredicate);
kvs.forEach(
kv ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ public void onCompleted() {}

@Test
public void testListValid() {
runListTestWithPrefix("wildcard");
runListTestWithPrefix("wildcard.");
runListTestWithPrefix("wildcard.*");
}

private void runListTestWithPrefix(String prefix) {
EntityDescriptor entity = server.repo.getEntity("dummy");
AttributeDescriptor<?> attribute = entity.getAttribute("wildcard.*");
String key = "my-fancy-entity-key";
Expand Down Expand Up @@ -516,7 +522,7 @@ public void testListValid() {
Rpc.ListRequest request =
Rpc.ListRequest.newBuilder()
.setEntity(entity.getName())
.setWildcardPrefix("wildcard")
.setWildcardPrefix(prefix)
.setKey(key)
.build();

Expand Down

0 comments on commit 13bd095

Please sign in to comment.