UffizziCloud / uffizzi_controller

A smart proxy service that handles requests from the Uffizzi API to the Kubernetes API
Apache License 2.0
11 stars 3 forks source link

[75] add http check for ingress #76

Closed zipofar closed 1 year ago

axisofentropy commented 1 year ago

What we really want is for our redirect page to redirect when or just after when our ingress-nginx load balancer begins forwarding traffic, i.e. when HTTP requests to the load balancer will successfully be forwarded to the tenant's container. When does ingress-nginx make that determination? Can we check the status of the Ingress or containers and achieve this without making our own HTTP requests?

zipofar commented 1 year ago

I think ingress starts forward traffic immediately after we add ingress rule in the namespace. So I guess we can't avoid make http checks. But maybe we can separate ingress-nginx response from tenant's container. Maybe we can add custom header to our ingress-nginx and parse it. Or if that's impossible, we can add custom text to the error body page and parse it. What do you think?

Regarding 500 error. I thought we can't get status lower then 500 from out ingress-nginx because before http check we make tcp checks, therefore 404 and other statuses are impossible in this case. But I forgot that we can have 401 if user use basic auth feature.

How it works now. We make two tcp checks. One for service (to internal ip address like a 10.20.0.7) with public port and one for ingress address (like a pr-4-deployment-168076242045401-hello-world-2.app.qa-gke.uffizzi.com). Then if the previous tcp checks have done we make http check to https://pr-4-deployment-168076242045401-hello-world-2.app.qa-gke.uffizzi.com

axisofentropy commented 1 year ago

Thanks for explaining all that. It's good that you're checking at the load balancer, that serves our goal.

I think nginx itself, within its controller, maintains its own status of each backend, but I don't think that's exposed in a way we can easily access?

You're right that we want to determine whether an error response is coming from our load balancer or the tenant's container. We recently added custom error responses. I think they have some specific HTTP response headers we can check. That will be better than checking the response body, which could change.

axisofentropy commented 1 year ago

Well, it looks like there are no such response headers. Maybe we can add them?

zipofar commented 1 year ago

Looks like we can add custom headers to ingress (doc)

zipofar commented 1 year ago

I've added ConfigMap ingress-nginx-controller-custom-headers.yml

apiVersion: v1
data:
  X-Different-Uffizzi-Name: "true"
  X-Request-Uffizzi-Start: t=${msec}
  X-Using-Nginx-Uffizzi-Controller: "true"
kind: ConfigMap
metadata:
  name: ingress-nginx-controller-custom-headers
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx

And have updated ConfigMap ingress-nginx-for-uffizzi-controller-controller

apiVersion: v1
data:
  allow-snippet-annotations: "true"
  custom-http-errors: 400,401,403,404,502,503,504
  disable-proxy-intercept-errors: "true"
  proxy-body-size: 100m
  proxy-buffer-size: 128k
  add-headers: "ingress-nginx/ingress-nginx-controller-custom-headers" <<<<<<<<<
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: ingress-nginx-for-uffizzi-controller
    meta.helm.sh/release-namespace: ingress-nginx
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx-for-uffizzi-controller
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.7.0
    helm.sh/chart: ingress-nginx-4.6.0
  name: ingress-nginx-for-uffizzi-controller-controller
  namespace: ingress-nginx

And it works

![Screenshot 2023-05-12 at 16 56 44](https://github.com/UffizziCloud/uffizzi_controller/assets/22678201/d5fb0b9f-07c0-43a1-9e2b-c6481014ac09)
zipofar commented 1 year ago

But ingress return these headers always.

![Screenshot 2023-05-12 at 17 01 05](https://github.com/UffizziCloud/uffizzi_controller/assets/22678201/98e1485e-05b3-43c5-a1f6-6cb991b67f36)

Therefore separate response by custom headers does not work

axisofentropy commented 1 year ago

Yeah we want to add them to the "default backend" specifically