krakend

package module
v0.0.0-...-a49728a Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 61 Imported by: 0

README

Krakend logo

KrakenD

KrakenD is an extensible, ultra-high performance API Gateway that helps you effortlessly adopt microservices and secure communications. KrakenD is easy to operate and run and scales out without a single point of failure.

KrakenD Community Edition (or KrakenD-CE) is the open-source distribution of KrakenD.

KrakenD Site | Documentation | Blog | Twitter | Downloads

Benefits

  • Easy integration of an ultra-high performance gateway.
  • Effortlessly transition to microservices and Backend For Frontend implementations.
  • True linear scalability: Thanks to its stateless design, every KrakenD node can operate independently in the cluster without any coordination or centralized persistence.
  • Low operational cost: +70K reqs/s on a single instance of regular size. Super low memory consumption with high traffic (usually under 50MB w/ +1000 concurrent). Fewer machines. Smaller machines. Lower budget.
  • Platform-agnostic. Whether you work in a Cloud-native environment (e.g., Kubernetes) or self-hosted on-premises.
  • No vendor lock-in: Reuse the best existing open-source and proprietary tools rather than having everything in the gateway (telemetry, identity providers, etc.)
  • API Lifecycle: Using GitOps and declarative configuration.
  • Decouple clients from existing services. Create new APIs without changing your existing API contracts.

Technical features

  • Content aggregation, composition, and filtering: Create views and mashups of aggregated content from your APIs.
  • Content Manipulation and format transformation: Change responses, convert transparently from XML to JSON, and vice-versa.
  • Security:: Zero-trust policy, CORS, OAuth, JWT, HSTS, clickjacking protection, HPKP, MIME-Sniffing prevention, XSS protection...
  • Concurrent calls: Serve content faster than consuming backends directly.
  • SSL and HTTP2 ready
  • Throttling: Limits of usage in the router and proxy layers
  • Multi-layer rate-limiting for the end-user and between KrakenD and your services, including bursting, load balancing, and circuit breaker.
  • Telemetry and dashboards of all sorts: Datadog, Zipkin, Jaeger, Prometheus, Grafana...
  • Extensible with Go plugins, Lua scripts, Martian, or Google CEL spec.

See the website for more information.

Download

KrakenD is packaged and distributed in several formats. You don't need to clone this repo to use KrakenD unless you want to tweak and build the binary yourself.

Run

In its simplest form with Docker:

docker run -it -p "8080:8080" devopsfaith/krakend

Now see http://localhost:8080/__health. The gateway is listening. Now CTRL-C and replace /etc/krakend/krakend.json with your first configuration.

Build

See the required Go version in the Makefile, and then:

make build

Or, if you don't have or don't want to install go, you can build it using the golang docker container:

make docker_build

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPlugins

func LoadPlugins(folder, pattern string, logger logging.Logger)

LoadPlugins loads and registers the plugins so they can be used if enabled at the configuration

func NewBackendFactory

func NewBackendFactory(logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory

NewBackendFactory creates a BackendFactory by stacking all the available middlewares: - oauth2 client credentials - http cache - martian - pubsub - amqp - cel - lua - rate-limit - circuit breaker - metrics collector - opencensus collector

func NewBackendFactoryWithContext

func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory

NewBackendFactory creates a BackendFactory by stacking all the available middlewares and injecting the received context

func NewEngine

func NewEngine(cfg config.ServiceConfig, opt luragin.EngineOptions) *gin.Engine

NewEngine creates a new gin engine with some default values and a secure middleware

func NewExecutor

func NewExecutor(ctx context.Context) cmd.Executor

NewExecutor returns an executor for the cmd package. The executor initalizes the entire gateway by registering the components and composing a RouterFactory wrapping all the middlewares.

func NewHandlerFactory

func NewHandlerFactory(logger logging.Logger, metricCollector *metrics.Metrics, rejecter jose.RejecterFactory) router.HandlerFactory

NewHandlerFactory returns a HandlerFactory with a rate-limit and a metrics collector middleware injected

func NewProxyFactory

func NewProxyFactory(logger logging.Logger, backendFactory proxy.BackendFactory, metricCollector *metrics.Metrics) proxy.Factory

NewProxyFactory returns a new ProxyFactory wrapping the injected BackendFactory with the default proxy stack and a metrics collector

func RegisterEncoders

func RegisterEncoders()

RegisterEncoders registers all the available encoders

func RegisterSubscriberFactories

func RegisterSubscriberFactories(ctx context.Context, cfg config.ServiceConfig, logger logging.Logger) func(n string, p int)

RegisterSubscriberFactories registers all the available sd adaptors

Types

type AgentStarter

type AgentStarter interface {
	Start(
		context.Context,
		[]*config.AsyncAgent,
		logging.Logger,
		chan<- string,
		proxy.Factory,
	) func() error
}

AgentStarter defines a type that starts a set of agents

type BackendFactory

type BackendFactory interface {
	NewBackendFactory(context.Context, logging.Logger, *metrics.Metrics) proxy.BackendFactory
}

BackendFactory returns a KrakenD backend factory, ready to be passed to the KrakenD proxy factory

type BloomFilterJWT

type BloomFilterJWT struct{}

BloomFilterJWT is the default TokenRejecterFactory implementation.

func (BloomFilterJWT) NewTokenRejecter

func (t BloomFilterJWT) NewTokenRejecter(ctx context.Context, cfg config.ServiceConfig, l logging.Logger, reg func(n string, p int)) (jose.ChainedRejecterFactory, error)

NewTokenRejecter registers the bloomfilter component and links it to a token rejecter. Then it returns a chained rejecter factory with the created token rejecter and other based on the CEL component.

type DefaultRunServerFactory

type DefaultRunServerFactory struct{}

DefaultRunServerFactory creates the default RunServer by wrapping the injected RunServer with the plugin loader and the CORS module

func (*DefaultRunServerFactory) NewRunServer

type EngineFactory

type EngineFactory interface {
	NewEngine(config.ServiceConfig, router.EngineOptions) *gin.Engine
}

EngineFactory returns a gin engine, ready to be passed to the KrakenD RouterFactory

type ExecutorBuilder

type ExecutorBuilder struct {
	LoggerFactory               LoggerFactory
	PluginLoader                PluginLoader
	SubscriberFactoriesRegister SubscriberFactoriesRegister
	TokenRejecterFactory        TokenRejecterFactory
	MetricsAndTracesRegister    MetricsAndTracesRegister
	EngineFactory               EngineFactory
	ProxyFactory                ProxyFactory
	BackendFactory              BackendFactory
	HandlerFactory              HandlerFactory
	RunServerFactory            RunServerFactory
	AgentStarterFactory         AgentStarter

	Middlewares []gin.HandlerFunc
}

ExecutorBuilder is a composable builder. Every injected property is used by the NewCmdExecutor method.

func (*ExecutorBuilder) NewCmdExecutor

func (e *ExecutorBuilder) NewCmdExecutor(ctx context.Context) cmd.Executor

NewCmdExecutor returns an executor for the cmd package. The executor initializes the entire gateway by delegating most of the tasks to the injected collaborators. They register the components and compose a RouterFactory wrapping all the middlewares. Every nil collaborator is replaced by the default one offered by this package.

type HandlerFactory

type HandlerFactory interface {
	NewHandlerFactory(logging.Logger, *metrics.Metrics, jose.RejecterFactory) router.HandlerFactory
}

HandlerFactory returns a KrakenD router handler factory, ready to be passed to the KrakenD RouterFactory

type LoggerBuilder

type LoggerBuilder struct{}

LoggerBuilder is the default BuilderFactory implementation.

func (LoggerBuilder) NewLogger

NewLogger sets up the logging components as defined at the configuration.

type LoggerFactory

type LoggerFactory interface {
	NewLogger(config.ServiceConfig) (logging.Logger, io.Writer, error)
}

LoggerFactory returns a KrakenD Logger factory, ready to be passed to the KrakenD RouterFactory

type MetricsAndTraces

type MetricsAndTraces struct{}

MetricsAndTraces is the default implementation of the MetricsAndTracesRegister interface.

func (MetricsAndTraces) Register

Register registers the metrics, influx and opencensus packages as required by the given configuration.

type MetricsAndTracesRegister

type MetricsAndTracesRegister interface {
	Register(context.Context, config.ServiceConfig, logging.Logger) *metrics.Metrics
}

MetricsAndTracesRegister registers the defined observability components and returns a metrics collector, if required.

type PluginLoader

type PluginLoader interface {
	Load(folder, pattern string, logger logging.Logger)
}

PluginLoader defines the interface for the collaborator responsible of starting the plugin loaders

type ProxyFactory

type ProxyFactory interface {
	NewProxyFactory(logging.Logger, proxy.BackendFactory, *metrics.Metrics) proxy.Factory
}

ProxyFactory returns a KrakenD proxy factory, ready to be passed to the KrakenD RouterFactory

type RunServer

RunServer defines the interface of a function used by the KrakenD router to start the service

type RunServerFactory

type RunServerFactory interface {
	NewRunServer(logging.Logger, router.RunServerFunc) RunServer
}

RunServerFactory returns a RunServer with several wraps around the injected one

type SubscriberFactoriesRegister

type SubscriberFactoriesRegister interface {
	Register(context.Context, config.ServiceConfig, logging.Logger) func(string, int)
}

SubscriberFactoriesRegister registers all the required subscriber factories from the available service discover components and adapters and returns a service register function. The service register function will register the service by the given name and port to all the available service discover clients

type TokenRejecterFactory

type TokenRejecterFactory interface {
	NewTokenRejecter(context.Context, config.ServiceConfig, logging.Logger, func(string, int)) (jose.ChainedRejecterFactory, error)
}

TokenRejecterFactory returns a jose.ChainedRejecterFactory containing all the required jose.RejecterFactory. It also should setup and manage any service related to the management of the revocation process, if required.

Directories

Path Synopsis
cmd
Package tests implements utility functions to help with API Gateway testing.
Package tests implements utility functions to help with API Gateway testing.

Jump to

Keyboard shortcuts

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