jwalton / kube-auth-proxy

Securely expose your private Kubernetes services.
14 stars 1 forks source link

fix: Fix metrics endpoint response #3

Closed oguzbilgener closed 2 years ago

oguzbilgener commented 2 years ago

Hey Jason,

First of all thanks for keeping this project around. I've been using it on my personal cluster for a while and it fully met my needs. Anything else that's remotely similar is probably much more difficult to set up.

Recently (probably once my cluster pulled the v0.2.0) I noticed that kube-auth-proxy was getting restarted all the time and I saw this in the logs:

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Promise
    at new NodeError (node:internal/errors:371:5)
    at write_ (node:_http_outgoing:742:11)
    at ServerResponse.end (node:_http_outgoing:855:5)
    at /opt/app/dist/metrics.js:44:13
    at Layer.handle [as handle_request] (/opt/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/opt/app/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/opt/app/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/opt/app/node_modules/express/lib/router/layer.js:95:5)
    at /opt/app/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/opt/app/node_modules/express/lib/router/index.js:335:12)

Looks like .metrics() now returns a promise and express' res.end() doesn't like a promise as an argument.

I tried this fix on my cluster and it solves the problem. Prometheus can scrape the metrics endpoint again and I also tried curl-ing it.

Cheers

jwalton commented 2 years ago

Thanks for the fix, sir! I need some better tests for this repo. :P