MSP-8974 up deps
This commit is contained in:
1 parent
0abaaf740f
commit
a0aafd93b9
602 files changed
+47724
-13295
No files matched your search
+3
-2
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/txix-open/bgjob"
|
||||
)
|
||||
@@ -38,8 +39,8 @@ type Sync struct {
|
||||
// will be the outermost wrapper.
|
||||
func NewSync(adapter SyncHandlerAdapter, middlewares ...Middleware) Sync {
|
||||
s := Sync{}
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
adapter = middlewares[i](adapter)
|
||||
for _, middleware := range slices.Backward(middlewares) {
|
||||
adapter = middleware(adapter)
|
||||
}
|
||||
s.handler = adapter
|
||||
return s
|
||||
|
||||
+1
@@ -308,6 +308,7 @@ func initClusterClient(
|
||||
},
|
||||
EndpointsResolver: endpointsResolver,
|
||||
MetricsAutodiscovery: metricsServiceDiscovery(localConfig, broadcastHost),
|
||||
ModuleLeaderMode: localConfig.ModuleLeaderMode,
|
||||
}
|
||||
|
||||
schema := rc.GenerateConfigSchema(remoteConfig)
|
||||
|
||||
+2
@@ -41,6 +41,7 @@ type LocalConfig struct {
|
||||
// - DefaultRemoteConfigPath: Custom path for default remote configuration file (optional)
|
||||
// - RemoteConfigReceiverTimeout: Timeout for receiving remote configuration updates
|
||||
// - MetricsAutodiscovery: Configuration for Prometheus metrics auto-discovery
|
||||
// - ModuleLeaderMode: Module leader election mode announced in MODULE:READY (optional)
|
||||
type ClusteredLocalConfig struct {
|
||||
LocalConfig
|
||||
|
||||
@@ -48,6 +49,7 @@ type ClusteredLocalConfig struct {
|
||||
DefaultRemoteConfigPath string
|
||||
RemoteConfigReceiverTimeout time.Duration
|
||||
MetricsAutodiscovery MetricsAutodiscovery
|
||||
ModuleLeaderMode string
|
||||
}
|
||||
|
||||
// Logs configures log sampling and rate limiting.
|
||||
|
||||
+1
@@ -348,6 +348,7 @@ func (c *Client) notifyModuleReady(ctx context.Context, cli *clientWrapper, requ
|
||||
RequiredModules: moduleDependencies,
|
||||
Address: c.moduleInfo.GrpcOuterAddress,
|
||||
MetricsAutodiscovery: c.moduleInfo.MetricsAutodiscovery,
|
||||
ModuleLeaderMode: c.moduleInfo.ModuleLeaderMode,
|
||||
}
|
||||
_, err := cli.EmitJsonWithAck(ctx, ModuleReady, declaration)
|
||||
if err != nil {
|
||||
|
||||
+12
-3
@@ -10,12 +10,19 @@ const (
|
||||
GrpcTransport = "grpc"
|
||||
HttpTransport = "http"
|
||||
EmptyTransport = "empty"
|
||||
|
||||
ModuleLeaderModeNone = ""
|
||||
ModuleLeaderModeRequestElection = "REQUEST_ELECTION"
|
||||
ModuleLeaderModeImLeader = "IM_LEADER"
|
||||
ModuleLeaderModeImFollower = "IM_FOLLOWER"
|
||||
)
|
||||
|
||||
// AddressConfiguration represents the IP address and port for a service endpoint.
|
||||
// AddressConfiguration represents the IP address and port for a service endpoint,
|
||||
// and whether this instance is the module leader.
|
||||
type AddressConfiguration struct {
|
||||
IP string `json:"ip"`
|
||||
Port string `json:"port"`
|
||||
IP string `json:"ip"`
|
||||
Port string `json:"port"`
|
||||
IsModuleLeader bool
|
||||
}
|
||||
|
||||
// ConfigData contains configuration data for a module, including version information
|
||||
@@ -36,6 +43,7 @@ type ModuleInfo struct {
|
||||
GrpcOuterAddress AddressConfiguration
|
||||
EndpointsResolver EndpointsResolver
|
||||
MetricsAutodiscovery *MetricsAutodiscovery
|
||||
ModuleLeaderMode string
|
||||
}
|
||||
|
||||
// RoutingConfig represents a list of backend declarations for routing configuration.
|
||||
@@ -52,6 +60,7 @@ type BackendDeclaration struct {
|
||||
RequiredModules []ModuleDependency
|
||||
Address AddressConfiguration
|
||||
MetricsAutodiscovery *MetricsAutodiscovery
|
||||
ModuleLeaderMode string
|
||||
}
|
||||
|
||||
// EndpointDescriptor describes an HTTP endpoint, including its path, method, authentication
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -289,8 +290,8 @@ func defaultTransportDialContext(dialer *net.Dialer) func(context.Context, strin
|
||||
// nolint:ireturn
|
||||
func joinMiddlewares(root RoundTripper, mws ...Middleware) RoundTripper {
|
||||
roundTripper := root
|
||||
for i := len(mws) - 1; i >= 0; i-- {
|
||||
roundTripper = mws[i](roundTripper)
|
||||
for _, mw := range slices.Backward(mws) {
|
||||
roundTripper = mw(roundTripper)
|
||||
}
|
||||
return roundTripper
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@ func LogLevelForError(err error) log.Level {
|
||||
// It uses LogLevelForError to determine the log level and returns the corresponding Logger method.
|
||||
func LogLevelFuncForError(err error, logger log.Logger) func(ctx context.Context, message any, fields ...log.Field) {
|
||||
logLevel := LogLevelForError(err)
|
||||
switch logLevel {
|
||||
switch logLevel { //nolint:exhaustive
|
||||
case log.ErrorLevel:
|
||||
return logger.Error
|
||||
case log.WarnLevel:
|
||||
|
||||
-5
@@ -8,14 +8,9 @@
|
||||
|
||||
Проверяет, что удалённая конфигурация соответствует сгенерированной JSON-схеме и проходит валидацию.
|
||||
|
||||
* Проверяет отсутствие устаревшего тега `valid`
|
||||
* Проверяет соответствие структуры JSON-схеме
|
||||
* Выполняет валидацию значений с помощью `validator.Default`
|
||||
|
||||
### `FindTag[T any](v T, tag string) bool`
|
||||
|
||||
Рекурсивно проверяет, содержит ли структура тег с указанным именем.
|
||||
|
||||
## Usage
|
||||
|
||||
### Example usage in test
|
||||
|
||||
-36
@@ -5,7 +5,6 @@ package rct
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -21,7 +20,6 @@ import (
|
||||
// validator tag validation.
|
||||
//
|
||||
// The function checks:
|
||||
// - No deprecated 'valid' tags are present
|
||||
// - The default configuration file is valid against the generated schema
|
||||
// - The configuration can be unmarshaled from the file
|
||||
// - The configuration passes validation
|
||||
@@ -30,9 +28,6 @@ import (
|
||||
func Test[T any](t *testing.T, defaultRemoteConfigPath string, remoteConfig T) {
|
||||
require := require.New(t)
|
||||
|
||||
validatorTag := "valid"
|
||||
require.Falsef(FindTag(remoteConfig, validatorTag), "'%s' tag is not longer supported, you must use https://github.com/go-playground/validator", validatorTag)
|
||||
|
||||
defaultRemoteConfig, err := os.ReadFile(defaultRemoteConfigPath)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -58,34 +53,3 @@ func Test[T any](t *testing.T, defaultRemoteConfigPath string, remoteConfig T) {
|
||||
err = validator.Default.ValidateToError(remoteConfig)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
// FindTag recursively searches a type for the specified struct tag.
|
||||
// It traverses structs, maps, arrays, and slices to find any field
|
||||
// that has the given tag. Returns true if the tag is found.
|
||||
func FindTag[T any](v T, tag string) bool {
|
||||
t := reflect.TypeOf(v)
|
||||
if t == nil {
|
||||
return false
|
||||
}
|
||||
queue := []reflect.Type{t}
|
||||
for len(queue) > 0 {
|
||||
cur := queue[0]
|
||||
queue = queue[1:]
|
||||
if cur.Kind() == reflect.Ptr {
|
||||
cur = cur.Elem()
|
||||
}
|
||||
// nolint:exhaustive
|
||||
switch cur.Kind() {
|
||||
case reflect.Struct:
|
||||
for field := range cur.Fields() {
|
||||
if field.Tag.Get(tag) != "" {
|
||||
return true
|
||||
}
|
||||
queue = append(queue, field.Type)
|
||||
}
|
||||
case reflect.Map, reflect.Array, reflect.Slice:
|
||||
queue = append(queue, cur.Elem())
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user