-
Notifications
You must be signed in to change notification settings - Fork 291
/
config.go
123 lines (104 loc) · 4.01 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package main
import (
"fmt"
"os"
"time"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"github.com/daos-stack/daos/src/control/build"
"github.com/daos-stack/daos/src/control/common"
"github.com/daos-stack/daos/src/control/lib/daos"
"github.com/daos-stack/daos/src/control/security"
)
const (
defaultConfigFile = "daos_agent.yml"
defaultRuntimeDir = "/var/run/daos_agent"
)
type refreshMinutes time.Duration
func (rm *refreshMinutes) UnmarshalYAML(unmarshal func(interface{}) error) error {
var mins uint
if err := unmarshal(&mins); err != nil {
return err
}
*rm = refreshMinutes(time.Duration(mins) * time.Minute)
return nil
}
func (rm refreshMinutes) Duration() time.Duration {
return time.Duration(rm)
}
// Config defines the agent configuration.
type Config struct {
SystemName string `yaml:"name"`
AccessPoints []string `yaml:"access_points"`
ControlPort int `yaml:"port"`
RuntimeDir string `yaml:"runtime_dir"`
LogFile string `yaml:"log_file"`
LogLevel common.ControlLogLevel `yaml:"control_log_mask,omitempty"`
TransportConfig *security.TransportConfig `yaml:"transport_config"`
DisableCache bool `yaml:"disable_caching,omitempty"`
CacheExpiration refreshMinutes `yaml:"cache_expiration,omitempty"`
DisableAutoEvict bool `yaml:"disable_auto_evict,omitempty"`
EvictOnStart bool `yaml:"enable_evict_on_start,omitempty"`
ExcludeFabricIfaces common.StringSet `yaml:"exclude_fabric_ifaces,omitempty"`
FabricInterfaces []*NUMAFabricConfig `yaml:"fabric_ifaces,omitempty"`
ProviderIdx uint // TODO SRS-31: Enable with multiprovider functionality
TelemetryPort int `yaml:"telemetry_port,omitempty"`
TelemetryEnabled bool `yaml:"telemetry_enabled,omitempty"`
TelemetryRetain time.Duration `yaml:"telemetry_retain,omitempty"`
}
// TelemetryExportEnabled returns true if client telemetry export is enabled.
func (c *Config) TelemetryExportEnabled() bool {
return c.TelemetryPort > 0
}
// NUMAFabricConfig defines a list of fabric interfaces that belong to a NUMA
// node.
type NUMAFabricConfig struct {
NUMANode int `yaml:"numa_node"`
Interfaces []*FabricInterfaceConfig `yaml:"devices"`
}
// FabricInterfaceConfig defines a specific fabric interface device.
type FabricInterfaceConfig struct {
Interface string `yaml:"iface"`
Domain string `yaml:"domain"`
}
// LoadConfig reads a config file and uses it to populate a Config.
func LoadConfig(cfgPath string) (*Config, error) {
if cfgPath == "" {
return nil, errors.New("no config path supplied")
}
data, err := os.ReadFile(cfgPath)
if err != nil {
return nil, errors.Wrap(err, "reading config file")
}
cfg := DefaultConfig()
if err := yaml.UnmarshalStrict(data, cfg); err != nil {
return nil, errors.Wrapf(err, "parsing config: %s", cfgPath)
}
if !daos.SystemNameIsValid(cfg.SystemName) {
return nil, fmt.Errorf("invalid system name: %s", cfg.SystemName)
}
if cfg.TelemetryRetain > 0 && cfg.TelemetryPort == 0 {
return nil, errors.New("telemetry_retain requires telemetry_port")
}
if cfg.TelemetryEnabled && cfg.TelemetryPort == 0 {
return nil, errors.New("telemetry_enabled requires telemetry_port")
}
return cfg, nil
}
// DefaultConfig creates a basic default configuration.
func DefaultConfig() *Config {
localServer := fmt.Sprintf("localhost:%d", build.DefaultControlPort)
return &Config{
SystemName: build.DefaultSystemName,
ControlPort: build.DefaultControlPort,
AccessPoints: []string{localServer},
RuntimeDir: defaultRuntimeDir,
LogLevel: common.DefaultControlLogLevel,
TransportConfig: security.DefaultAgentTransportConfig(),
}
}