Skip to content

[PR - 0] Add cryostat operator instance and REST API changes#1957

Open
khansaad wants to merge 2 commits into
kruize:runtimes-iirjfrom
khansaad:mds-pr-0-initial-design-changes
Open

[PR - 0] Add cryostat operator instance and REST API changes#1957
khansaad wants to merge 2 commits into
kruize:runtimes-iirjfrom
khansaad:mds-pr-0-initial-design-changes

Conversation

@khansaad

@khansaad khansaad commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds cryostat datasource client support and REST client handling needed for executing layer queries against cryostat-backed datasources.
Also, Updates datasource abstraction and shared constants/types needed to support multi-datasource layer query execution without including cryostat client-specific implementation changes.

Fixes # (issue)

Type of change

  • Bug fix
  • New feature
  • Docs update
  • Breaking change (What changes might users need to make in their application due to this PR?)
  • Requires DB changes

How has this been tested?

Please describe the tests that were run to verify your changes and steps to reproduce. Please specify any test configuration required.

  • New Test X
  • Functional testsuite

Test Configuration

  • Kubernetes clusters tested on:

Checklist 🎯

  • Followed coding guidelines
  • Comments added
  • Dependent changes merged
  • Documentation updated
  • Tests added or updated

Additional information

Include any additional information such as links, test results, screenshots here

Summary by Sourcery

Add Cryostat as a supported datasource provider and extend the generic REST client to support POST-based JSON queries and more robust response handling.

New Features:

  • Introduce CryostatDataOperatorImpl to integrate Cryostat as a datasource, including reachability checks and query handling stubs.
  • Add Cryostat to the set of supported datasource providers and wire it into the datasource operator selection logic.

Enhancements:

  • Extend GenericRestApiClient to support POST requests with JSON bodies and skip Prometheus-specific parsing for non-GET responses.
  • Improve datasource provider validation by centralizing allowed providers into KruizeSupportedTypes.DATASOURCES_SUPPORTED.
  • Harden REST response handling by treating null or empty responses as empty JSON objects and refining result/warning inspection.

Signed-off-by: Saad Khan <saakhan@ibm.com>
@sourcery-ai

sourcery-ai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds Cryostat as a supported datasource, including a new Cryostat data operator implementation, updates datasource provider selection and supported types, and extends the generic REST client to support POST requests and safer JSON handling needed for Cryostat’s GraphQL API.

Sequence diagram for Cryostat POST GraphQL query via GenericRestApiClient

sequenceDiagram
    participant CryostatDataOperatorImpl
    participant GenericRestApiClient
    participant HttpClient

    CryostatDataOperatorImpl->>GenericRestApiClient: fetchMetricsJson(POST, query)
    GenericRestApiClient->>GenericRestApiClient: methodType.equalsIgnoreCase(POST)
    alt methodType is POST
        GenericRestApiClient->>GenericRestApiClient: create HttpPost(baseURL)
        GenericRestApiClient->>GenericRestApiClient: setEntity(StringEntity(query, ContentType.APPLICATION_JSON))
        GenericRestApiClient->>GenericRestApiClient: LOGGER.info(Request body)
    else methodType is GET
        GenericRestApiClient->>GenericRestApiClient: create HttpGet(baseURL + encoded query)
    end

    GenericRestApiClient->>HttpClient: execute(httpRequestBase)
    HttpClient-->>GenericRestApiClient: response
    GenericRestApiClient->>GenericRestApiClient: jsonResponse = StringResponseHandler.handleResponse(response)

    alt jsonResponse is null or blank
        GenericRestApiClient->>GenericRestApiClient: LOGGER.warn(null or empty JSON)
        GenericRestApiClient-->>CryostatDataOperatorImpl: new JSONObject()
    else jsonResponse not blank
        opt methodType is not POST
            GenericRestApiClient->>GenericRestApiClient: parse jsonResponse for data.result and warnings
            GenericRestApiClient->>GenericRestApiClient: may throw IOException on warnings
        end
        GenericRestApiClient-->>CryostatDataOperatorImpl: new JSONObject(jsonResponse)
    end
Loading

File-Level Changes

Change Details Files
Extend GenericRestApiClient to support POST requests and relax Prometheus-specific response assumptions.
  • Add HTTP POST handling with JSON request body to fetchMetricsJson, including request logging.
  • Skip Prometheus-specific result/warnings parsing for POST requests, treating responses as opaque JSON.
  • Improve empty-result handling by using isEmpty() on arrays and returning an empty JSONObject when the response body is null or blank, with a warning log.
src/main/java/com/autotune/utils/GenericRestApiClient.java
Wire Cryostat into datasource operator selection and supported provider validation.
  • Refactor getOperator to use a switch expression and add a mapping from the Cryostat provider string to CryostatDataOperatorImpl.
  • Introduce a central DATASOURCES_SUPPORTED set and use it in datasource validation instead of hard-coded provider checks.
  • Add Cryostat to SupportedDatasources constants.
src/main/java/com/autotune/common/datasource/DataSourceOperatorImpl.java
src/main/java/com/autotune/common/datasource/DataSourceCollection.java
src/main/java/com/autotune/utils/KruizeSupportedTypes.java
src/main/java/com/autotune/utils/KruizeConstants.java
Introduce CryostatDataOperatorImpl to talk to Cryostat’s GraphQL API via the generic REST client.
  • Implement singleton CryostatDataOperatorImpl extending DataSourceOperatorImpl, defining default port and GraphQL endpoint.
  • Implement reachability and value retrieval by issuing POST GraphQL queries through GenericRestApiClient and interpreting non-null JSON responses as success.
  • Stub out result-array extraction and validation methods, with TODO for actual GraphQL response parsing, and handle UnknownHostException as an unreachable datasource.
src/main/java/com/autotune/common/datasource/cryostat/CryostatDataOperatorImpl.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@khansaad khansaad moved this to Under Review in Monitoring Jun 11, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • In CryostatDataOperatorImpl.getResultArrayForQuery the TODO currently results in always returning null; consider either implementing the GraphQL response parsing now or throwing an explicit UnsupportedOperationException so that callers don’t silently proceed with an unexpected null result.
  • The Cryostat-specific methods (isServiceable, getValueForQuery, getJsonObjectForQuery) use null responses as a generic signal (e.g., for reachability); it may be helpful to distinguish between different failure modes (DNS/host errors vs other IO/parsing errors) so the caller can react more precisely.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `CryostatDataOperatorImpl.getResultArrayForQuery` the TODO currently results in always returning `null`; consider either implementing the GraphQL response parsing now or throwing an explicit `UnsupportedOperationException` so that callers don’t silently proceed with an unexpected `null` result.
- The Cryostat-specific methods (`isServiceable`, `getValueForQuery`, `getJsonObjectForQuery`) use `null` responses as a generic signal (e.g., for reachability); it may be helpful to distinguish between different failure modes (DNS/host errors vs other IO/parsing errors) so the caller can react more precisely.

## Individual Comments

### Comment 1
<location path="src/main/java/com/autotune/common/datasource/DataSourceCollection.java" line_range="109" />
<code_context>
         }

-        if (!provider.equalsIgnoreCase(KruizeConstants.SupportedDatasources.PROMETHEUS) && !provider.equalsIgnoreCase(KruizeConstants.SupportedDatasources.THANOS)) {
+        if (!KruizeSupportedTypes.DATASOURCES_SUPPORTED.contains(provider)) {
             throw new UnsupportedDataSourceProvider(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.UNSUPPORTED_DATASOURCE_PROVIDER);
         }
</code_context>
<issue_to_address>
**issue (bug_risk):** Provider validation is now case-sensitive, which changes existing behavior.

The old logic used `equalsIgnoreCase`, but `DATASOURCES_SUPPORTED` contains only lowercase values and `contains(provider)` is case-sensitive, so inputs like `"PROMETHEUS"` or `"Thanos"` will now fail. Normalize `provider` (e.g., `provider.toLowerCase(Locale.ROOT)`) before checking membership, or ensure the set and inputs are consistently normalized.
</issue_to_address>

### Comment 2
<location path="src/main/java/com/autotune/utils/GenericRestApiClient.java" line_range="111-113" />
<code_context>
+                        )
+                );
+                httpRequestBase = httpPost;
+                LOGGER.info(
+                        "Request body: {}",
+                        EntityUtils.toString(
+                                ((HttpPost) httpRequestBase).getEntity(),
+                                StandardCharsets.UTF_8
</code_context>
<issue_to_address>
**🚨 issue (security):** Logging the full POST request body at INFO may expose sensitive data.

This branch logs the entire JSON body at INFO, which can expose credentials or tokens in logs. Please either lower this to DEBUG, redact sensitive fields, or make it configurable so it can be disabled in production environments.
</issue_to_address>

### Comment 3
<location path="src/main/java/com/autotune/utils/GenericRestApiClient.java" line_range="156-160" />
<code_context>
                 }
             }
         }
+        if (jsonResponse == null || jsonResponse.isBlank()) {
+            LOGGER.warn("Received null or empty JSON response");
+            return new JSONObject();
+        }
         return new JSONObject(jsonResponse);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Returning an empty JSONObject on null/blank responses may hide upstream errors.

This change makes an empty or null body indistinguishable from a valid (but empty) JSON object. Callers expecting required fields may now treat an upstream failure as a valid response. Consider signaling this case explicitly (e.g., throw for non-JSON/empty responses or return `null`) so callers can differentiate "no/invalid data" from a successful JSON payload.

```suggestion
        if (jsonResponse == null || jsonResponse.isBlank()) {
            LOGGER.warn("Received null or empty JSON response");
            throw new IOException("Received null or empty JSON response");
        }
        return new JSONObject(jsonResponse);
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/main/java/com/autotune/common/datasource/DataSourceCollection.java Outdated
Comment thread src/main/java/com/autotune/utils/GenericRestApiClient.java Outdated
Comment thread src/main/java/com/autotune/utils/GenericRestApiClient.java
Signed-off-by: Saad Khan <saakhan@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

2 participants