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

feat(aci): error detector #82533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Dec 23, 2024

Basically the same thing as #81950 sans migration

Adds the following for error detectors:

  • Config schema (must have empty dict)
  • Class variable with project options (only used for errors)
  • Updated serializer to account for error detector project options and put them in config
  • Error detector validator

Missing:

  • Attaching validator to ErrorGrouptype. This will require moving a lot of imports, so saving for another PR.
  • Using the error detector for fingerprinting rules and auto resolve duration

For ACI-28

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 23, 2024
try:
FingerprintingRules.from_config_string(value)
except InvalidFingerprintingConfig as e:
raise serializers.ValidationError(str(e))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 4 days ago

To fix the problem, we should avoid exposing the detailed exception message to the end user. Instead, we can log the detailed exception message on the server for debugging purposes and raise a generic ValidationError message to the user. This approach ensures that sensitive information is not exposed while still allowing developers to diagnose issues.

  • Modify the validate_fingerprinting_rules method to log the exception message and raise a generic error message.
  • Add necessary imports for logging if not already present.
Suggested changeset 1
src/sentry/workflow_engine/endpoints/validators/error_detector.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/workflow_engine/endpoints/validators/error_detector.py b/src/sentry/workflow_engine/endpoints/validators/error_detector.py
--- a/src/sentry/workflow_engine/endpoints/validators/error_detector.py
+++ b/src/sentry/workflow_engine/endpoints/validators/error_detector.py
@@ -9,2 +9,5 @@
 
+import logging
+
+logger = logging.getLogger(__name__)
 
@@ -25,3 +28,4 @@
         except InvalidFingerprintingConfig as e:
-            raise serializers.ValidationError(str(e))
+            logger.error(f"Invalid fingerprinting config: {e}")
+            raise serializers.ValidationError("Invalid fingerprinting configuration provided.")
 
EOF
@@ -9,2 +9,5 @@

import logging

logger = logging.getLogger(__name__)

@@ -25,3 +28,4 @@
except InvalidFingerprintingConfig as e:
raise serializers.ValidationError(str(e))
logger.error(f"Invalid fingerprinting config: {e}")
raise serializers.ValidationError("Invalid fingerprinting configuration provided.")

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 71.69811% with 15 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...flow_engine/endpoints/validators/error_detector.py 68.75% 10 Missing ⚠️
src/sentry/workflow_engine/models/detector.py 50.00% 3 Missing ⚠️
...rc/sentry/workflow_engine/endpoints/serializers.py 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #82533      +/-   ##
==========================================
- Coverage   80.43%   80.43%   -0.01%     
==========================================
  Files        7319     7320       +1     
  Lines      322657   322709      +52     
  Branches    21048    21048              
==========================================
+ Hits       259529   259567      +38     
- Misses      62721    62735      +14     
  Partials      407      407              

@cathteng cathteng marked this pull request as ready for review December 23, 2024 17:05
@cathteng cathteng requested review from a team as code owners December 23, 2024 17:06
@cathteng cathteng requested a review from a team December 23, 2024 17:06
@@ -126,11 +128,30 @@ def get_attrs(
for group, serialized in zip(condition_groups, serialize(condition_groups, user=user))
}

filtered_item_list = [item for item in item_list if item.type == ErrorGroupType.slug]
project_ids = [item.project_id for item in filtered_item_list]
Copy link
Member

Choose a reason for hiding this comment

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

the ids are guaranteed to be unique b/c 1 error detector per project right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but that is a good point.

if item.id in configs:
attrs[item]["config"] = configs[item.id]
else:
attrs[item]["config"] = item.config
Copy link
Member

Choose a reason for hiding this comment

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

for all other detectors, will this just be empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's possible, but it will have whatever shape defined by detector_config_schema for the group type

detector_config_schema = {"type": "object", "additionalProperties": False} # empty schema

Copy link
Member Author

Choose a reason for hiding this comment

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

^ as an example. but for the error detector i'm overwriting it since i'm not migrating the project options rn

@iamrajjoshi iamrajjoshi requested a review from a team December 23, 2024 18:09
**kwargs,
) -> Detector:
if name is None:
name = petname.generate(2, " ", letters=10).title()
if config is None:
config = {}
Copy link
Member Author

Choose a reason for hiding this comment

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

need to explicitly set this as a dictionary, the receiver does not think the Django db_default={} is the same as {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants