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

ref(py): Rename sampling to rule condition #2720

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Validate span timestamps and IDs in light normalization on renormalization. ([#2679](https://github.com/getsentry/relay/pull/2679))
- Rename `validate_sampling_condition` to `validate_rule_condition`. ([#2720](https://github.com/getsentry/relay/pull/2720))

## 0.8.35

Expand Down
16 changes: 13 additions & 3 deletions py/sentry_relay/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"pii_strip_event",
"pii_selector_suggestions_from_event",
"VALID_PLATFORMS",
"validate_rule_condition",
"validate_sampling_condition",
"validate_sampling_configuration",
"validate_project_config",
Expand Down Expand Up @@ -237,11 +238,20 @@ def compare_version(a, b):

def validate_sampling_condition(condition):
"""
Validate a dynamic rule condition. Used in dynamic sampling serializer.
The parameter is a string containing the rule condition as JSON.
Deprecated legacy alias. Please use ``validate_rule_condition`` instead.
"""
return validate_rule_condition(condition)


def validate_rule_condition(condition):
"""
Validate a dynamic rule condition. Used by dynamic sampling, metric extraction, and metric
tagging.

:param condition: A string containing the condition encoded as JSON.
"""
assert isinstance(condition, str)
raw_error = rustcall(lib.relay_validate_sampling_condition, encode_str(condition))
raw_error = rustcall(lib.relay_validate_rule_condition, encode_str(condition))
error = decode_str(raw_error, free=True)
if error:
raise ValueError(error)
Expand Down
7 changes: 3 additions & 4 deletions py/tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ def compare_versions():
assert sentry_relay.compare_versions("1.0.0", "1.0") == -1


def test_validate_sampling_condition():
def test_validate_rule_condition():
"""
Test that a valid condition passes
"""
# Should not throw
condition = '{"op": "eq", "name": "field_2", "value": ["UPPER", "lower"]}'
sentry_relay.validate_sampling_condition(condition)
sentry_relay.validate_rule_condition(condition)


def test_invalid_sampling_condition():
Expand All @@ -245,8 +245,7 @@ def test_invalid_sampling_condition():
# Should throw
condition = '{"op": "legacyBrowser", "value": [1,2,3]}'
with pytest.raises(ValueError):

sentry_relay.validate_sampling_condition(condition)
sentry_relay.validate_rule_condition(condition)


def test_validate_sampling_configuration():
Expand Down
6 changes: 4 additions & 2 deletions relay-cabi/include/relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ int32_t relay_compare_versions(const struct RelayStr *a,
const struct RelayStr *b);

/**
* Validate a sampling rule condition.
* Validate a dynamic rule condition.
*
* Used by dynamic sampling, metric extraction, and metric tagging.
*/
struct RelayStr relay_validate_sampling_condition(const struct RelayStr *value);
struct RelayStr relay_validate_rule_condition(const struct RelayStr *value);

/**
* Validate whole rule ( this will be also implemented in Sentry for better error messages)
Expand Down
6 changes: 4 additions & 2 deletions relay-cabi/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ pub unsafe extern "C" fn relay_compare_versions(a: *const RelayStr, b: *const Re
}
}

/// Validate a sampling rule condition.
/// Validate a dynamic rule condition.
///
/// Used by dynamic sampling, metric extraction, and metric tagging.
#[no_mangle]
#[relay_ffi::catch_unwind]
pub unsafe extern "C" fn relay_validate_sampling_condition(value: *const RelayStr) -> RelayStr {
pub unsafe extern "C" fn relay_validate_rule_condition(value: *const RelayStr) -> RelayStr {
let ret_val = match serde_json::from_str::<RuleCondition>((*value).as_str()) {
Ok(condition) => {
if condition.supported() {
Expand Down
Loading