config

package
v2.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DynamicConfigFileName    = "agent-dynamic.conf"
	DynamicConfigFileAbsPath = "/etc/nginx-agent/agent-dynamic.conf"
	ConfigFileName           = "nginx-agent.conf"
	ConfigFileType           = "yaml"
	KeyDelimiter             = "_"
	EnvPrefix                = "nms"
	ConfigPathKey            = "path"
	DynamicConfigPathKey     = "dynamic-config-path"

	CloudAccountIdKey = "cloudaccountid"
	LocationKey       = "location"
	DisplayNameKey    = "display_name"
	InstanceGroupKey  = "instance_group"
	ConfigDirsKey     = "config_dirs"
	TagsKey           = "tags"

	// viper keys used in config
	LogKey = "log"

	LogLevel = LogKey + KeyDelimiter + "level"
	LogPath  = LogKey + KeyDelimiter + "path"

	// viper keys used in config
	ServerKey = "server"

	ServerHost     = ServerKey + KeyDelimiter + "host"
	ServerGrpcport = ServerKey + KeyDelimiter + "grpcport"
	ServerToken    = ServerKey + KeyDelimiter + "token"
	ServerMetrics  = ServerKey + KeyDelimiter + "metrics"
	ServerCommand  = ServerKey + KeyDelimiter + "command"

	// viper keys used in config
	TlsKey = "tls"

	TlsEnable     = TlsKey + KeyDelimiter + "enable"
	TlsCert       = TlsKey + KeyDelimiter + "cert"
	TlsPrivateKey = TlsKey + KeyDelimiter + "key"
	TlsCa         = TlsKey + KeyDelimiter + "ca"
	TlsSkipVerify = TlsKey + KeyDelimiter + "skip_verify"

	// viper keys used in config
	NginxKey = "nginx"

	NginxExcludeLogs    = NginxKey + KeyDelimiter + "exclude_logs"
	NginxDebug          = NginxKey + KeyDelimiter + "debug"
	NginxCountingSocket = NginxKey + KeyDelimiter + "socket"

	// viper keys used in config
	DataplaneKey = "dataplane"

	DataplaneEventsEnable         = DataplaneKey + KeyDelimiter + "events_enable"
	DataplaneSyncEnable           = DataplaneKey + KeyDelimiter + "sync_enable"
	DataplaneStatusPoll           = DataplaneKey + KeyDelimiter + "status_poll_interval"
	DataplaneStatusReportInterval = DataplaneKey + KeyDelimiter + "report_interval"

	// viper keys used in config
	MetricsKey = "metrics"

	MetricsBulkSize           = MetricsKey + KeyDelimiter + "bulk_size"
	MetricsReportInterval     = MetricsKey + KeyDelimiter + "report_interval"
	MetricsCollectionInterval = MetricsKey + KeyDelimiter + "collection_interval"
	MetricsMode               = MetricsKey + KeyDelimiter + "mode"

	// viper keys used in config
	AdvancedMetricsKey = "advanced_metrics"

	AdvancedMetricsSocketPath           = AdvancedMetricsKey + KeyDelimiter + "socket_path"
	AdvancedMetricsAggregationPeriod    = AdvancedMetricsKey + KeyDelimiter + "aggregation_period"
	AdvancedMetricsPublishPeriod        = AdvancedMetricsKey + KeyDelimiter + "publishing_period"
	AdvancedMetricsTableSizesLimits     = AdvancedMetricsKey + KeyDelimiter + "table_sizes_limits"
	AdvancedMetricsTableSizesLimitsSTMS = AdvancedMetricsTableSizesLimits + KeyDelimiter + "staging_table_max_size"
	AdvancedMetricsTableSizesLimitsSTT  = AdvancedMetricsTableSizesLimits + KeyDelimiter + "staging_table_threshold"
	AdvancedMetricsTableSizesLimitsPTMS = AdvancedMetricsTableSizesLimits + KeyDelimiter + "priority_table_max_size"
	AdvancedMetricsTableSizesLimitsPTT  = AdvancedMetricsTableSizesLimits + KeyDelimiter + "priority_table_threshold"

	// viper keys used in config
	NginxAppProtectKey = "nginx_app_protect"

	NginxAppProtectReportInterval = NginxAppProtectKey + KeyDelimiter + "report_interval"

	// DEPRECATED KEYS
	NginxBinPathKey       = "nginx_bin_path"
	NginxPIDPathKey       = "nginx_pid_path"
	NginxStubStatusURLKey = "nginx_stub_status"
	NginxPlusAPIURLKey    = "nginx_plus_api"
	NginxMetricsPollKey   = "nginx_metrics_poll_interval"

	MetricsEnableTLSKey   = "metrics_tls_enable"
	MetricsTLSCertPathKey = "metrics_tls_cert"
	MetricsTLSKeyPathKey  = "metrics_tls_key"
	MetricsTLSCAPathKey   = "metrics_tls_ca"
)

Variables

View Source
var (
	Defaults = &Config{
		CloudAccountID: uuid.New().String(),
		Log: LogConfig{
			Level: "info",
			Path:  "/var/log/nginx-agent",
		},
		Server: Server{
			Host:     "127.0.0.1",
			GrpcPort: 443,
			Command:  "",
			Metrics:  "",

			Token: uuid.New().String(),
		},
		Nginx: Nginx{
			Debug:               false,
			NginxCountingSocket: "unix:/var/run/nginx-agent/nginx.sock",
		},
		ConfigDirs:            "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms",
		AllowedDirectoriesMap: map[string]struct{}{},
		TLS: TLSConfig{
			Enable:     false,
			SkipVerify: false,
		},
		Dataplane: Dataplane{
			Status: Status{
				PollInterval:   30 * time.Second,
				ReportInterval: 24 * time.Hour,
			},
		},
		AgentMetrics: AgentMetrics{
			BulkSize:           20,
			ReportInterval:     1 * time.Minute,
			CollectionInterval: 15 * time.Second,
			Mode:               "aggregation",
		},
		AdvancedMetrics: AdvancedMetrics{
			SocketPath:        "/tmp/advanced-metrics.sock",
			AggregationPeriod: time.Second * 10,
			PublishingPeriod:  time.Second * 30,
			TableSizesLimits: advanced_metrics.TableSizesLimits{
				StagingTableThreshold:  1000,
				StagingTableMaxSize:    1000,
				PriorityTableThreshold: 1000,
				PriorityTableMaxSize:   1000,
			},
		},
	}
	AllowedDirectoriesMap map[string]struct{}
)
View Source
var COMPLETION_COMMAND = &cobra.Command{
	Use:   "completion [bash|zsh|fish]",
	Short: "Generate completion script.",
	Long: `To load completions:

Bash:

$ source <(nginx-agent completion bash)

# To load completions for each session, execute once:
Linux:
  $ nginx-agent completion bash > /etc/bash_completion.d/nginx-agent
MacOS:
  $ nginx-agent completion bash > /usr/local/etc/bash_completion.d/nginx-agent

Zsh:

# If shell completion is not already enabled in your environment you will need
# to enable it.  You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ nginx-agent completion zsh > "${fpath[1]}/_nginx-agent"

# You will need to start a new shell for this setup to take effect.

Fish:

$ nginx-agent completion fish | source

# To load completions for each session, execute once:
$ nginx-agent completion fish > ~/.config/fish/completions/nginx-agent.fish
`,
	DisableFlagsInUseLine: true,
	ValidArgs:             []string{"bash", "zsh", "fish"},
	Args:                  cobra.ExactValidArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var err error

		switch args[0] {
		case "bash":
			err = cmd.Root().GenBashCompletion(os.Stdout)
		case "zsh":
			err = cmd.Root().GenZshCompletion(os.Stdout)
		case "fish":
			err = cmd.Root().GenFishCompletion(os.Stdout, true)
		}

		if err != nil {
			log.Warnf("Error sending command: %v", err)
		}
	},
}
View Source
var ROOT_COMMAND = &cobra.Command{
	Use:   "nginx-agent [flags]",
	Short: "nginx-agent",
}

Functions

func CheckAndSetDefault

func CheckAndSetDefault(attribute interface{}, defaultValue interface{})

func ConfigFilePaths

func ConfigFilePaths() []string

func Execute

func Execute() error

func LoadPropertiesFromFile

func LoadPropertiesFromFile(cfg string) error

func RegisterConfigFile

func RegisterConfigFile(dynamicConfFilePath string, confFileName string, confPaths ...string) (string, error)

func RegisterFlags

func RegisterFlags()

func RegisterRunner

func RegisterRunner(r func(cmd *cobra.Command, args []string))

func SeekConfigFileInPaths

func SeekConfigFileInPaths(configName string, searchPaths ...string) (string, error)

func SetAdvancedMetricsDefaults

func SetAdvancedMetricsDefaults()

func SetDefaults

func SetDefaults()

func SetDynamicConfigFileAbsPath

func SetDynamicConfigFileAbsPath(dynamicCfgPath string)

func SetNginxAppProtectDefaults

func SetNginxAppProtectDefaults()

func SetVersion

func SetVersion(version, commit string)

func UpdateAgentConfig

func UpdateAgentConfig(systemId string, updateTags []string) (bool, error)

UpdateAgentConfig updates the Agent config on disk with the tags that are passed into it. A bool is returned indicating if the Agent config was overwritten or not.

Types

type AdvancedMetrics

type AdvancedMetrics struct {
	SocketPath        string                            `mapstructure:"socket_path" yaml:"-"`
	AggregationPeriod time.Duration                     `mapstructure:"aggregation_period" yaml:"-"`
	PublishingPeriod  time.Duration                     `mapstructure:"publishing_period" yaml:"-"`
	TableSizesLimits  advanced_metrics.TableSizesLimits `mapstructure:"table_sizes_limits" yaml:"-"`
}

type AgentMetrics

type AgentMetrics struct {
	BulkSize           int           `mapstructure:"bulk_size" yaml:"-"`
	ReportInterval     time.Duration `mapstructure:"report_interval" yaml:"-"`
	CollectionInterval time.Duration `mapstructure:"collection_interval" yaml:"-"`
	Mode               string        `mapstructure:"mode" yaml:"-"`
}

AgentMetrics for system/agent metrics

type BoolFlag

type BoolFlag struct {
	Name         string
	Usage        string
	DefaultValue bool
}

type Config

type Config struct {
	Path                  string              `yaml:"-"`
	DynamicConfigPath     string              `yaml:"-"`
	ClientID              string              `mapstructure:"agent_id" yaml:"-"`
	CloudAccountID        string              `mapstructure:"cloud_account" yaml:"-"`
	Server                Server              `mapstructure:"server" yaml:"-"`
	ConfigDirs            string              `mapstructure:"config-dirs" yaml:"-"`
	Log                   LogConfig           `mapstructure:"log" yaml:"-"`
	TLS                   TLSConfig           `mapstructure:"tls" yaml:"-"`
	Nginx                 Nginx               `mapstructure:"nginx" yaml:"-"`
	Dataplane             Dataplane           `mapstructure:"dataplane" yaml:"-"`
	AgentMetrics          AgentMetrics        `mapstructure:"metrics" yaml:"-"`
	Tags                  []string            `mapstructure:"tags" yaml:"tags,omitempty"`
	Updated               time.Time           `yaml:"-"` // update time of the config file
	AllowedDirectoriesMap map[string]struct{} `yaml:"-"`
	DisplayName           string              `mapstructure:"display_name" yaml:"display_name,omitempty"`
	InstanceGroup         string              `mapstructure:"instance_group" yaml:"instance_group,omitempty"`
	AdvancedMetrics       AdvancedMetrics     `mapstructure:"advanced_metrics" yaml:"advanced_metrics,omitempty"`
	NginxAppProtect       NginxAppProtect     `mapstructure:"nginx_app_protect" yaml:"nginx_app_protect,omitempty"`
}

func GetConfig

func GetConfig(clientId string) (*Config, error)

type Dataplane

type Dataplane struct {
	Status Status `mapstructure:"status" yaml:"-"`
}

type DurationFlag

type DurationFlag struct {
	Name         string
	Usage        string
	DefaultValue time.Duration
}

type IntFlag

type IntFlag struct {
	Name         string
	Usage        string
	DefaultValue int
}

type LogConfig

type LogConfig struct {
	Level string `mapstructure:"level" yaml:"-"`
	Path  string `mapstructure:"path" yaml:"-"`
}

LogConfig for logging

type Nginx

type Nginx struct {
	ExcludeLogs         string `mapstructure:"exclude_logs" yaml:"-"`
	Debug               bool   `mapstructure:"debug" yaml:"-"`
	NginxCountingSocket string `mapstructure:"socket" yaml:"-"`
}

Nginx settings

type NginxAppProtect

type NginxAppProtect struct {
	ReportInterval time.Duration `mapstructure:"report_interval" yaml:"-"`
}

type Registrable

type Registrable interface {
	// contains filtered or unexported methods
}

Registrable registers a pflag

type Server

type Server struct {
	Host     string `mapstructure:"host" yaml:"-"`
	GrpcPort int    `mapstructure:"grpcPort" yaml:"-"`
	Token    string `mapstructure:"token" yaml:"-"`
	Metrics  string `mapstructure:"metrics" yaml:"-"`
	Command  string `mapstructure:"command" yaml:"-"`
	// This is internal and shouldnt be exposed as a flag
	Target string `mapstructure:"target" yaml:"-"`
}

type Status

type Status struct {
	PollInterval   time.Duration `mapstructure:"poll_interval" yaml:"-"`
	ReportInterval time.Duration `mapstructure:"report_interval" yaml:"-"`
}

Status polling for heartbeat settings

type StringFlag

type StringFlag struct {
	Name         string
	Usage        string
	DefaultValue string
}

type StringMapFlag

type StringMapFlag struct {
	Name         string
	Usage        string
	DefaultValue map[string]string
}

type StringSliceFlag

type StringSliceFlag struct {
	Name         string
	Usage        string
	DefaultValue []string
}

type TLSConfig

type TLSConfig struct {
	Enable     bool   `mapstructure:"enable" yaml:"-"`
	Cert       string `mapstructure:"cert" yaml:"-"`
	Key        string `mapstructure:"key" yaml:"-"`
	Ca         string `mapstructure:"ca" yaml:"-"`
	SkipVerify bool   `mapstructure:"skip_verify" yaml:"-"`
}

TLSConfig for securing communications

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL