kong icon indicating copy to clipboard operation
kong copied to clipboard

Bug in proxy-cache plugin not returning age header

Open tobiasehlert opened this issue 3 months ago • 3 comments

Is there an existing issue for this?

  • [X] 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

tobiasehlert avatar Mar 26 '24 21:03 tobiasehlert

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

joelact avatar Mar 28 '24 23:03 joelact

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

tobiasehlert avatar Mar 29 '24 02:03 tobiasehlert

@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 avatar Mar 29 '24 13:03 joelact