-
Notifications
You must be signed in to change notification settings - Fork 105
enhance monitor to store only relevant fields for docs linked to findings #855
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,8 @@ data class Monitor( | |
val dataSources: DataSources = DataSources(), | ||
val deleteQueryIndexInEveryRun: Boolean? = false, | ||
val shouldCreateSingleAlertForFindings: Boolean? = false, | ||
val owner: String? = "alerting" | ||
val owner: String? = "alerting", | ||
val metadataForFindings: List<String>? = listOf() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metadataForFindings -> contextFields? findingFields? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. java doc |
||
) : ScheduledJob { | ||
|
||
override val type = MONITOR_TYPE | ||
|
@@ -123,7 +124,8 @@ data class Monitor( | |
} else { | ||
false | ||
}, | ||
owner = sin.readOptionalString() | ||
owner = sin.readOptionalString(), | ||
metadataForFindings = sin.readOptionalStringList() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz add version awareness to avoid serde issues |
||
) | ||
|
||
// This enum classifies different Monitors | ||
|
@@ -185,6 +187,7 @@ data class Monitor( | |
builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun) | ||
builder.field(SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD, shouldCreateSingleAlertForFindings) | ||
builder.field(OWNER_FIELD, owner) | ||
builder.field(METADATA_FOR_FINDINGS_FIELD, metadataForFindings) | ||
if (params.paramAsBoolean("with_type", false)) builder.endObject() | ||
return builder.endObject() | ||
} | ||
|
@@ -242,6 +245,7 @@ data class Monitor( | |
out.writeOptionalBoolean(shouldCreateSingleAlertForFindings) | ||
} | ||
out.writeOptionalString(owner) | ||
out.writeOptionalStringCollection(metadataForFindings) | ||
} | ||
|
||
companion object { | ||
|
@@ -264,6 +268,7 @@ data class Monitor( | |
const val DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD = "delete_query_index_in_every_run" | ||
const val SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD = "should_create_single_alert_for_findings" | ||
const val OWNER_FIELD = "owner" | ||
const val METADATA_FOR_FINDINGS_FIELD = "metadata_for_findings" | ||
val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}") | ||
|
||
// This is defined here instead of in ScheduledJob to avoid having the ScheduledJob class know about all | ||
|
@@ -294,6 +299,7 @@ data class Monitor( | |
var deleteQueryIndexInEveryRun = false | ||
var delegateMonitor = false | ||
var owner = "alerting" | ||
var metadataForFindings: MutableList<String> = mutableListOf() | ||
|
||
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) | ||
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { | ||
|
@@ -357,6 +363,17 @@ data class Monitor( | |
xcp.booleanValue() | ||
} | ||
OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text() | ||
METADATA_FOR_FINDINGS_FIELD -> { | ||
XContentParserUtils.ensureExpectedToken( | ||
XContentParser.Token.START_ARRAY, | ||
xcp.currentToken(), | ||
xcp | ||
) | ||
|
||
while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { | ||
metadataForFindings.add(xcp.text()) | ||
} | ||
} | ||
else -> { | ||
xcp.skipChildren() | ||
} | ||
|
@@ -385,7 +402,8 @@ data class Monitor( | |
dataSources, | ||
deleteQueryIndexInEveryRun, | ||
delegateMonitor, | ||
owner | ||
owner, | ||
metadataForFindings | ||
) | ||
} | ||
|
||
|
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.
javadocs plz
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.
plz add version awareness to avoid serde issues