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

limiter: support queryMatch #281

Merged
merged 1 commit into from
Feb 3, 2023
Merged

limiter: support queryMatch #281

merged 1 commit into from
Feb 3, 2023

Conversation

MouceL
Copy link
Contributor

@MouceL MouceL commented Feb 2, 2023

if request contains header foo:bar and contains parameters key1=value1 key2=value2

limit rule is 2 times/10s

use useQueryMatch: true to specify queryMatch

apiVersion: microservice.slime.io/v1alpha2
kind: SmartLimiter
metadata:
  name: productpage
  namespace: default
spec:
  sets:
    _base:
      descriptor:
      - action:
          fill_interval:
            seconds: 10
          quota: "2"
          strategy: "single"
        condition: "true"
        target:
          port: 9080
        match:
        - name: foo
          exact_match: bar
        - name: key1
          exact_match: value1
          useQueryMatch: true
        - name: key2
          exact_match: value2
          useQueryMatch: true

==> result

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  creationTimestamp: "2023-02-02T08:30:01Z"
  generation: 1
  name: productpage.default.ratelimit
  namespace: default
  ownerReferences:
  - apiVersion: microservice.slime.io/v1alpha2
    blockOwnerDeletion: true
    controller: true
    kind: SmartLimiter
    name: productpage
    uid: 07e18655-863b-4f0d-847a-19a0e017a040
  resourceVersion: "9298561"
  uid: 086c5e5c-1c89-42bb-b5f4-99552a04de80
spec:
  configPatches:
  - applyTo: HTTP_ROUTE
    match:
      context: SIDECAR_INBOUND
      routeConfiguration:
        vhost:
          name: inbound|http|9080
          route:
            name: default
    patch:
      operation: MERGE
      value:
        route:
          rate_limits:
          - actions:
            - query_parameter_value_match:
                descriptor_value: Service[productpage.default]-Id[3209452642]
                query_parameters:
                - name: key1
                  string_match:
                    exact: value1
                - name: key2
                  string_match:
                    exact: value2
            - header_value_match:
                descriptor_value: Service[productpage.default]-Id[3209452642]
                headers:
                - exact_match: bar
                  name: foo
  - applyTo: HTTP_FILTER
    match:
      context: SIDECAR_INBOUND
      listener:
        filterChain:
          filter:
            name: envoy.filters.network.http_connection_manager
            subFilter:
              name: envoy.filters.http.router
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.filters.http.local_ratelimit
        typed_config:
          '@type': type.googleapis.com/udpa.type.v1.TypedStruct
          type_url: type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
          value:
            stat_prefix: http_local_rate_limiter
  - applyTo: HTTP_ROUTE
    match:
      context: SIDECAR_INBOUND
      routeConfiguration:
        vhost:
          name: inbound|http|9080
          route:
            name: default
    patch:
      operation: MERGE
      value:
        typed_per_filter_config:
          envoy.filters.http.local_ratelimit:
            '@type': type.googleapis.com/udpa.type.v1.TypedStruct
            type_url: type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
            value:
              descriptors:
              - entries:
                - key: query_match
                  value: Service[productpage.default]-Id[3209452642]
                - key: header_match
                  value: Service[productpage.default]-Id[3209452642]
                token_bucket:
                  fill_interval:
                    seconds: "10"
                  max_tokens: 2
                  tokens_per_fill:
                    value: 2
              filter_enabled:
                default_value:
                  numerator: 100
                runtime_key: local_rate_limit_enabled
              filter_enforced:
                default_value:
                  numerator: 100
                runtime_key: local_rate_limit_enforced
              stat_prefix: http_local_rate_limiter
              token_bucket:
                fill_interval:
                  seconds: "1"
                max_tokens: 100000
                tokens_per_fill:
                  value: 100000
  workloadSelector:
    labels:
      app: productpage

@YonkaFang
Copy link
Contributor

注意一下:

  1. 这个新字段的使用,可能导致对istio版本兼容性的收窄。 如某版本以下的istio(用的envoy和go-control-plane)不支持该字段,则会报错。 这点至少要说明一下

  2. 为了支持这个新字段,就当前实现来说要升级slime go-control-plane版本,但不一定要这么高v0.11。 至少我看到istio 1.12(的go-control-plane v0.10.2)就支持了该字段;

@MouceL
Copy link
Contributor Author

MouceL commented Feb 6, 2023

注意一下:

  1. 这个新字段的使用,可能导致对istio版本兼容性的收窄。 如某版本以下的istio(用的envoy和go-control-plane)不支持该字段,则会报错。 这点至少要说明一下
  2. 为了支持这个新字段,就当前实现来说要升级slime go-control-plane版本,但不一定要这么高v0.11。 至少我看到istio 1.12(的go-control-plane v0.10.2)就支持了该字段;

也使用了https://github.com/envoyproxy/go-control-plane/blob/fd73e3e0fadcc4c69759e862fa3ff48bb92ee633/envoy/config/route/v3/route_components.pb.go#L5581

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.

2 participants