Skip to content

feat(graphql): implement k8s-style label selectors #872

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 18 commits into from
Apr 19, 2022

Conversation

andrewazores
Copy link
Member

@andrewazores andrewazores commented Mar 25, 2022

Closes #846
Closes #825
Closes #822
Closes #821
Closes #820

This adds labels to GraphQL query filters for nodes in the deployment tree and for recordings, as well as annotations to query filters on target nodes. For annotations the Cryostat-generated annotations and the platform-provided annotations are merged together into one map. Both the labels and annotations query fields are optional, and can be given a Kubernetes label selector expression to match against the labels or annotations maps on the objects being queried.

@andrewazores andrewazores added the feat New feature or request label Mar 25, 2022
@andrewazores andrewazores marked this pull request as draft March 25, 2022 02:56
@andrewazores andrewazores marked this pull request as ready for review March 25, 2022 22:26
@jan-law jan-law self-requested a review March 28, 2022 20:08
@andrewazores andrewazores requested a review from ebaron March 29, 2022 12:45
@andrewazores andrewazores force-pushed the graphql-k8s-label-selector branch from 7220c2c to e1857df Compare March 29, 2022 12:46
Copy link
Contributor

@jan-law jan-law left a comment

Choose a reason for hiding this comment

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

The label equality matchers are working well with both labels and annotation filters. Just had a question about the set matchers

@andrewazores andrewazores force-pushed the graphql-k8s-label-selector branch from 694d420 to 670e06d Compare March 30, 2022 22:50
@andrewazores
Copy link
Member Author

With the latest commit you can perform a query like:

query {
    environmentNodes(filter: { name: "JDP" }) {
        name
        nodeType
        descendantTargets (filter: { annotations: ["PORT in (9091, 9096)", "env != production"] }) {
            target {
                alias
                annotations {
                cryostat
                }
            }
        }
    }
}

GraphQL also seems to support a sort of "bare singleton" for lists, so you can also do:

query {
    environmentNodes(filter: { name: "JDP" }) {
        name
        nodeType
        descendantTargets (filter: { annotations: "PORT in (9091, 9096)" } ) {
            target {
                alias
                annotations {
                cryostat
                }
            }
        }
    }
}

Copy link
Contributor

@jan-law jan-law left a comment

Choose a reason for hiding this comment

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

Looks good!

Looking ahead, will there be other documentation (eg on HTTP_API or cryostat.io) for these 2.1 GraphQL features besides the blog posts?

@andrewazores
Copy link
Member Author

I think a general description of the GraphQL endpoint in HTTP_API.md makes sense, but since that endpoint has so many possibilities in operation depending on the query sent, it's a little too hefty to describe it all there. There is still the GRAPHQL.md and the graphql/ examples hanging around which I had intended as temporary and to be cleaned up later, but perhaps it makes sense to clean them up and keep them around as in-repo docs. There should also be some form of documentation for this feature that also makes it onto cryostat.io for upstream docs, as well as something similar to whatever that ends up being for downstream product docs.

Copy link
Contributor

@jan-law jan-law left a comment

Choose a reason for hiding this comment

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

Whoops, just saw this now

@andrewazores andrewazores merged commit a957d56 into cryostatio:main Apr 19, 2022
@andrewazores andrewazores deleted the graphql-k8s-label-selector branch April 19, 2022 14:08
mergify bot pushed a commit that referenced this pull request Apr 19, 2022
* feat(graphql): implement k8s-style label selectors

* apply spotless formatting

* handle null expression string

* remove unused input type

* hook label selector matcher into fetchers

* hook label selector matcher into annotations on target fetchers

* do not include parens in values character set

* relax regexes to allow non-whitespace characters

* fixup! relax regexes to allow non-whitespace characters

* exercise set membership a bit more

* support conjunction of filter/annotation expressions by GraphQL list

* remove disabled/unsupported test

(cherry picked from commit a957d56)
andrewazores added a commit that referenced this pull request Apr 19, 2022
* feat(graphql): implement k8s-style label selectors

* apply spotless formatting

* handle null expression string

* remove unused input type

* hook label selector matcher into fetchers

* hook label selector matcher into annotations on target fetchers

* do not include parens in values character set

* relax regexes to allow non-whitespace characters

* fixup! relax regexes to allow non-whitespace characters

* exercise set membership a bit more

* support conjunction of filter/annotation expressions by GraphQL list

* remove disabled/unsupported test

(cherry picked from commit a957d56)

Co-authored-by: Andrew Azores <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport feat New feature or request
Projects
None yet
3 participants