[#1422] config: Add multinet config
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 1m34s
DCO action / DCO (pull_request) Successful in 1m44s
Vulncheck / Vulncheck (pull_request) Successful in 2m42s
Pre-commit hooks / Pre-commit (pull_request) Failing after 2m53s
Build / Build Components (pull_request) Successful in 3m18s
Tests and linters / Staticcheck (pull_request) Successful in 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m16s
Tests and linters / Lint (pull_request) Successful in 3m50s
Tests and linters / Tests (pull_request) Successful in 4m59s
Tests and linters / Tests with -race (pull_request) Successful in 6m48s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-10-08 15:24:01 +03:00
parent c065d55ca3
commit 3ddc094211
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
6 changed files with 136 additions and 5 deletions

View file

@ -0,0 +1,42 @@
package multinet
import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
)
const (
subsection = "multinet"
FallbackDelayDefault = 300 * time.Millisecond
)
// Enabled returns the value of "enabled" config parameter from "multinet" section.
func Enabled(c *config.Config) bool {
return config.BoolSafe(c.Sub(subsection), "enabled")
}
// Subnets returns the value of "subnets" config parameter from "multinet" section.
func Subnets(c *config.Config) []string {
return config.StringSliceSafe(c.Sub(subsection), "subnets")
}
// Balancer returns the value of "balancer" config parameter from "multinet" section.
func Balancer(c *config.Config) string {
return config.StringSafe(c.Sub(subsection), "balancer")
}
// Restrict returns the value of "restrict" config parameter from "multinet" section.
func Restrict(c *config.Config) bool {
return config.BoolSafe(c.Sub(subsection), "restrict")
}
// FallbackDelay returns the value of "fallback_delay" config parameter from "multinet" section.
func FallbackDelay(c *config.Config) time.Duration {
fd := config.DurationSafe(c.Sub(subsection), "fallback_delay")
if fd != 0 { // negative value means no fallback
return fd
}
return FallbackDelayDefault
}

View file

@ -0,0 +1,40 @@
package multinet
import (
"testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
configtest "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/test"
"github.com/stretchr/testify/require"
)
func TestMultinetSection(t *testing.T) {
t.Run("defaults", func(t *testing.T) {
empty := configtest.EmptyConfig()
require.Equal(t, false, Enabled(empty))
require.Equal(t, ([]string)(nil), Subnets(empty))
require.Equal(t, "", Balancer(empty))
require.Equal(t, false, Restrict(empty))
require.Equal(t, FallbackDelayDefault, FallbackDelay(empty))
})
const path = "../../../../config/example/node"
fileConfigTest := func(c *config.Config) {
require.Equal(t, true, Enabled(c))
require.Equal(t, []string{
"192.168.219.174/24",
"10.78.70.74/23",
}, Subnets(c))
require.Equal(t, "roundrobin", Balancer(c))
require.Equal(t, false, Restrict(c))
require.Equal(t, 350*time.Millisecond, FallbackDelay(c))
}
configtest.ForEachFileType(path, fileConfigTest)
t.Run("ENV", func(t *testing.T) {
configtest.ForEnvFileType(t, path, fileConfigTest)
})
}

View file

@ -206,3 +206,10 @@ FROSTFS_RUNTIME_SOFT_MEMORY_LIMIT=1073741824
# AUDIT section
FROSTFS_AUDIT_ENABLED=true
# MULTINET section
FROSTFS_MULTINET_ENABLED=true
FROSTFS_MULTINET_SUBNETS="192.168.219.174/24 10.78.70.74/23"
FROSTFS_MULTINET_BALANCER=roundrobin
FROSTFS_MULTINET_RESTRICT=false
FROSTFS_MULTINET_FALLBACK_DELAY=350ms

View file

@ -264,5 +264,15 @@
},
"audit": {
"enabled": true
},
"multinet": {
"enabled": true,
"subnets": [
"192.168.219.174/24",
"10.78.70.74/23"
],
"balancer": "roundrobin",
"restrict": false,
"fallback_delay": "350ms"
}
}

View file

@ -240,3 +240,12 @@ runtime:
audit:
enabled: true
multinet:
enabled: true
subnets:
- 192.168.219.174/24
- 10.78.70.74/23
balancer: roundrobin
restrict: false
fallback_delay: 350ms

View file

@ -25,8 +25,8 @@ There are some custom types used for brevity:
| `replicator` | [Replicator service configuration](#replicator-section) |
| `storage` | [Storage engine configuration](#storage-section) |
| `runtime` | [Runtime configuration](#runtime-section) |
| `audit` | [Audit configuration](#audit-section) |
| `audit` | [Audit configuration](#audit-section) |
| `multinet` | [Multinet configuration](#audit-section) |
# `control` section
```yaml
@ -435,6 +435,29 @@ audit:
enabled: true
```
| Parameter | Type | Default value | Description |
|---------------------|--------|---------------|---------------------------------------------------|
| `soft_memory_limit` | `bool` | false | If `true` then audit event logs will be recorded. |
| Parameter | Type | Default value | Description |
|-----------|--------|---------------|---------------------------------------------------|
| `enabled` | `bool` | false | If `true` then audit event logs will be recorded. |
# `multinet` section
Contains multinet parameters.
```yaml
multinet:
enabled: true
subnets:
- 192.168.219.174/24
- 10.78.70.74/23
balancer: roundrobin
restrict: false
fallback_delay: 350ms
```
| Parameter | Type | Default value | Description |
| ---------------- | ---------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `enabled` | `bool` | false | If `true` then source-based routing is enabled. |
| `subnets` | `[]string` | empty | Resulting subnets. |
| `balancer` | `string` | "" | Balancer to select network interfaces, allowed values are "" (no balancing, use first suitable interface) or "roundrobin". |
| `restrict` | `bool` | false | If `true` then any requests that do not match `subnets` will fail. |
| `fallback_delay` | `duration` | 350ms | Delay before fallback to secondary IP addresses in case of hostname resolve. |