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

Add parent endpoint method to backend logs. #709

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ type Backend struct {
// so logs and other instrumentation can output better info (thus, it is not loaded
// with `mapstructure` or `json` tags).
ParentEndpoint string `json:"-" mapstructure:"-"`
// ParentEndpointMethod is to be filled by the parent endpoint with its enpoint method
// so logs and other instrumentation can output better info (thus, it is not loaded
// with `mapstructure` or `json` tags).
ParentEndpointMethod string `json:"-" mapstructure:"-"`
}

// Plugin contains the config required by the plugin module
Expand Down Expand Up @@ -504,6 +508,7 @@ func (s *ServiceConfig) initEndpoints() error {
for j, b := range e.Backend {
// we "tell" the backend which is his parent endpoint
b.ParentEndpoint = e.Endpoint
b.ParentEndpointMethod = e.Method
if err := s.initBackendDefaults(i, j); err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions proxy/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import (
// NewConcurrentMiddlewareWithLogger creates a proxy middleware that enables sending several requests concurrently
func NewConcurrentMiddlewareWithLogger(logger logging.Logger, remote *config.Backend) Middleware {
if remote.ConcurrentCalls == 1 {
logger.Fatal("too few concurrent calls for %s -> %s: NewConcurrentMiddleware expects more than 1 concurrent call, got %d", remote.ParentEndpoint, remote.URLPattern, remote.ConcurrentCalls)
logger.Fatal("too few concurrent calls for %s %s -> %s: NewConcurrentMiddleware expects more than 1 concurrent call, got %d",
remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, remote.ConcurrentCalls)
return nil
}
serviceTimeout := time.Duration(75*remote.Timeout.Nanoseconds()/100) * time.Nanosecond

return func(next ...Proxy) Proxy {
if len(next) > 1 {
logger.Fatal("too many proxies for this %s -> %s proxy middleware: NewConcurrentMiddleware only accepts 1 proxy, got %d", remote.ParentEndpoint, remote.URLPattern, len(next))
logger.Fatal("too many proxies for this %s -> %s proxy middleware: NewConcurrentMiddleware only accepts 1 proxy, got %d",
remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, len(next))
return nil
}

Expand Down
8 changes: 5 additions & 3 deletions proxy/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewGraphQLMiddleware(logger logging.Logger, remote *config.Backend) Middlew
if err != nil {
if err != graphql.ErrNoConfigFound {
logger.Warning(
fmt.Sprintf("[BACKEND: %s -> %s][GraphQL] %s", remote.ParentEndpoint, remote.URLPattern, err.Error()))
fmt.Sprintf("[BACKEND: %s %s -> %s][GraphQL] %s", remote.ParentEndpoint, remote.ParentEndpoint, remote.URLPattern, err.Error()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, remote.ParentEndpoint -> remote.ParentEndpointMethod

}
return emptyMiddlewareFallback(logger)
}
Expand Down Expand Up @@ -68,13 +68,15 @@ func NewGraphQLMiddleware(logger logging.Logger, remote *config.Backend) Middlew

return func(next ...Proxy) Proxy {
if len(next) > 1 {
logger.Fatal("too many proxies for this %s -> %s proxy middleware: NewGraphQLMiddleware only accepts 1 proxy, got %d", remote.ParentEndpoint, remote.URLPattern, len(next))
logger.Fatal("too many proxies for this %s %s -> %s proxy middleware: NewGraphQLMiddleware only accepts 1 proxy, got %d",
remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, len(next))
return nil
}

logger.Debug(
fmt.Sprintf(
"[BACKEND: %s -> %s][GraphQL] Operation: %s, Method: %s",
"[BACKEND: %s %s -> %s][GraphQL] Operation: %s, Method: %s",
remote.ParentEndpointMethod,
remote.ParentEndpoint,
remote.URLPattern,
opt.Type,
Expand Down
2 changes: 1 addition & 1 deletion proxy/headers_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewFilterHeadersMiddleware(logger logging.Logger, remote *config.Backend) M

return func(next ...Proxy) Proxy {
if len(next) > 1 {
logger.Fatal("too many proxies for this %s -> %s proxy middleware: NewFilterHeadersMiddleware only accepts 1 proxy, got %d", remote.ParentEndpoint, remote.URLPattern, len(next))
logger.Fatal("too many proxies for this %s %s -> %s proxy middleware: NewFilterHeadersMiddleware only accepts 1 proxy, got %d", remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, len(next))
return nil
}
nextProxy := next[0]
Expand Down
2 changes: 1 addition & 1 deletion proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewRequestBuilderMiddlewareWithLogger(logger logging.Logger, remote *config
func newRequestBuilderMiddleware(l logging.Logger, remote *config.Backend) Middleware {
return func(next ...Proxy) Proxy {
if len(next) > 1 {
l.Fatal("too many proxies for this %s -> %s proxy middleware: newRequestBuilderMiddleware only accepts 1 proxy, got %d", remote.ParentEndpoint, remote.URLPattern, len(next))
l.Fatal("too many proxies for this %s %s -> %s proxy middleware: newRequestBuilderMiddleware only accepts 1 proxy, got %d", remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, len(next))
return nil
}
return func(ctx context.Context, request *Request) (*Response, error) {
Expand Down
2 changes: 1 addition & 1 deletion proxy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewBackendPluginMiddleware(logger logging.Logger, remote *config.Backend) M
}

return newPluginMiddleware(logger, "BACKEND",
fmt.Sprintf("%s -> %s", remote.ParentEndpoint, remote.URLPattern), cfg)
fmt.Sprintf("%s %s -> %s", remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern), cfg)
}

func newPluginMiddleware(logger logging.Logger, tag, pattern string, cfg map[string]interface{}) Middleware {
Expand Down
2 changes: 1 addition & 1 deletion proxy/query_strings_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewFilterQueryStringsMiddleware(logger logging.Logger, remote *config.Backe

return func(next ...Proxy) Proxy {
if len(next) > 1 {
logger.Fatal("too many proxies for this %s -> %s proxy middleware: NewFilterQueryStringsMiddleware only accepts 1 proxy, got %d", remote.ParentEndpoint, remote.URLPattern, len(next))
logger.Fatal("too many proxies for this %s %s -> %s proxy middleware: NewFilterQueryStringsMiddleware only accepts 1 proxy, got %d", remote.ParentEndpointMethod, remote.ParentEndpoint, remote.URLPattern, len(next))
return nil
}
nextProxy := next[0]
Expand Down
2 changes: 1 addition & 1 deletion transport/http/client/plugin/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func HTTPRequestExecutorWithContext(
next func(*config.Backend) client.HTTPRequestExecutor,
) func(*config.Backend) client.HTTPRequestExecutor {
return func(cfg *config.Backend) client.HTTPRequestExecutor {
logPrefix := fmt.Sprintf("[BACKEND: %s -> %s]", cfg.ParentEndpoint, cfg.URLPattern)
logPrefix := fmt.Sprintf("[BACKEND: %s %s -> %s]", cfg.ParentEndpointMethod, cfg.ParentEndpoint, cfg.URLPattern)
v, ok := cfg.ExtraConfig[Namespace]
if !ok {
return next(cfg)
Expand Down
Loading