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

Fix return value when host property does not exist from data.selector #39

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

eguzki
Copy link
Contributor

@eguzki eguzki commented Aug 22, 2023

What

Selectors in rules[].data.selector[] have a default named attribute to cover the use case where the property does not exist https://github.com/Kuadrant/wasm-shim/blob/main/src/configuration.rs#L7-L20

pub struct SelectorItem {
    // Selector of an attribute from the contextual properties provided by kuadrant
    // during request and connection processing
    pub selector: String,

    // If not set it defaults to `selector` field value as the descriptor key.
    #[serde(default)]
    pub key: Option<String>,

    // An optional value to use if the selector is not found in the context.
    // If not set and the selector is not found in the context, then no data is generated.
    #[serde(default)]
    pub default: Option<String>,
}

When the selector property does not exist, the behavior is ruled by the default field. Currently the implementation was enforcing a default value (empty string "") defeating the purpose of the default attribute.

Verification Steps

  • Run development env
make development

The wasm configuration applied for *.a.com is

{
                              "name": "rlp-ns-A/rlp-name-A",
                              "domain": "rlp-ns-A/rlp-name-A",
                              "service": "limitador",
                              "hostnames": ["*.a.com"],
                              "rules": [
                                {
                                  "data": [
                                    {
                                      "selector": {
                                        "selector": "unknown.path"
                                      }
                                    }
                                  ]
                                }
                              ]
                            }
  • Run request
curl -H "Host: test.a.com" http://127.0.0.1:18000/get

Data selector should not generate return any value. Thus, descriptor should be empty and rate limiting service should not be called. Logs should not show any log from the limitador service or GRPC client.

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
@eguzki eguzki requested a review from alexsnaps August 22, 2023 13:11
Cargo.toml Outdated
@@ -26,7 +26,7 @@ regex = "1"
radix_trie = "0.2.1"

[dev-dependencies]
proxy-wasm-test-framework = { git = "https://github.com/Kuadrant/wasm-test-framework.git", branch = "kuadrant" }
proxy-wasm-test-framework = { git = "https://github.com/Kuadrant/wasm-test-framework.git", branch = "fix-get-property-when-none" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change will be reverted, only used for testing Kuadrant/wasm-test-framework#2

@eguzki
Copy link
Contributor Author

eguzki commented Aug 22, 2023

requires Kuadrant/wasm-test-framework#2

@eguzki eguzki marked this pull request as ready for review August 30, 2023 14:22
@eguzki
Copy link
Contributor Author

eguzki commented Aug 30, 2023

ready for review @alexsnaps

@eguzki eguzki mentioned this pull request Aug 30, 2023
3 tasks
@eguzki eguzki requested a review from a team September 14, 2023 08:47
Copy link
Member

@alexsnaps alexsnaps left a comment

Choose a reason for hiding this comment

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

So sorry @eguzki - I had like 3 tabs open with this PR 🤦

@eguzki eguzki merged commit 1c8ea02 into main Sep 14, 2023
9 checks passed
@eguzki eguzki deleted the fix-not-existing-property branch September 14, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants