Skip to content
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

CorrelationAlert model added #631

Merged

Conversation

riysaxen-amzn
Copy link
Collaborator

@riysaxen-amzn riysaxen-amzn commented Apr 9, 2024

Description

  • Creates a model class for GenericAlert i.e BaseAlert class which can be extended later on by monitor based alerts
  • Creates a model class for CorrelationAlert which extends BaseAlert class
  • Tests added to support CorrelationAlerts

Issues Resolved

Alerts in Correlations

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --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.

Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
@riysaxen-amzn riysaxen-amzn requested a review from eirsep May 17, 2024 00:16

init {
if (errorMessage != null) {
require((state == Alert.State.DELETED) || (state == Alert.State.ERROR) || (state == Alert.State.AUDIT)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why would alert state Deleted mandate a non-null error message

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah this one's in Alert state class also, so eventually Monitor based Alert (i.e Alert class) will also extend this BaseClass, therefore.

}
}

val unifiedAlert = parse(xcp, version)
Copy link
Member

Choose a reason for hiding this comment

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

Which parse() method is called? Recursive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, so in this case, the parse function of CorrelationAlert is utilizing the parse function of its superclass BaseAlert to handle the parsing of fields common to both types of alerts. Then, it proceeds to parse the additional fields specific to CorrelationAlert

@riysaxen-amzn riysaxen-amzn requested a review from eirsep May 17, 2024 17:21
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, but here src/test/kotlin/org/opensearch/commons/alerting/CorrelationAlertTests.kt in test correlation parse function we are validating such scenarios

@@ -16,7 +17,11 @@ import java.io.ByteArrayOutputStream
fun getJsonString(xContent: ToXContent): String {
ByteArrayOutputStream().use { byteArrayOutputStream ->
val builder = XContentFactory.jsonBuilder(byteArrayOutputStream)
xContent.toXContent(builder, ToXContent.EMPTY_PARAMS)
if (xContent is CorrelationAlert) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this change? because this is not part of alerting package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah I'm using getJsonString method to convert correlation alert Json into string on line 87 in src/test/kotlin/org/opensearch/commons/alerting/CorrelationAlertTests.kt therefore changed this to make it work for CorrelationAlert

@riysaxen-amzn riysaxen-amzn requested a review from sbcd90 May 21, 2024 18:08
@riysaxen-amzn riysaxen-amzn merged commit e060f5e into opensearch-project:main May 21, 2024
9 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 11, 2024
* CorrelationALert model added

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fix klint errors

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* address the comments

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

* fix klint errors

Signed-off-by: Riya Saxena <riysaxen@amazon.com>

---------

Signed-off-by: Riya Saxena <riysaxen@amazon.com>
(cherry picked from commit e060f5e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
riysaxen-amzn pushed a commit that referenced this pull request Jun 11, 2024
* CorrelationALert model added



* fix klint errors



* address the comments



* fix klint errors



---------


(cherry picked from commit e060f5e)

Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants