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

Allow for "within" or "not within" style asserts #3205

Open
abangser opened this issue Oct 3, 2023 · 1 comment
Open

Allow for "within" or "not within" style asserts #3205

abangser opened this issue Oct 3, 2023 · 1 comment
Labels
enhancement New feature or request user-request

Comments

@abangser
Copy link
Contributor

abangser commented Oct 3, 2023

Describe the enhancement you'd like to see
I would like to see an assertion that checks if the value is within (or not within) an array of provided values.

Additional context
Right now there are a number of comparisons I can do in the assert including equality, greater/less than, and regex compare. However, some lower cardinality data may have hard to regex values while having a set number of acceptable responses.

In a super ideal world this would be possible in the span selectors too! But that may be another enhancement request 😁

@abangser abangser added enhancement New feature or request triage requires triage labels Oct 3, 2023
@mathnogueira
Copy link
Contributor

mathnogueira commented Oct 3, 2023

Hey @abangser!

You can assert if an array contains a value. We don't support the not operator yet. But I think I can add support for it quickly:

When the left side of an operation is an array, you can use the contains operator to check if a specific value is contained in it:

[31,35,39] contains 35
// returns true

[31,35,39] contains 42
// returns false

If your array is in json format, you can use the json_path filter to transform it into a simple array:

// input.json
{
  "array": [
    {
      "name": "john",
      "company": "X"
    },
    {
      "name": "alice",
      "company": "Y"
    }
  ]
}
attr:json_input | json_path '$.array[*].name' contains "alice"
// returns true

Does this solve your problem?

@mathnogueira mathnogueira removed the triage requires triage label Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user-request
Projects
None yet
Development

No branches or pull requests

2 participants