Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version to 2.6.0 #847

Merged
merged 53 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c235d72
add instrumented http client factory
dhontecillas Jan 20, 2024
4c22d8c
instrument pipe stage with krakend-otel
dhontecillas Jan 20, 2024
f5dafb1
add otel insturmentation at the router level
dhontecillas Jan 20, 2024
0733f08
fix error check and allow to override version when buildingdocker image
dhontecillas Jan 21, 2024
3647362
fix wrong err comparison
dhontecillas Jan 21, 2024
999e32d
update dependencies
dhontecillas Jan 22, 2024
66e44bc
update to global layer and new otel exporter config format
dhontecillas Jan 29, 2024
04dc9ab
update to most recen krakend-otel library draft
dhontecillas Feb 12, 2024
61f6e76
Update Dockerfile
kpacha Feb 13, 2024
337a680
update krakend-otel lib
dhontecillas Feb 19, 2024
f8650e1
Bump version to 2.6.0
taik0 Feb 23, 2024
dd947a8
opencensus exporters updated
kpacha Feb 23, 2024
7179521
Pass the application context and the execution context to the modifie…
taik0 Feb 23, 2024
3cf193c
Merge pull request #848 from krakend/modifiers_context
kpacha Feb 23, 2024
6942a5d
google and opencensus deps updated
kpacha Feb 23, 2024
9aa1656
aws deps updated
kpacha Feb 23, 2024
ff7f281
some deps updated
kpacha Feb 23, 2024
9f1accc
hashicorp deps updated
kpacha Feb 23, 2024
ef84524
prometheus deps updated
kpacha Feb 23, 2024
63bb6c9
update to latest krakend-otel
dhontecillas Feb 23, 2024
6a47ff2
otel and spf13 deps updated
kpacha Feb 23, 2024
f859049
gocloud deps updated
kpacha Feb 23, 2024
6ca456e
extra repos updated
kpacha Feb 23, 2024
ced9139
nats deps updated
kpacha Feb 23, 2024
79e1bc7
take the changes from dev-2.6
kpacha Feb 23, 2024
e642b94
initial version of the test plugin cmd
kpacha Feb 26, 2024
6891ef8
reduce CCN
kpacha Feb 26, 2024
5819874
integration tests fixed
kpacha Feb 26, 2024
d2bf830
update to krakend otel with logger
dhontecillas Feb 27, 2024
e134067
Merge pull request #849 from krakend/update_deps
taik0 Feb 27, 2024
e699ecc
fix otel global runserver position
dhontecillas Feb 27, 2024
aa01ad9
update to latest krakend-otel version
dhontecillas Feb 27, 2024
1dd0e78
Merge pull request #845 from krakend/alpine_upgrade
taik0 Feb 28, 2024
a7a675b
Merge branch 'dev-2.6' into test_plugins
kpacha Feb 28, 2024
2fa9472
uncomment autocompletion
kpacha Feb 28, 2024
7e78705
Merge pull request #851 from krakend/test_plugins
taik0 Feb 28, 2024
eebce17
internal deps updated
kpacha Feb 28, 2024
ce14f63
update to latest dev krakend-otel implementation
dhontecillas Mar 1, 2024
deaf509
fix deep source naming issue
dhontecillas Mar 1, 2024
ff57115
Merge branch 'dev-2.6' into krakend_otel
dhontecillas Mar 1, 2024
8c1e9b7
update to main branch of the otel library
dhontecillas Mar 5, 2024
8efe3ca
update to krakend-otel v0.1.0 and go mod tidy
dhontecillas Mar 5, 2024
d8034e5
use v0.2 of krakend-otel
dhontecillas Mar 5, 2024
5e0f271
move otel registration to MetricsAndTraces
dhontecillas Mar 5, 2024
441ebe5
update to use v0.2.0 of krakend-otel
dhontecillas Mar 6, 2024
38bcc5d
lura version upgraded to v2.6.1
kpacha Mar 7, 2024
802ea93
fix deep source issues
dhontecillas Mar 8, 2024
d2115e2
update to krakend-otel v0.2.0
dhontecillas Mar 11, 2024
54ff788
Merge pull request #854 from krakend/fix_move_otel_to_metrics_and_tra…
kpacha Mar 11, 2024
2b49cf1
remove non required interfaces
dhontecillas Mar 11, 2024
81f2bca
Merge pull request #839 from krakend/krakend_otel
kpacha Mar 11, 2024
e6eaf6b
upgrade indirect deps
kpacha Mar 11, 2024
0933949
check if the plugin exists before trying to load it
kpacha Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FROM alpine:${ALPINE_VERSION}

LABEL maintainer="community@krakend.io"

RUN apk add --no-cache ca-certificates tzdata && \
RUN apk upgrade --no-cache --no-interactive && apk add --no-cache ca-certificates tzdata && \
adduser -u 1000 -S -D -H krakend && \
mkdir /etc/krakend && \
echo '{ "version": 3 }' > /etc/krakend/krakend.json
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

BIN_NAME :=krakend
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
VERSION := 2.5.1
VERSION := 2.6.0
SCHEMA_VERSION := $(shell echo "${VERSION}" | cut -d '.' -f 1,2)
GIT_COMMIT := $(shell git rev-parse --short=7 HEAD)
PKGNAME := krakend
Expand All @@ -20,7 +20,7 @@ DESC := High performance API gateway. Aggregate, filter, manipulate and add midd
MAINTAINER := Daniel Ortiz <dortiz@krakend.io>
DOCKER_WDIR := /tmp/fpm
DOCKER_FPM := devopsfaith/fpm
GOLANG_VERSION := 1.20.13
GOLANG_VERSION := 1.20.14
GLIBC_VERSION := $(shell sh find_glibc.sh)
ALPINE_VERSION := 3.18
OS_TAG :=
Expand Down
22 changes: 18 additions & 4 deletions backend_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

otellura "github.com/krakend/krakend-otel/lura"
amqp "github.com/krakendio/krakend-amqp/v2"
cel "github.com/krakendio/krakend-cel/v2"
cb "github.com/krakendio/krakend-circuitbreaker/v2/gobreaker/proxy"
Expand Down Expand Up @@ -39,18 +40,25 @@ func NewBackendFactory(logger logging.Logger, metricCollector *metrics.Metrics)
return NewBackendFactoryWithContext(context.Background(), logger, metricCollector)
}

// NewBackendFactoryWithContext creates a BackendFactory by stacking all the available middlewares and injecting the received context
func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory {
func newRequestExecutorFactory(logger logging.Logger) func(*config.Backend) client.HTTPRequestExecutor {
requestExecutorFactory := func(cfg *config.Backend) client.HTTPRequestExecutor {
clientFactory := client.NewHTTPClient
if _, ok := cfg.ExtraConfig[oauth2client.Namespace]; ok {
clientFactory = oauth2client.NewHTTPClient(cfg)
} else {
clientFactory = httpcache.NewHTTPClient(cfg, clientFactory)
}

clientFactory = otellura.InstrumentedHTTPClientFactory(clientFactory, cfg)
// TODO: check what happens if we have both, opencensus and otel enabled ?
return opencensus.HTTPRequestExecutorFromConfig(clientFactory, cfg)
}
requestExecutorFactory = httprequestexecutor.HTTPRequestExecutor(logger, requestExecutorFactory)
return httprequestexecutor.HTTPRequestExecutor(logger, requestExecutorFactory)
}

func internalNewBackendFactory(ctx context.Context, requestExecutorFactory func(*config.Backend) client.HTTPRequestExecutor,
logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory {

backendFactory := martian.NewConfiguredBackendFactory(logger, requestExecutorFactory)
bf := pubsub.NewBackendFactory(ctx, logger, backendFactory)
backendFactory = bf.New
Expand All @@ -62,13 +70,19 @@ func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, me
backendFactory = cb.BackendFactory(backendFactory, logger)
backendFactory = metricCollector.BackendFactory("backend", backendFactory)
backendFactory = opencensus.BackendFactory(backendFactory)

backendFactory = otellura.BackendFactory(backendFactory)
return func(remote *config.Backend) proxy.Proxy {
logger.Debug(fmt.Sprintf("[BACKEND: %s] Building the backend pipe", remote.URLPattern))
return backendFactory(remote)
}
}

// NewBackendFactoryWithContext creates a BackendFactory by stacking all the available middlewares and injecting the received context
func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory {
requestExecutorFactory := newRequestExecutorFactory(logger)
return internalNewBackendFactory(ctx, requestExecutorFactory, logger, metricCollector)
}

type backendFactory struct{}

func (backendFactory) NewBackendFactory(ctx context.Context, l logging.Logger, m *metrics.Metrics) proxy.BackendFactory {
Expand Down
12 changes: 12 additions & 0 deletions cmd/krakend-ce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func main() {
})
}

commandsToLoad := []cmd.Command{
cmd.RunCommand,
cmd.CheckCommand,
cmd.PluginCommand,
cmd.VersionCommand,
cmd.AuditCommand,
krakend.NewTestPluginCmd(),
}

cmd.DefaultRoot = cmd.NewRoot(cmd.RootCommand, commandsToLoad...)
cmd.DefaultRoot.Cmd.CompletionOptions.DisableDefaultCmd = true

cmd.Execute(cfg, krakend.NewExecutor(ctx))
}

Expand Down
68 changes: 52 additions & 16 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/go-contrib/uuid"
"golang.org/x/sync/errgroup"

kotel "github.com/krakend/krakend-otel"
otellura "github.com/krakend/krakend-otel/lura"
otelgin "github.com/krakend/krakend-otel/router/gin"
krakendbf "github.com/krakendio/bloomfilter/v2/krakend"
asyncamqp "github.com/krakendio/krakend-amqp/v2/async"
audit "github.com/krakendio/krakend-audit"
Expand Down Expand Up @@ -53,10 +56,16 @@ func NewExecutor(ctx context.Context) cmd.Executor {
}

// PluginLoader defines the interface for the collaborator responsible of starting the plugin loaders
// Deprecated: Use PluginLoaderWithContext
type PluginLoader interface {
Load(folder, pattern string, logger logging.Logger)
}

// PluginLoaderWithContext defines the interface for the collaborator responsible of starting the plugin loaders
type PluginLoaderWithContext interface {
LoadWithContext(ctx context.Context, folder, pattern string, logger logging.Logger)
}

// 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
Expand Down Expand Up @@ -123,17 +132,20 @@ type AgentStarter interface {

// ExecutorBuilder is a composable builder. Every injected property is used by the NewCmdExecutor method.
type ExecutorBuilder struct {
LoggerFactory LoggerFactory
// PluginLoader is deprecated: Use PluginLoaderWithContext
PluginLoader PluginLoader
PluginLoaderWithContext PluginLoaderWithContext
LoggerFactory LoggerFactory
SubscriberFactoriesRegister SubscriberFactoriesRegister
TokenRejecterFactory TokenRejecterFactory
MetricsAndTracesRegister MetricsAndTracesRegister
EngineFactory EngineFactory
ProxyFactory ProxyFactory
BackendFactory BackendFactory
HandlerFactory HandlerFactory
RunServerFactory RunServerFactory
AgentStarterFactory AgentStarter

ProxyFactory ProxyFactory
BackendFactory BackendFactory
HandlerFactory HandlerFactory
RunServerFactory RunServerFactory
AgentStarterFactory AgentStarter

Middlewares []gin.HandlerFunc
}
Expand Down Expand Up @@ -161,10 +173,13 @@ func (e *ExecutorBuilder) NewCmdExecutor(ctx context.Context) cmd.Executor {
}

if cfg.Plugin != nil {
e.PluginLoader.Load(cfg.Plugin.Folder, cfg.Plugin.Pattern, logger)
e.PluginLoaderWithContext.LoadWithContext(ctx, cfg.Plugin.Folder, cfg.Plugin.Pattern, logger)
}

metricCollector := e.MetricsAndTracesRegister.Register(ctx, cfg, logger)
if metricsAndTracesCloser, ok := e.MetricsAndTracesRegister.(io.Closer); ok {
defer metricsAndTracesCloser.Close()
}

// Initializes the global cache for the JWK clients if enabled in the config
if err := jose.SetGlobalCacher(logger, cfg.ExtraConfig); err != nil && err != jose.ErrNoValidatorCfg {
Expand All @@ -180,14 +195,18 @@ func (e *ExecutorBuilder) NewCmdExecutor(ctx context.Context) cmd.Executor {
logger.Warning("[SERVICE: Bloomfilter]", err.Error())
}

pf := e.ProxyFactory.NewProxyFactory(
logger,
e.BackendFactory.NewBackendFactory(ctx, logger, metricCollector),
metricCollector,
)
bpf := e.BackendFactory.NewBackendFactory(ctx, logger, metricCollector)
pf := e.ProxyFactory.NewProxyFactory(logger, bpf, metricCollector)

agentPing := make(chan string, len(cfg.AsyncAgents))

handlerF := e.HandlerFactory.NewHandlerFactory(logger, metricCollector, tokenRejecterFactory)
handlerF = otelgin.New(handlerF)

runServerChain := serverhttp.RunServerWithLoggerFactory(logger)
runServerChain = otellura.GlobalRunServer(logger, runServerChain)
runServerChain = router.RunServerFunc(e.RunServerFactory.NewRunServer(logger, runServerChain))

// setup the krakend router
routerFactory := router.NewFactory(router.Config{
Engine: e.EngineFactory.NewEngine(cfg, router.EngineOptions{
Expand All @@ -198,8 +217,8 @@ func (e *ExecutorBuilder) NewCmdExecutor(ctx context.Context) cmd.Executor {
ProxyFactory: pf,
Middlewares: e.Middlewares,
Logger: logger,
HandlerFactory: e.HandlerFactory.NewHandlerFactory(logger, metricCollector, tokenRejecterFactory),
RunServer: router.RunServerFunc(e.RunServerFactory.NewRunServer(logger, serverhttp.RunServerWithLoggerFactory(logger))),
HandlerFactory: handlerF,
RunServer: runServerChain,
})

// start the engines
Expand Down Expand Up @@ -238,6 +257,9 @@ func (e *ExecutorBuilder) checkCollaborators() {
if e.PluginLoader == nil {
e.PluginLoader = new(pluginLoader)
}
if e.PluginLoaderWithContext == nil {
e.PluginLoaderWithContext = new(pluginLoader)
}
if e.SubscriberFactoriesRegister == nil {
e.SubscriberFactoriesRegister = new(registerSubscriberFactories)
}
Expand Down Expand Up @@ -352,10 +374,12 @@ func (BloomFilterJWT) NewTokenRejecter(ctx context.Context, cfg config.ServiceCo
}

// MetricsAndTraces is the default implementation of the MetricsAndTracesRegister interface.
type MetricsAndTraces struct{}
type MetricsAndTraces struct {
shutdownFn func()
}

// Register registers the metrics, influx and opencensus packages as required by the given configuration.
func (MetricsAndTraces) Register(ctx context.Context, cfg config.ServiceConfig, l logging.Logger) *metrics.Metrics {
func (m *MetricsAndTraces) Register(ctx context.Context, cfg config.ServiceConfig, l logging.Logger) *metrics.Metrics {
metricCollector := metrics.New(ctx, cfg.ExtraConfig, l)

if err := influxdb.New(ctx, cfg.ExtraConfig, metricCollector, l); err != nil {
Expand All @@ -374,9 +398,21 @@ func (MetricsAndTraces) Register(ctx context.Context, cfg config.ServiceConfig,
l.Debug("[SERVICE: OpenCensus] Service correctly registered")
}

if shutdownFn, err := kotel.Register(ctx, l, cfg); err == nil {
m.shutdownFn = shutdownFn
} else {
l.Error(fmt.Sprintf("[SERVICE: OpenTelemetry] cannot register exporters: %s", err.Error()))
}

return metricCollector
}

func (m *MetricsAndTraces) Close() {
if m.shutdownFn != nil {
m.shutdownFn()
}
}

const (
usageDisable = "USAGE_DISABLE"
usageDelay = 5 * time.Second
Expand Down
Loading
Loading