Skip to content

Conversation

@joshuali925
Copy link
Member

@joshuali925 joshuali925 commented Mar 17, 2025

Description

This PR adds direct-query-core module to SQL. It implements the following changes

  • move some shared classes from prometheus module to direct-query-core
    • prometheus client
    • client exception
    • metric metadata model
    • test fixtures
  • add direct-query-core module to support ExecuteDirectQuery and GetDirectQueryResources actions
  • implement query handler for executing the actions. currently the only supported data source type is prometheus

This PR does not expose the actions in SQL plugin at runtime. The follow up #3441 for direct-query module will add the rest and transport actions to SQL

Query API owner: @goyamegh
Resources API owner: @joshuali925

It is currently in draft since some tests are not fixed yet

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@Override
public ExecuteDirectQueryResponse executeDirectQuery(ExecuteDirectQueryRequest request) {
// TODO: Replace with the data source query id.
String queryId = UUID.randomUUID().toString();
Copy link
Member Author

Choose a reason for hiding this comment

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

is this needed?

try {
return handler.executeQuery(client, request);
} catch (IOException e) {
return "{\"error\": \"Error executing query: " + e.getMessage() + "\"}";
Copy link
Member Author

Choose a reason for hiding this comment

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

if prometheus returns an error, should the SQL request fail with non-200 response?

Response response = this.okHttpClient.newCall(request).execute();

logger.info("Received Prometheus response for instant query: code={}", response);
// Return the full response object, not just the data field
Copy link
Member Author

Choose a reason for hiding this comment

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

what does the comment mean?

package org.opensearch.sql.prometheus.exceptions;
package org.opensearch.sql.prometheus.exception;

import org.opensearch.sql.datasources.exceptions.DataSourceClientException;
Copy link
Member Author

@joshuali925 joshuali925 Mar 18, 2025

Choose a reason for hiding this comment

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

this should be package org.opensearch.sql.datasource.client.exceptions.DataSourceClientException;? i think we should remove one of the two DataSourceClientException

any reason we need the datasource package under direct-query-core? or can we move it to datasource module?

@opensearch-trigger-bot
Copy link
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@RyanL1997
Copy link
Collaborator

Hi @joshuali925 , do we still need this?

@joshuali925
Copy link
Member Author

we do, but currently no bandwidth

@goyamegh
Copy link
Contributor

goyamegh commented May 6, 2025

we do, but currently no bandwidth

@lezzago and I will take over this and take it further. Thanks.

@opensearch-trigger-bot
Copy link
Contributor

This PR is stalled because it has been open for 30 days with no activity.

// Optional fields
private Integer maxResults; // Optional: limit for Prometheus, maxDataPoints for CW
private Integer timeout; // Optional: number of seconds
private DataSourceOptions options; // Optional: Source specific arguments
Copy link
Member

Choose a reason for hiding this comment

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

Would we want a separate queryOptions or is the idea to have this contain query options as those are in a way specific to a datasource.

Copy link
Member Author

Choose a reason for hiding this comment

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

can't remember the details, will leave it to query API owner @goyamegh

currently this is the only usage

public class PrometheusOptions implements DataSourceOptions {
private PrometheusQueryType queryType;
private String step; // Duration string in seconds
private String time; // ISO timestamp for instant queries
private String start; // ISO timestamp for range queries
private String end; // ISO timestamp for range queries
}

does look like query options

public class ExecuteDirectQueryResponse {
private String queryId;
private String result;
private String sessionId;
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed if we have the queryId? What benefit is there to add another tracker if we can just use queryId everywhere instead.

Copy link
Member Author

@joshuali925 joshuali925 Aug 25, 2025

Choose a reason for hiding this comment

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

i remember session id is for EMR job control, and different queries might reuse the same EMR job. I might be wrong but i agree direct (sync) query shouldn't have session concept.

will leave it to query API owner @goyamegh

@joshuali925 joshuali925 changed the base branch from main to feature/direct-query-prometheus September 4, 2025 19:04
@joshuali925 joshuali925 marked this pull request as ready for review September 4, 2025 19:09
@joshuali925 joshuali925 merged commit 0ee85a3 into opensearch-project:feature/direct-query-prometheus Sep 4, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants