ResponseTimeBalancer

package module
v1.2.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

Configuration examples

Local file provider

Static config
experimental:
  localPlugins:
    rtb_static:
      moduleName: "github.com/ArtemUgrimov/ResponseTimeBalancer"

Dynamic config
http:
  middlewares:
    rtb:
      plugin:
        rtb_static:
          namespace: "rc"
          serviceName: "bng-server"

K8s

Chart config
experimental:
  plugins:
    rtb_static:
        moduleName: "github.com/ArtemUgrimov/ResponseTimeBalancer"
        version: "v1.0.0"
Middleware
apiVersion: "traefik.io/v1alpha1"
kind: "Middleware"
metadata:
  name: "rtb"
spec:
  plugin:
    rtb_static:
      namespace: "rc"
      serviceName: "bng-server"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New creates a new instance of the middleware It initializes the Kubernetes client to fetch pod information dynamically

Types

type Config

type Config struct {
	KubernetesNamespace string `json:"namespace,omitempty"`
	ServiceName         string `json:"serviceName,omitempty"`
}

func CreateConfig

func CreateConfig() *Config

type K8sBalancer added in v1.2.5

type K8sBalancer struct {
	// contains filtered or unexported fields
}

K8sBalancer is the middleware struct It ensures sticky sessions by routing requests to the same pod using a custom header (pod-id)

func (*K8sBalancer) ServeHTTP added in v1.2.5

func (b *K8sBalancer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP handles the request and selects a pod based on the pod-id header If the pod-id is missing, it picks a random pod and assigns a new pod-id If the pod-id exists but the pod is unavailable, it selects a new one

type K8sClient added in v1.2.5

type K8sClient struct {
	// contains filtered or unexported fields
}

K8sClient interacts with Kubernetes API using HTTP requests.

func NewK8sClient added in v1.2.5

func NewK8sClient(namespace, service string) (*K8sClient, error)

NewK8sClient initializes the Kubernetes client, loads initial pod list, and starts watching changes.

func (*K8sClient) GetPod added in v1.2.5

func (kc *K8sClient) GetPod(podID string) (string, bool)

GetPod returns the IP of a pod by its hash.

func (*K8sClient) GetRandomPod added in v1.2.5

func (kc *K8sClient) GetRandomPod() string

GetRandomPod returns a random pod IP.

type K8sClientInterface added in v1.2.11

type K8sClientInterface interface {
	GetPod(podID string) (string, bool)
	GetRandomPod() string
}

K8sClientInterface defines the contract for Kubernetes client interactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL