-
Notifications
You must be signed in to change notification settings - Fork 149
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
Add direct-query-core module for prometheus integration #3440
base: main
Are you sure you want to change the base?
Add direct-query-core module for prometheus integration #3440
Conversation
Co-authored-by: Megha Goyal <[email protected]> Signed-off-by: Joshua Li <[email protected]>
return dataSourceService.getDataSourceMetadata(dataSourceName).getConnector(); | ||
} | ||
|
||
private Object createClientForType(String dataSourceType, DataSourceMetadata metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be better to create a base client interface instead of Object and generics. Currently it's not straightforward to find all data source client implementations
switch (dataSourceType) { | ||
case "PROMETHEUS": | ||
return createPrometheusClient(metadata); | ||
// Add cases for other data source types as needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commment
|
||
private PrometheusClient createPrometheusClient(DataSourceMetadata metadata) { | ||
try { | ||
// replace this with validate properties in PrometheusStorageFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed?
|
||
package org.opensearch.sql.directquery.rest.model; | ||
|
||
public enum QueryEntityType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
@Override | ||
public ExecuteDirectQueryResponse executeDirectQuery(ExecuteDirectQueryRequest request) { | ||
// TODO: Replace with the data source query id. | ||
String queryId = UUID.randomUUID().toString(); |
There was a problem hiding this comment.
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() + "\"}"; |
There was a problem hiding this comment.
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?
String queryString = | ||
params.entrySet().stream() | ||
.map( | ||
entry -> | ||
URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) | ||
+ "=" | ||
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) | ||
.collect(Collectors.joining("&")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String queryString = | |
params.entrySet().stream() | |
.map( | |
entry -> | |
URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) | |
+ "=" | |
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) | |
.collect(Collectors.joining("&")); | |
String queryString = this.paramsToQueryString(params); |
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 |
There was a problem hiding this comment.
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?
URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) | ||
+ "=" | ||
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) | ||
.collect(Collectors.joining("&")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also reuse the paramsToQueryString
here
*/ | ||
|
||
package org.opensearch.sql.prometheus.exceptions; | ||
package org.opensearch.sql.prometheus.exception; | ||
|
||
import org.opensearch.sql.datasources.exceptions.DataSourceClientException; |
There was a problem hiding this comment.
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?
Description
This PR adds direct-query-core module to SQL. It implements the following changes
ExecuteDirectQuery
andGetDirectQueryResources
actionsprometheus
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 SQLQuery 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
--signoff
.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.