Skip to content

Commit

Permalink
fix(relayproxy): Remove Timeout middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Dec 24, 2024
1 parent 5a6108d commit 3ff8e57
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 37 deletions.
21 changes: 2 additions & 19 deletions cmd/relayproxy/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/aws/aws-lambda-go/lambda"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
Expand All @@ -21,6 +17,8 @@ import (
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/service"
"go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
"go.uber.org/zap"
"net/http"
"strings"
)

// New is used to create a new instance of the API server
Expand Down Expand Up @@ -55,21 +53,6 @@ func (s *Server) initRoutes() {
s.apiEcho.HidePort = true
s.apiEcho.Debug = s.config.IsDebugEnabled()
s.apiEcho.Use(otelecho.Middleware("go-feature-flag"))
// Timeout middleware has to be the first middleware in the list
// (see: https://github.com/labstack/echo/blob/3b017855b4d331002e2b8b28e903679b875ae3e9/middleware/timeout.go#L17)
s.apiEcho.Use(middleware.TimeoutWithConfig(
middleware.TimeoutConfig{
Skipper: func(c echo.Context) bool {
// ignore websocket in the timeout
return strings.HasPrefix(c.Request().URL.String(), "/ws")
},
Timeout: time.Duration(s.config.RestAPITimeout) * time.Millisecond,
OnTimeoutRouteErrorHandler: func(err error, c echo.Context) {
s.zapLog.Error("Timeout on route", zap.String("route", c.Path()), zap.Error(err))
},
ErrorMessage: `Timeout on the server, please retry later`,
}),
)
s.apiEcho.Use(custommiddleware.ZapLogger(s.zapLog, s.config))
s.apiEcho.Use(middleware.BodyDumpWithConfig(middleware.BodyDumpConfig{
Skipper: func(c echo.Context) bool {
Expand Down
4 changes: 0 additions & 4 deletions cmd/relayproxy/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func New(flagSet *pflag.FlagSet, log *zap.Logger, version string) (*Config, erro
"listen": "1031",
"host": "localhost",
"fileFormat": "yaml",
"restApiTimeout": 5000,
"pollingInterval": 60000,
"logLevel": DefaultLogLevel,
}, "."), nil)
Expand Down Expand Up @@ -260,9 +259,6 @@ type Config struct {
// Notifiers is the configuration on where to notify a flag change
Notifiers []NotifierConf `mapstructure:"notifier" koanf:"notifier"`

// RestAPITimeout is the timeout on the API.
RestAPITimeout int `mapstructure:"restApiTimeout" koanf:"restapitimeout"`

// Version is the version of the relay-proxy
Version string `mapstructure:"version" koanf:"version"`

Expand Down
13 changes: 0 additions & 13 deletions cmd/relayproxy/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
Kind: "log",
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
AuthorizedKeys: config.APIKeys{
Expand Down Expand Up @@ -75,7 +74,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
},
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
AuthorizedKeys: config.APIKeys{
Expand Down Expand Up @@ -105,7 +103,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
Kind: "log",
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
APIKeys: []string{
Expand Down Expand Up @@ -133,7 +130,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
Kind: "log",
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
APIKeys: []string{
Expand All @@ -153,7 +149,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
FileFormat: "yaml",
Host: "localhost",
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
LogLevel: config.DefaultLogLevel,
},
Expand All @@ -172,7 +167,6 @@ func TestParseConfig_fileFromPflag(t *testing.T) {
PollingInterval: 60000,
FileFormat: "yaml",
Host: "localhost",
RestAPITimeout: 5000,
LogLevel: config.DefaultLogLevel,
Version: "1.X.X",
Retrievers: &[]config.RetrieverConf{
Expand Down Expand Up @@ -238,7 +232,6 @@ func TestParseConfig_fileFromFolder(t *testing.T) {
Kind: "log",
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
AuthorizedKeys: config.APIKeys{
Expand All @@ -263,7 +256,6 @@ func TestParseConfig_fileFromFolder(t *testing.T) {
FileFormat: "yaml",
Host: "localhost",
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
LogLevel: config.DefaultLogLevel,
},
Expand All @@ -284,7 +276,6 @@ func TestParseConfig_fileFromFolder(t *testing.T) {
FileFormat: "yaml",
Host: "localhost",
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
LogLevel: config.DefaultLogLevel,
},
Expand All @@ -299,7 +290,6 @@ func TestParseConfig_fileFromFolder(t *testing.T) {
FileFormat: "yaml",
Host: "localhost",
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
LogLevel: config.DefaultLogLevel,
},
Expand All @@ -314,7 +304,6 @@ func TestParseConfig_fileFromFolder(t *testing.T) {
FileFormat: "yaml",
Host: "localhost",
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
LogLevel: config.DefaultLogLevel,
},
Expand Down Expand Up @@ -837,7 +826,6 @@ func TestMergeConfig_FromOSEnv(t *testing.T) {
Kind: "log",
},
StartWithRetrieverError: false,
RestAPITimeout: 5000,
Version: "1.X.X",
EnableSwagger: true,
AuthorizedKeys: config.APIKeys{
Expand Down Expand Up @@ -870,7 +858,6 @@ func TestMergeConfig_FromOSEnv(t *testing.T) {
PollingInterval: 60000,
FileFormat: "yaml",
Host: "localhost",
RestAPITimeout: 5000,
LogLevel: config.DefaultLogLevel,
Version: "1.X.X",
Retrievers: &[]config.RetrieverConf{
Expand Down
1 change: 0 additions & 1 deletion website/docs/relay_proxy/configure_relay_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ ex: `AUTHORIZEDKEYS_EVALUATION=my-first-key,my-second-key`)_.
| `hideBanner` | boolean | `false` | Should we display the beautiful **go-feature-flag** banner when starting the relay proxy |
| `enableSwagger` | boolean | `false` | Enables Swagger for testing the APIs directly. If you are enabling Swagger you will have to provide the `host` configuration and the Swagger UI will be available at `http://<host>:<listen>/swagger/`. |
| `host` | string | `localhost` | This is the DNS you will use to access the relay proxy. This field is used by Swagger to query the API at the right place. |
| `restApiTimeout` | int | `5000` | Timeout in milliseconds for API calls. |
| `logLevel` | string | `info` | The log level to use for the relay proxy.<br/> Available values are `ERROR`, `WARN`, `INFO`, `DEBUG`. |
| `logFormat` | string | `json` | The format to use for structured logs from the relay proxy.<br/>Valid values are `json` and `logfmt`. |
| `fileFormat` | string | `yaml` | This is the format of your `go-feature-flag` configuration file. Acceptable values are `yaml`, `json`, `toml`. |
Expand Down

0 comments on commit 3ff8e57

Please sign in to comment.