Compare commits

...

3 commits

Author SHA1 Message Date
13dd4ec563 [#238] node: Read cfg from dir even if cfg file not set
All checks were successful
ci/woodpecker/pr/pre-commit Pipeline was successful
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-04-14 12:07:27 +03:00
03a8436d2b [#238] Fix golangci-lint error
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-04-14 10:28:42 +03:00
c3929ff564 [#238] Fix linter error
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-04-14 09:12:28 +03:00
7 changed files with 37 additions and 19 deletions

View file

@ -7,6 +7,7 @@ Changelog for FrostFS Node
### Changed
### Fixed
- Take network settings into account during netmap contract update (#100)
- Read config files from dir even if config file not provided via `--config` for node (#238)
### Removed
### Updated

View file

@ -0,0 +1,24 @@
package config
import (
"os"
"path"
"testing"
"github.com/spf13/cast"
"github.com/stretchr/testify/require"
)
func TestConfigDir(t *testing.T) {
dir := t.TempDir()
cfgFileName0 := path.Join(dir, "cfg_00.json")
cfgFileName1 := path.Join(dir, "cfg_01.yml")
require.NoError(t, os.WriteFile(cfgFileName0, []byte(`{"storage":{"shard_pool_size":15}}`), 0777))
require.NoError(t, os.WriteFile(cfgFileName1, []byte("logger:\n level: debug"), 0777))
c := New(Prm{}, WithConfigDir(dir))
require.Equal(t, "debug", cast.ToString(c.Sub("logger").Value("level")))
require.EqualValues(t, 15, cast.ToUint32(c.Sub("storage").Value("shard_pool_size")))
}

View file

@ -187,4 +187,4 @@ FROSTFS_STORAGE_SHARD_1_GC_REMOVER_SLEEP_INTERVAL=5m
FROSTFS_TRACING_ENABLED=true
FROSTFS_TRACING_ENDPOINT="localhost"
FROSTFS_TRACING_EXPORTER="otlp_grpc"
FROSTFS_TRACING_EXPORTER="otlp_grpc"

View file

@ -219,4 +219,3 @@ tracing:
enabled: true
exporter: "otlp_grpc"
endpoint: "localhost"

View file

@ -490,7 +490,7 @@ const (
NetmapCantInvokeNetmapUpdatePeer = "can't invoke netmap.UpdatePeer" // Error in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapNonAlphabetModeIgnoreRemoveNodeFromSubnetNotification = "non alphabet mode, ignore remove node from subnet notification" // Info in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapCouldNotGetNetworkMapCandidates = "could not get network map candidates" // Warn in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapCouldNotUnmarshalSubnetId = "could not unmarshal subnet id" // Warn in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapCouldNotUnmarshalSubnetID = "could not unmarshal subnet id" // Warn in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapGotZeroSubnetInRemoveNodeNotification = "got zero subnet in remove node notification" // Warn in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapCouldNotIterateOverSubnetworksOfTheNode = "could not iterate over subnetworks of the node" // Warn in ../node/pkg/innerring/processors/netmap/process_peers.go
NetmapCouldNotInvokeNetmapUpdateState = "could not invoke netmap.UpdateState" // Error in ../node/pkg/innerring/processors/netmap/process_peers.go

View file

@ -159,7 +159,7 @@ func (np *Processor) processRemoveSubnetNode(ev subnetEvent.RemoveNode) {
err = subnetToRemoveFrom.Unmarshal(rawSubnet)
if err != nil {
np.log.Warn(logs.NetmapCouldNotUnmarshalSubnetId,
np.log.Warn(logs.NetmapCouldNotUnmarshalSubnetID,
zap.Error(err),
)
return

View file

@ -1,6 +1,7 @@
package config
import (
"fmt"
"os"
"path"
@ -20,7 +21,7 @@ func ReadConfigDir(v *viper.Viper, configDir string) error {
continue
}
ext := path.Ext(entry.Name())
if ext != ".yaml" && ext != ".yml" {
if ext != ".yaml" && ext != ".yml" && ext != ".json" {
continue
}
@ -33,22 +34,15 @@ func ReadConfigDir(v *viper.Viper, configDir string) error {
}
// mergeConfig reads config file and merge its content with current viper.
func mergeConfig(v *viper.Viper, fileName string) (err error) {
var cfgFile *os.File
cfgFile, err = os.Open(fileName)
func mergeConfig(v *viper.Viper, fileName string) error {
cv := viper.New()
cv.SetConfigFile(fileName)
err := cv.ReadInConfig()
if err != nil {
return err
return fmt.Errorf("failed to read config: %w", err)
}
defer func() {
errClose := cfgFile.Close()
if err == nil {
err = errClose
}
}()
if err = v.MergeConfig(cfgFile); err != nil {
return err
if err = v.MergeConfigMap(cv.AllSettings()); err != nil {
return fmt.Errorf("failed to merge config: %w", err)
}
return nil