-
Notifications
You must be signed in to change notification settings - Fork 202
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
Prometheus Sink draft code for issue #1744. #3103
Prometheus Sink draft code for issue #1744. #3103
Conversation
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
…project#1744. Signed-off-by: mallikagogoi7 <[email protected]>
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.
General comments:
- Use final on local and method variables.
- Add metrics for success and failure scenarios.
|
||
- `url` The http/https endpoint url which can bee backed by prometheus. | ||
|
||
- `encoding` Default is snappy |
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.
Do we support other encoding and content-type ?
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.
@dinujoh Thanks for your review. No, currently only snappy is required to support Prometheus.
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.
Since we don't support any other configuration, this configuration parameter is not adding any value unless we have a followup plan to support another encoding. Can you followup and check what is the plan ?
@BeforeEach | ||
void setUp() throws JsonProcessingException{ | ||
this.urlString = System.getProperty("tests.prometheus.sink.http.endpoint"); | ||
String[] values = { urlString,"unauthenticated","ap-south-1","arn:aws:iam::524239988944:role/app-test" }; |
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.
the role and region needs to be configurable.
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.
@dinujoh Thanks for your review. It should be configurable and should be read from system properties. Will update the code accordingly.
* An {@link HttpRequestInterceptor} that signs requests using any AWS {@link Signer} | ||
* and {@link AwsCredentialsProvider}. | ||
*/ | ||
public final class AwsRequestSigningApacheInterceptor implements HttpRequestInterceptor { |
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 class code is duplicated. We need to move this to common plugin module.
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 can be moved to aws-plugin-api
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.
@dinujoh Thanks for your review. Will update the code accordingly.
* This class consist logic for downloading the SSL certificates from S3/ACM/Local file. | ||
* | ||
*/ | ||
public class CertificateProviderFactory { |
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 class is duplicated as well. Need to move this to common module.
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.
Move this to common certificate module. This class would need refactoring to remove direct dependency on PrometheusSinkConfiguration and set the required parameters in the constructor or create common object for them.
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.
@dinujoh Thanks for your review. Will update the code accordingly.
if (event instanceof JacksonGauge) { | ||
JacksonGauge jacksonGauge = (JacksonGauge) event; | ||
message = buildRemoteWriteRequest(jacksonGauge.getTime(), | ||
jacksonGauge.getStartTime(), jacksonGauge.getValue(), jacksonGauge.getAttributes(),jacksonGauge.getName()); | ||
} else if (event instanceof JacksonSum) { | ||
JacksonSum jacksonSum = (JacksonSum) event; | ||
message = buildRemoteWriteRequest(jacksonSum.getTime(), | ||
jacksonSum.getStartTime(), jacksonSum.getValue(), jacksonSum.getAttributes(), jacksonSum.getName()); | ||
} else if (event instanceof JacksonSummary) { | ||
JacksonSummary jacksonSummary = (JacksonSummary) event; | ||
message = buildRemoteWriteRequest(jacksonSummary.getTime(), | ||
jacksonSummary.getStartTime(), jacksonSummary.getSum(), jacksonSummary.getAttributes(), jacksonSummary.getName()); | ||
} else if (event instanceof JacksonHistogram) { | ||
JacksonHistogram jacksonHistogram = (JacksonHistogram) event; | ||
message = buildRemoteWriteRequest(jacksonHistogram.getTime(), | ||
jacksonHistogram.getStartTime(), jacksonHistogram.getSum(), jacksonHistogram.getAttributes(), jacksonHistogram.getName()); | ||
} else if (event instanceof JacksonExponentialHistogram) { | ||
JacksonExponentialHistogram jacksonExpHistogram = (JacksonExponentialHistogram) event; | ||
message = buildRemoteWriteRequest(jacksonExpHistogram.getTime(), | ||
jacksonExpHistogram.getStartTime(), jacksonExpHistogram.getSum(), jacksonExpHistogram.getAttributes(), jacksonExpHistogram.getName()); | ||
} else { |
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.
I see getSum
method is not part of interface. Can we avoid this multiple if else statement and use reflection to call the getSum
method ?
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.
@dinujoh Thanks for your review. Will update the code accordingly.
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.
@dinujoh Can we please elaborate on that?
try { | ||
failedHttpEndPointResponses = pushToEndPoint(bytes); | ||
} catch (IOException e) { | ||
LOG.info("Error while pushing to the end point"); |
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.
We should add metric when this failure occurs.
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.
@dinujoh Thanks for your review. Will update the code accordingly.
if (failedHttpEndPointResponses != null) { | ||
logFailedData(failedHttpEndPointResponses); | ||
releaseEventHandles(Boolean.FALSE); | ||
} else { |
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 is not true when exception occurs at line 166.
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.
@omkarmmore95 and @mallikagogoi7 Could you please have a look and clarify?
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.
@dinujoh The code has been updated accordingly
final ClassicRequestBuilder classicHttpRequestBuilder = | ||
httpAuthOptions.get(prometheusSinkConfiguration.getUrl()).getClassicHttpRequestBuilder(); | ||
|
||
final byte[] compressedBufferData = Snappy.compress(data); |
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.
Will the data be always Snappy compressed ? Should this be configurable ?
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.
@dinujoh Thanks for your review. Yes, only snappy compression is required to send data to Prometheus.
classicHttpRequestBuilder.addHeader("X-Prometheus-Remote-Write-Version", prometheusSinkConfiguration.getRemoteWriteVersion()); | ||
|
||
try { | ||
if(AuthTypeOptions.BEARER_TOKEN.equals(prometheusSinkConfiguration.getAuthType())) |
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.
How about other Auth support ?
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.
@omkarmmore95 and @mallikagogoi7 Could you please clarify?
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.
@dinujoh , we have unauthenticated, http_basic, and bearer_token auth just like Http Sink plugin
|
||
- `scope` (Optional) : This scope limit an application's access to a user's account. | ||
|
||
- `aws_sigv4`: A boolean flag to sign the HTTP request with AWS credentials. Default to `false`. |
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.
We should use aws:
property for sigv4 and not use aws_
.
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.
@dinujoh Thanks for your review. We are following the other plugins (opensearch, httpsink etc.) key naming conventions to define the aws_sigv4 property.
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.
The new convention is to move away from aws_
for the new sources and sinks.. We should only use aws:
for new sources and sinks.
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.
Resolved
Signed-off-by: mallikagogoi7 <[email protected]>
@dinujoh Above comments has been addressed |
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
|
||
- `scope` (Optional) : This scope limit an application's access to a user's account. | ||
|
||
- `aws_sigv4`: A boolean flag to sign the HTTP request with AWS credentials. Default to `false`. |
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.
The new convention is to move away from aws_
for the new sources and sinks.. We should only use aws:
for new sources and sinks.
|
||
- `url` The http/https endpoint url which can bee backed by prometheus. | ||
|
||
- `encoding` Default is snappy |
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.
Since we don't support any other configuration, this configuration parameter is not adding any value unless we have a followup plan to support another encoding. Can you followup and check what is the plan ?
" url: {0}\n" + | ||
" http_method: POST\n" + | ||
" auth_type: {1}\n" + | ||
" ssl: false\n"; |
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.
How about other configurations for Integration test ?
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.
@dino, Due to less time for this plugin, integration test was not in scope
//TODO: implementation | ||
public void process(final HttpResponse response, final EntityDetails entity, final HttpContext context) throws IOException { | ||
if (response.getCode() != STATUS_CODE_200) { | ||
throw new IOException(String.format("url: %s , status code: %s", url,response.getCode())); |
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.
Why is this IOException ?
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.
@dino, Thanks for review,For failed response we are throwing IOException, and on IOException, we are sending Failed data to DLQ
}catch (Exception e) { | ||
LOG.info("Exception : "+ e.getMessage() ); | ||
} | ||
return bearerTokenOptions.getAccessToken(); |
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 the exception is thrown in line 37, what would be this return value ? Will this cause NPE ?
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.
@dinujoh , Thanks for the review, Resolved
Certificate trustedCa; | ||
trustedCa = factory.generateCertificate(certificate); |
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 can be single line
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.
@dinujoh , Thanks for the review, Resolved
StandardOpenOption.CREATE, StandardOpenOption.APPEND)) { | ||
dlqFileWriter.write(objectWriter.writeValueAsString(failedData)+"\n"); | ||
} catch (IOException e) { | ||
LOG.error("Exception while writing failed data to DLQ file Exception: ",e); |
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.
We should emit metrics on this exception.
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.
@dinujoh , Thanks for the review, Resolved
|
||
dlqWriter.write(Arrays.asList(dlqObject), pluginSetting.getPipelineName(), pluginId); | ||
} catch (final IOException e) { | ||
LOG.error("Exception while writing failed data to DLQ, Exception : ", e); |
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.
Same as above. Emit metric on this exception.
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.
@dinujoh , Thanks for the review, Resolved
if(dlqFile != null) { | ||
this.dlqFile = dlqFile; | ||
this.objectWriter = new ObjectMapper().writer(); | ||
}else{ | ||
this.dlqProvider = getDlqProvider(pluginFactory,bucket,stsRoleArn,awsRegion,dlqPathPrefix); | ||
} |
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.
Can this be injected instead of being constructed here ?
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.
@dinujoh , Thanks for the review, Resolved
} else { | ||
LOG.error("No valid Event type found"); | ||
} | ||
bytes = message.toByteArray(); |
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 will cause NPE if line 171 is executed. No valid event type found.
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.
@dinujoh Thanks for the review, Resolved
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
@@ -12,7 +14,7 @@ jacocoTestCoverageVerification { | |||
violationRules { | |||
rule { | |||
limit { | |||
minimum = 1.0 | |||
minimum = 0.1 |
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 project has 100% coverage and can retain that. Dropping this to 10% will prevent us from ensuring that code coverage exists within the project. We should test the AwsRequestSigningApacheInterceptor
. I believe that a different PR may be doing something similar here.
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.
@dlvenable Resolved
@JsonProperty("encoding") | ||
private String encoding = DEFAULT_ENCODING; | ||
|
||
@JsonProperty("content-type") |
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 project uses underscores for YAML configuration property names. Please change to content_type
.
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.
@dlvenable Resolved
@JsonProperty("content-type") | ||
private String contentType = DEFAULT_CONTENT_TYPE; | ||
|
||
@JsonProperty("remote-write-version") |
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.
Please change to remote_write_version
.
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.
@dlvenable Resolved
@@ -8,10 +8,10 @@ | |||
|
|||
public class AuthenticationOptions { | |||
|
|||
@JsonProperty("http_basic") | |||
@JsonProperty("http-basic") |
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.
Please change this back to http_basic
.
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.
@dlvenable Resolved
private BasicAuthCredentials httpBasic; | ||
|
||
@JsonProperty("bearer_token") | ||
@JsonProperty("bearer-token") |
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.
Please change this back to bearer_token
.
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.
@dlvenable Resolved
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
Signed-off-by: mallikagogoi7 <[email protected]>
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 feature is incomplete, but having the code in the repo would be easier than keeping it in this PR. Somebody could pick up from the merged code.
…rge of PR opensearch-project#3103. Signed-off-by: David Venable <[email protected]>
…rge of PR opensearch-project#3103. Signed-off-by: David Venable <[email protected]>
Cleaning up some unnecessary code and dependencies from the recent merge of PR #3103. Adds missing certificate and key files to fix failures from recent merge of PR #3103. Signed-off-by: David Venable <[email protected]>
Description
Prometheus Sink draft code for issue #1744.
Issues Resolved
#1744
Check List
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.