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

Bug in proxy-cache plugin not returning age header #12787

Open
1 task done
tobiasehlert opened this issue Mar 26, 2024 · 3 comments · May be fixed by #12812
Open
1 task done

Bug in proxy-cache plugin not returning age header #12787

tobiasehlert opened this issue Mar 26, 2024 · 3 comments · May be fixed by #12812

Comments

@tobiasehlert
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

Kong Enterprise 3.6.1.1

Current Behavior

I have the proxy-cache plugin running (with the response_headers parameters on default) and I do only get back x-cache-status and x-cache-key but not the age header.

By default it should return age and I don't specifically set those values and I also tried to force the age to true but that didn't make any difference.

I checked in both 3.5 (using Kong Gateway in docker) and 3.6.1.1 (using the Kong Gateway Operator in Kubernetes) and it was the same behaviour.

Expected Behavior

I expect a header to be present called age with a number indicating the seconds the request is "old".

Steps To Reproduce

  1. add proxy-cache plugin to a route
  2. run curl command with -v and inspect headers

Anything else?

This is my Kubernetes resource:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: my-cache-1min
  namespace: my-api-v4
config:
  cache_ttl: 60
  content_type:
    - text/plain
    - application/json
    - application/json; charset=utf-8
  request_method:
    - GET
    - HEAD
  response_code:
    - 200
  ignore_uri_case: true
  strategy: memory
plugin: proxy-cache
@joelact
Copy link

joelact commented Mar 28, 2024

Hey @tobiasehlert!

Looking at the documentation for proxy-cache plugin you are missing some configuration parameters on the plugin. It seems that if you want the response to have the Age header you need to enable the following configuration:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: my-cache-1min
  namespace: my-api-v4
config:
  cache_ttl: 60
  content_type:
    - text/plain
    - application/json
    - application/json; charset=utf-8
  request_method:
    - GET
    - HEAD
  response_code:
    - 200
  ignore_uri_case: true
  strategy: memory
  reponse_headers:
    age: true
plugin: proxy-cache

Link to the plugin documentation: https://docs.konghq.com/hub/kong-inc/proxy-cache/

Hope this helps,
Joel

@tobiasehlert
Copy link
Contributor Author

hi @joelact and thanks for your reply, but the issue doesn't lie in that.

When looking in the configuration of the plugin it says that the response_headers section is required, but it has the three components set to true already. So you actually don't need to specify all parameters since it should default to those default parameters when not being specified, except for one.. the config.strategy!

You could actually create the KongPlugin resource by only doing this:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: my-cache-1min
  namespace: my-api-v4
config:
  strategy: memory
plugin: proxy-cache

So yeah.. "required field" flag in the docs doesn't really apply to the KongPlugin part, since the admission webhook (kongplugins.validation.ingress-controller.konghq.com) doesn't actually validate those. Another parameter would be the config.cache_control that is required but has a default and in their own docs (basic example) don't include that either.

But this is not the issue in this case.. it's that the config.response_headers.age parameter is not respected.

Regards,
Tobias

@joelact
Copy link

joelact commented Mar 29, 2024

@tobiasehlert just tested locally. You are right the Age header is not being returned.

I think the schema definition may be the problem. The header does not match the configuration header value.

I will try to submit a PR today with a possible fix so the Kong team can review it ASAP.

@joelact joelact linked a pull request Mar 29, 2024 that will close this issue
3 tasks
joelact added a commit to joelact/kong that referenced this issue Apr 30, 2024
The age parameter on the schema was in lower case which caused
the header Age to appear only when the kong debug option was enabled.
This commit changes the schema parameter from age to Age.

Fix Kong#12787
joelact added a commit to joelact/kong that referenced this issue May 24, 2024
The age parameter on the schema was in lower case which caused
the header Age to appear only when the kong debug option was enabled.
This commit changes the schema parameter from age to Age.

Fix Kong#12787
joelact added a commit to joelact/kong that referenced this issue May 24, 2024
The age parameter on the schema was in lower case which caused
the header Age to appear only when the kong debug option was enabled.
This commit changes the schema parameter from age to Age.

Fix Kong#12787
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 a pull request may close this issue.

2 participants