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

Added layer for creating and updating the workflow #831

Conversation

stevanbz
Copy link
Contributor

@stevanbz stevanbz commented Mar 14, 2023

Issue #, if available:
#834

Description of changes:
Added transport layer for creating/updating of the workflows and appropriate integration tests

CheckList:
[ ] 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.

@stevanbz stevanbz requested a review from a team March 14, 2023 17:38
@eirsep eirsep requested a review from lezzago March 14, 2023 17:40
@@ -299,6 +299,312 @@
}
}
},
"workflow": {
Copy link
Member

Choose a reason for hiding this comment

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

The schema version at the top needs to be incremented.

}
}
},
"triggers": {
Copy link
Member

Choose a reason for hiding this comment

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

This is not in the workflow object. ref: https://github.com/opensearch-project/common-utils/pull/380/files#diff-bba54255f406156efae1c6e081dd845fa7cd3444b381314a2fb58064cdb0e76d

This also seems like we are storing all the monitor information here and if we create monitors based on the workflows, this doesnt make sense to duplicate the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree. It should be removed.

@@ -15,7 +15,7 @@ dependencies {
implementation "com.cronutils:cron-utils:9.1.6"
api "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
implementation 'com.google.googlejavaformat:google-java-format:1.10.0'
api "org.opensearch:common-utils:${common_utils_version}"
api files("/home/stevan/git/opensearch/repo/common-utils/build/libs/common-utils-2.7.0.0-SNAPSHOT.jar")
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this from the PR. You can keep this locally for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A-ha ok cool - will do. Added in order to be "visible" that we need to merge the common-util first. Tnx

}
}

suspend fun validateRequest(request: IndexWorkflowRequest) {
Copy link
Member

Choose a reason for hiding this comment

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

Should there be another check to make sure there is only 1 input since that is what is being supported here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!

@lezzago
Copy link
Member

lezzago commented Mar 16, 2023

Can you share the integ test runs in here to add confidence on things working?

@stevanbz
Copy link
Contributor Author

stevanbz commented Mar 16, 2023

Can you share the integ test runs in here to add confidence on things working?

I think I added - it's just reduced view because of it's size. Here is the integ-test file


val user = readUserFromThreadContext(client)

if (!validateUserBackendRoles(user, actionListener)) {
Copy link
Member

Choose a reason for hiding this comment

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

can we also validate if the user has EXECUTE permission on the delegate monitors?

}

if (user == null) {
// Security is disabled, add empty user to Monitor. user is null for older versions.
Copy link
Member

Choose a reason for hiding this comment

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

plz write a workflow relevant comment instead

transformedRequest.rbacRoles != null
) {
if (transformedRequest.rbacRoles?.stream()?.anyMatch { !user.backendRoles.contains(it) } == true) {
log.debug(
Copy link
Member

Choose a reason for hiding this comment

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

this is an error log

not debug

// Retry mapping of monitor
onCreateMappingsResponse(true)
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Add error log:
log.error("Failed to create workflow", e)

Copy link
Member

Choose a reason for hiding this comment

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

plz add error log with such messages at every failure/exception

Copy link
Member

@eirsep eirsep left a comment

Choose a reason for hiding this comment

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

plz add error logs at every exception with descriptive message

// Retry mapping of monitor
onCreateMappingsResponse(true)
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

plz add error log with such messages at every failure/exception

prepareWorkflowIndexing()
IndexUtils.scheduledJobIndexUpdated()
} else {
log.info("Create $SCHEDULED_JOBS_INDEX mappings call not acknowledged.")
Copy link
Member

Choose a reason for hiding this comment

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

this is an error log

onUpdateMappingsResponse(response)
}

override fun onFailure(t: Exception) {
Copy link
Member

Choose a reason for hiding this comment

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

Add error log

indexResponse.primaryTerm, request.workflow
)
)
} catch (t: Exception) {
Copy link
Member

Choose a reason for hiding this comment

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

add error log

@stevanbz
Copy link
Contributor Author

Can you share the integ test runs in here to add confidence on things working?

Sorry didn't understood you correctly :) will attach the test results

@stevanbz
Copy link
Contributor Author

actionListener.onResponse(
IndexWorkflowResponse(
indexResponse.id, indexResponse.version, indexResponse.seqNo,
indexResponse.primaryTerm, request.workflow
Copy link
Member

Choose a reason for hiding this comment

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

can we set workflow id in workflow object

Signed-off-by: Stevan Buzejic <[email protected]>
@opensearch-project opensearch-project deleted a comment from stevanbz Mar 21, 2023
@eirsep
Copy link
Member

eirsep commented Mar 21, 2023

#834

Comment on lines 545 to 547
private suspend fun getDelegateMonitors(
monitorIds: MutableList<String>
): List<Monitor> {
Copy link
Member

Choose a reason for hiding this comment

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

We dont check if the user has access to these monitors. We need to also check for the backend roles. Lastly, we need to ensure the users have access to the indices in the monitors for when it tries to execute those monitors.

"monitor_id": {
"type": "keyword"
},
"chained_findings": {
Copy link
Member

Choose a reason for hiding this comment

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

this should be chained_monitor_findings, right?

Copy link
Contributor Author

@stevanbz stevanbz Mar 22, 2023

Choose a reason for hiding this comment

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

Ah... Good catch! Hm... But wrong param naming went on common-util feature branch -> I renamed the property but forgot to rename the property used in a builder:
https://github.com/opensearch-project/common-utils/blob/feature/composite-monitors/src/main/kotlin/org/opensearch/commons/alerting/model/Delegate.kt#L77

So we have inconsistency now in property naming and mapping. What do you suggest? Should I do a change on common-util first and then change the mappings here or? Tnx

Copy link
Member

Choose a reason for hiding this comment

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

Yea lets get both updated. Since these are going into the feature branch, we can do both at the same time.

request.workflow = request.workflow
.copy(user = User(user.name, currentWorkflow.user!!.backendRoles, user.roles, user.customAttNames))
}
log.debug("Update monitor backend roles to: ${request.workflow.user?.backendRoles}")
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: change this to Update workflow instead of Update monitor

@@ -418,7 +418,7 @@
"monitor_id": {
"type": "keyword"
},
"chained_findings": {
"chained_monitor_findings": {
Copy link
Member

Choose a reason for hiding this comment

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

do we need to fix this in common utils for the model also ?

Copy link
Member

Choose a reason for hiding this comment

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

@eirsep eirsep merged commit 8b95195 into opensearch-project:feature/composite-monitors Mar 23, 2023
eirsep pushed a commit to eirsep/alerting that referenced this pull request May 24, 2023
…t#831)

* Renamed chainedFindings to chainedMonitorFindings

* Removed unecessary mappings from workflow definition

* Improved logging when saving the workflows

* Added a workflow id in response

* Added role check and index access once the workflow is being created

* Updated mappings for the workflow

---------

Signed-off-by: Stevan Buzejic <[email protected]>
eirsep pushed a commit to eirsep/alerting that referenced this pull request May 24, 2023
…t#831)

* Renamed chainedFindings to chainedMonitorFindings

* Removed unecessary mappings from workflow definition

* Improved logging when saving the workflows

* Added a workflow id in response

* Added role check and index access once the workflow is being created

* Updated mappings for the workflow

---------

Signed-off-by: Stevan Buzejic <[email protected]>
eirsep pushed a commit to eirsep/alerting that referenced this pull request May 25, 2023
…t#831)

* Renamed chainedFindings to chainedMonitorFindings

* Removed unecessary mappings from workflow definition

* Improved logging when saving the workflows

* Added a workflow id in response

* Added role check and index access once the workflow is being created

* Updated mappings for the workflow

---------

Signed-off-by: Stevan Buzejic <[email protected]>
eirsep pushed a commit to eirsep/alerting that referenced this pull request May 25, 2023
…t#831)

* Renamed chainedFindings to chainedMonitorFindings

* Removed unecessary mappings from workflow definition

* Improved logging when saving the workflows

* Added a workflow id in response

* Added role check and index access once the workflow is being created

* Updated mappings for the workflow

---------

Signed-off-by: Stevan Buzejic <[email protected]>
eirsep added a commit that referenced this pull request May 25, 2023
* Added layer for creating and updating the workflow (#831)

* Renamed chainedFindings to chainedMonitorFindings

* Removed unecessary mappings from workflow definition

* Improved logging when saving the workflows

* Added a workflow id in response

* Added role check and index access once the workflow is being created

* Updated mappings for the workflow

---------

Signed-off-by: Stevan Buzejic <[email protected]>

* Fixed xContent dependencies due to OSCore changes (#839)

Signed-off-by: Angie Zhang <[email protected]>

* Dependency fix (#846)

Signed-off-by: Stevan Buzejic <[email protected]>

* Refactored workflowIndexing validation - removed coroutine and contex… (#857)

* Refactored workflowIndexing validation - removed coroutine and context client context lost

Signed-off-by: Stevan Buzejic <[email protected]>

* refactored getting the workflows

Signed-off-by: Stevan Buzejic <[email protected]>

* Changed the logic according to secure test findings

Signed-off-by: Stevan Buzejic <[email protected]>

* [Backport 2.x] Notification security fix (#861) (#863)

* Notification security fix (#852)

* added injecting whole user object in threadContext before calling notification APIs so that backend roles are available to notification plugin

* compile fix

* refactored user_info injection to use InjectSecurity

* ktlint fix

---------

(cherry picked from commit e0b7a5a)

* remove unneeded import

---------

Signed-off-by: Ashish Agrawal <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Petar Dzepina <[email protected]>
Co-authored-by: Ashish Agrawal <[email protected]>

* Stashed user together with it's roles

Signed-off-by: Stevan Buzejic <[email protected]>

---------

Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Ashish Agrawal <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Petar Dzepina <[email protected]>
Co-authored-by: Ashish Agrawal <[email protected]>

* Added workflow execution logic (#850)

* Added workflow execution logic

Signed-off-by: Stevan Buzejic <[email protected]>

* Adjusted code according to comments

Signed-off-by: Stevan Buzejic <[email protected]>

* Updated version of the findings json

Signed-off-by: Stevan Buzejic <[email protected]>

* Updating the workflow metadata in the case of updating flag set to false while the metadata alerady exist

Signed-off-by: Stevan Buzejic <[email protected]>

* Added logging for workflow metadata update

Signed-off-by: Stevan Buzejic <[email protected]>

* Added Rest Execute Workflow action

Signed-off-by: Stevan Buzejic <[email protected]>

* Extended workflow context with workflowMetadataId. Adjusted the doc level monitor findings

Signed-off-by: Stevan Buzejic <[email protected]>

* Updated conditions for unstashing the context when indexing and deleting the workflow

Signed-off-by: Stevan Buzejic <[email protected]>

---------

Signed-off-by: Stevan Buzejic <[email protected]>

* Added fix when executing the workflow and when chained findings index… (#890)

Signed-off-by: Stevan Buzejic <[email protected]>

* Fixed deleting monitor workflow metadata (#882)

* Fixed deleting monitor metadata and workflow metadata.

Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Surya Sashank Nistala <[email protected]>

* fix monitor metadata error from conflict resolution

Signed-off-by: Surya Sashank Nistala <[email protected]>

* remove unused import

Signed-off-by: Surya Sashank Nistala <[email protected]>

* remove rest execute workflow action

Signed-off-by: Surya Sashank Nistala <[email protected]>

* increment schema version for findings mapping json

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Angie Zhang <[email protected]>
Signed-off-by: Ashish Agrawal <[email protected]>
Signed-off-by: Surya Sashank Nistala <[email protected]>
Co-authored-by: Stevan Buzejic <[email protected]>
Co-authored-by: Angie Zhang <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Petar Dzepina <[email protected]>
Co-authored-by: Ashish Agrawal <[email protected]>
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.

3 participants