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

[Task] Add GraphQL filter ability for node name from set #1433

Closed
andrewazores opened this issue Mar 28, 2023 · 0 comments · Fixed by #1518
Closed

[Task] Add GraphQL filter ability for node name from set #1433

andrewazores opened this issue Mar 28, 2023 · 0 comments · Fixed by #1518
Assignees
Labels
feat New feature or request good first issue Good for newcomers

Comments

@andrewazores
Copy link
Member

          https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/resources/types.graphqls#L19

https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/java/io/cryostat/net/web/http/api/v2/graph/FilterInput.java#L69

https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java#L108 / https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java#L115

https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java#L97 / https://github.com/cryostatio/cryostat/blob/9bcda3f42ad05349a38d3767f33f11042aa767d2/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java#L104

I think this functionality can be retrofitted into the existing system pretty cleanly actually:

diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/FilterInput.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/FilterInput.java
index ee783a7c..a845453d 100644
--- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/FilterInput.java
+++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/FilterInput.java
@@ -67,6 +67,7 @@ class FilterInput {
     enum Key {
         ID("id"),
         NAME("name"),
+        NAMES("names"),
         LABELS("labels"),
         ANNOTATIONS("annotations"),
         SOURCE_TARGET("sourceTarget"),
diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java
index 2e6df720..a966d1bd 100644
--- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java
+++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java
@@ -112,6 +112,16 @@ class TargetNodesFetcher extends AbstractPermissionedDataFetcher<List<TargetNode
                             .filter(n -> Objects.equals(n.getName(), nodeName))
                             .collect(Collectors.toList());
         }
+        if (filter.contains(FilterInput.Key.NAMES)) {
+            List<String> names = filter.get(FilterInput.Key.NAMES);
+            for (String name : names) {
+                result =
+                        result.stream()
+                                .filter(n -> LabelSelectorMatcher.parse(name).test(Map.of("name",
+                                                n.getName())))
+                                .collect(Collectors.toList());
+            }
+        }
         if (filter.contains(FilterInput.Key.LABELS)) {
             List<String> labels = filter.get(FilterInput.Key.LABELS);
             for (String label : labels) {
diff --git a/src/main/resources/types.graphqls b/src/main/resources/types.graphqls
index 410efb66..5b15af3d 100644
--- a/src/main/resources/types.graphqls
+++ b/src/main/resources/types.graphqls
@@ -17,6 +17,7 @@ input EnvironmentNodeFilterInput {
 input TargetNodesFilterInput {
     id: Int
     name: String
+    names: [String]
     labels: [String]
     annotations: [String]
 }

haven't tested this, just an idea. This would just allow for a single query to match a given node if its name is not just equal to a specific value, but if its name is a member of a given set. Then clients can make much more flexible requests targeting sets of nodes and doing further queries on those all server-side. Thoughts? If this makes sense I will go ahead and work on a PR.

Originally posted by @andrewazores in cryostatio/cryostat-web#920 (comment)

@andrewazores andrewazores added the feat New feature or request label Mar 28, 2023
@andrewazores andrewazores self-assigned this Mar 28, 2023
@andrewazores andrewazores moved this to Todo in 2.4.0 release Mar 28, 2023
@andrewazores andrewazores moved this from Todo to Backlog in 2.4.0 release May 23, 2023
@andrewazores andrewazores removed their assignment Jun 2, 2023
@andrewazores andrewazores added the good first issue Good for newcomers label Jun 2, 2023
@andrewazores andrewazores moved this from Backlog to Todo in 2.4.0 release Jun 2, 2023
@aali309 aali309 moved this from Todo to In Progress in 2.4.0 release Jun 5, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in 2.4.0 release Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request good first issue Good for newcomers
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants