traefik_correlation

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 4 Imported by: 0

README

About plugin

This plugin allows to generate uuid V4 correlation ID for every request and transmit them to next request. Its allow to send pure correlationId key from client by send header name for this correlation or generate them by plugin with default header correlation-id name.

Configure (default)

...
    correlation:
      headerName: "correlation-id" # default correlation ID header name if client does not sent them
...

If client sent this header name by correlation, then plugin catch this value and transmit them to next

curl -XPOST https://<some domain>/<some api uri> -H 'Correlation-Id: <somw uuid correlation value or another unique value>'

Install

For install this middleware plugin you can configure them like this

Configure traefik-ingress for kubernates

First step is to add experimental plugin

# anywhere/traefik.yml
experimental:
  plugins:
    correlation-id:
      moduleName: github.com/killer-djon/traefik-correlation
      version: v1.3.0

Next step is to add customDefenition for middleware

...
-   apiVersion: traefik.containo.us/v1alpha1
    kind: Middleware
    metadata:
      name: my-traefik-correlation
      namespace: default
    spec:
      plugin:
        correlation-id:
          headerName: "correlation-id" # this is headerName to catch them
...

And as the third step is to add ingress annotation for this middleware (if need to be at single middleware for single service) or set this plugin for avery services as entryPoint (web, websecure ...)

  1. At ingress annotation
...
traefik.ingress.kubernetes.io/router.middlewares: default-my-traefik-correlation@kubernetescrd
  1. At general entrypoint of traefik instance
ports:
  ...
  websecure:
    port: 8443
    expose: true
    exposedPort: 443
    protocol: TCP
    appProtocol: https
    middlewares:
    - default-my-traefik-correlation@kubernetescrd
# in this case you installed plugin will works for every request

Documentation

Index

Constants

View Source
const (
	DEFAULT_HEADER_NAME = "correlation-id"
)

Variables

This section is empty.

Functions

func New

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

New created a new plugin.

Types

type Config

type Config struct {
	HeaderName string `yaml:"headerName,omitempty" json:"header_name,omitempty"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type Correlation

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

func (*Correlation) ServeHTTP

func (c *Correlation) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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