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

[Backport 2.x] Added validation for the new clusters field. (#633) #636

Merged
merged 2 commits into from
Apr 13, 2024

Conversation

AWSHurneyt
Copy link
Collaborator

@AWSHurneyt AWSHurneyt commented Apr 12, 2024

Description

Manual cherry-pick of PR #633

Issues Resolved

[List any issues this PR will resolve]

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.

* Added validation for the clusters field. Refactored ClusterMetricsInput validiation to throw 4xx-level CommonUtilsExceptions instead of 5xx-level IllegalArgumentException.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved some regex from alerting plugin to common utils.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved cluster-based regex to separate file.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed ktlint error.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed regex. Moved cluster-related regexes.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
engechas
engechas previously approved these changes Apr 12, 2024
eirsep
eirsep previously approved these changes Apr 12, 2024
clusterMetricType = findApiType(constructedUri.path)
this.parseEmptyFields()
} catch (exception: Exception) {
throw CommonUtilsException.wrap(exception)
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

Copy link
Member

Choose a reason for hiding this comment

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

why are we creating a common utils exception?
The plugin using common utils can handle the exception and wrap it as necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed CommonUtilsException in PR #639. Will cherry-pick that commit once that PR is merged.


private val log = LogManager.getLogger(CommonUtilsException::class.java)

class CommonUtilsException(message: String, val status: RestStatus, ex: Exception) : OpenSearchException(message, ex) {
Copy link
Member

Choose a reason for hiding this comment

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

what benefit are we getting from removing the delegation of execption handling to the plugin? there is no business logic in common utils
why should we have to throw a common utils exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed CommonUtilsException in PR #639. Will cherry-pick that commit once that PR is merged.

* question marks, double quotes, less than or greater than signs, pipes, colons, or periods.
* The length of the index must be between 1 and 255 characters
*/
val VALID_INDEX_NAME_REGEX = Regex("""^(?![_\-\+])(?!.*\.\.)[^\s,\\\/\*\?"<>|#:\.]{1,255}$""")
Copy link
Member

Choose a reason for hiding this comment

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

why aren't we using opensearch core's index name validation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was just moved to common utils from alerting; it wasn't implemented as part of these changes. Core didn't have a regex for index names. This comment explains where the validation came from https://github.com/opensearch-project/alerting/pull/992/files#r1259175796

* The sequences of characters can include lowercase letters, uppercase letters, digits, underscores, or hyphens
* The total length of the string can range from 1 to 255 characters
*/
val CLUSTER_NAME_REGEX = Regex("^(?=.{1,255}$)[a-z0-9]([a-zA-Z0-9_-]*:?[a-zA-Z0-9_-]*)$")
Copy link
Member

Choose a reason for hiding this comment

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

why are we not re-using cross cluster validation from core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussed this in this comment
#633 (comment)

…should be caught in the plugins themselves.

Signed-off-by: AWSHurneyt <[email protected]>
@AWSHurneyt AWSHurneyt dismissed stale reviews from eirsep and engechas via ab6db13 April 13, 2024 01:11
@eirsep eirsep merged commit 4e81d64 into opensearch-project:2.x Apr 13, 2024
9 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2024
)

* Added validation for the new clusters field. (#633)

* Added validation for the clusters field. Refactored ClusterMetricsInput validiation to throw 4xx-level CommonUtilsExceptions instead of 5xx-level IllegalArgumentException.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved some regex from alerting plugin to common utils.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved cluster-based regex to separate file.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed ktlint error.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed regex. Moved cluster-related regexes.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>

* Removed CommonUtilsException. Team decided IllegalArgumentExceptions should be caught in the plugins themselves.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
(cherry picked from commit 4e81d64)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2024
)

* Added validation for the new clusters field. (#633)

* Added validation for the clusters field. Refactored ClusterMetricsInput validiation to throw 4xx-level CommonUtilsExceptions instead of 5xx-level IllegalArgumentException.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved some regex from alerting plugin to common utils.

Signed-off-by: AWSHurneyt <[email protected]>

* Moved cluster-based regex to separate file.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed ktlint error.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed regex. Moved cluster-related regexes.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>

* Removed CommonUtilsException. Team decided IllegalArgumentExceptions should be caught in the plugins themselves.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
(cherry picked from commit 4e81d64)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
AWSHurneyt pushed a commit that referenced this pull request Apr 13, 2024
) (#641)

* Added validation for the new clusters field. (#633)

* Added validation for the clusters field. Refactored ClusterMetricsInput validiation to throw 4xx-level CommonUtilsExceptions instead of 5xx-level IllegalArgumentException.



* Moved some regex from alerting plugin to common utils.



* Moved cluster-based regex to separate file.



* Fixed ktlint error.



* Fixed regex. Moved cluster-related regexes.



---------



* Removed CommonUtilsException. Team decided IllegalArgumentExceptions should be caught in the plugins themselves.



---------


(cherry picked from commit 4e81d64)

Signed-off-by: AWSHurneyt <[email protected]>
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.

4 participants