-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use common timeout middleware (#6866)
* fix: use common timeout middleware * fix: use apiserver factory for config * fix: add backward compatibility for old variables * fix: remove apiserver provider and use config directly * fix: remove apiserver interface * fix: address comments * fix: address minor comments * fix: address minor comments
- Loading branch information
1 parent
726f2b0
commit df5ab64
Showing
13 changed files
with
157 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package apiserver | ||
|
||
import ( | ||
"time" | ||
|
||
"go.signoz.io/signoz/pkg/factory" | ||
) | ||
|
||
// Config holds the configuration for config. | ||
type Config struct { | ||
Timeout Timeout `mapstructure:"timeout"` | ||
} | ||
|
||
type Timeout struct { | ||
// The default context timeout that can be overridden by the request | ||
Default time.Duration `mapstructure:"default"` | ||
// The maximum allowed context timeout | ||
Max time.Duration `mapstructure:"max"` | ||
// The list of routes that are excluded from the timeout | ||
ExcludedRoutes []string `mapstructure:"excluded_routes"` | ||
} | ||
|
||
func NewConfigFactory() factory.ConfigFactory { | ||
return factory.NewConfigFactory(factory.MustNewName("apiserver"), newConfig) | ||
} | ||
|
||
func newConfig() factory.Config { | ||
return &Config{ | ||
Timeout: Timeout{ | ||
Default: 60 * time.Second, | ||
Max: 600 * time.Second, | ||
ExcludedRoutes: []string{ | ||
"/api/v1/logs/tail", | ||
"/api/v3/logs/livetail", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c Config) Validate() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package apiserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.signoz.io/signoz/pkg/config" | ||
"go.signoz.io/signoz/pkg/config/envprovider" | ||
"go.signoz.io/signoz/pkg/factory" | ||
) | ||
|
||
func TestNewWithEnvProvider(t *testing.T) { | ||
t.Setenv("SIGNOZ_APISERVER_TIMEOUT_DEFAULT", "70s") | ||
t.Setenv("SIGNOZ_APISERVER_TIMEOUT_MAX", "700s") | ||
t.Setenv("SIGNOZ_APISERVER_TIMEOUT_EXCLUDED__ROUTES", "/excluded1,/excluded2") | ||
|
||
conf, err := config.New( | ||
context.Background(), | ||
config.ResolverConfig{ | ||
Uris: []string{"env:"}, | ||
ProviderFactories: []config.ProviderFactory{ | ||
envprovider.NewFactory(), | ||
}, | ||
}, | ||
[]factory.ConfigFactory{ | ||
NewConfigFactory(), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
actual := &Config{} | ||
err = conf.Unmarshal("apiserver", actual) | ||
|
||
require.NoError(t, err) | ||
|
||
expected := &Config{ | ||
Timeout: Timeout{ | ||
Default: 70 * time.Second, | ||
Max: 700 * time.Second, | ||
ExcludedRoutes: []string{ | ||
"/excluded1", | ||
"/excluded2", | ||
}, | ||
}, | ||
} | ||
|
||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.