config

package
v3.0.0-...-83eac60 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright (c) F5, Inc.

This source code is licensed under the Apache License, Version 2.0 license found in the LICENSE file in the root directory of this source tree.

Copyright (c) F5, Inc.

This source code is licensed under the Apache License, Version 2.0 license found in the LICENSE file in the root directory of this source tree.

Index

Constants

View Source
const (
	ConfigFileName = "nginx-agent.conf"
	EnvPrefix      = "NGINX_AGENT"
	KeyDelimiter   = "_"
)
View Source
const (
	DefGracefulShutdownPeriod      = 5 * time.Second
	DefNginxReloadMonitoringPeriod = 10 * time.Second
	DefTreatErrorsAsWarnings       = true

	DefCollectorConfigPath = "/var/run/nginx-agent-otelcol.yaml"

	DefCommandServerHostKey    = ""
	DefCommandServerPortKey    = 0
	DefCommandServerTypeKey    = "grpc"
	DefCommandAuthTokenKey     = ""
	DefCommandTLSCertKey       = ""
	DefCommandTLSKeyKey        = ""
	DefCommandTLSCaKey         = ""
	DefCommandTLSSkipVerifyKey = false

	DefBackoffInitialInterval = 50 * time.Millisecond
	// the value is 0 <= and < 1
	DefBackoffRandomizationFactor = 0.1
	DefBackoffMultiplier          = 1.5
	DefBackoffMaxInterval         = 200 * time.Millisecond
	DefBackoffMaxElapsedTime      = 3 * time.Second

	DefInstanceWatcherMonitoringFrequency       = 5 * time.Second
	DefInstanceHealthWatcherMonitoringFrequency = 5 * time.Second
)
View Source
const (
	ClientRootKey                               = "client"
	ConfigDirectoriesKey                        = "config_dirs"
	ConfigPathKey                               = "path"
	CommandRootKey                              = "command"
	DataPlaneConfigRootKey                      = "data_plane_config"
	LogLevelRootKey                             = "log"
	CollectorRootKey                            = "collector"
	VersionKey                                  = "version"
	UUIDKey                                     = "uuid"
	InstanceWatcherMonitoringFrequencyKey       = "watchers_instance_watcher_monitoring_frequency"
	InstanceHealthWatcherMonitoringFrequencyKey = "watchers_instance_health_watcher_monitoring_frequency"
)

Variables

View Source
var (
	// child flags saved as vars to enable easier prefixing.
	ClientPermitWithoutStreamKey   = pre(ClientRootKey) + "permit_without_stream"
	ClientTimeKey                  = pre(ClientRootKey) + "time"
	ClientTimeoutKey               = pre(ClientRootKey) + "timeout"
	CollectorConfigPathKey         = pre(CollectorRootKey) + "config_path"
	CollectorExportersKey          = pre(CollectorRootKey) + "exporters"
	CollectorProcessorsKey         = pre(CollectorRootKey) + "processors"
	CollectorHealthKey             = pre(CollectorRootKey) + "health"
	CollectorReceiversKey          = pre(CollectorRootKey) + "receivers"
	CommandAuthKey                 = pre(CommandRootKey) + "auth"
	CommandAuthTokenKey            = pre(CommandAuthKey) + "token"
	CommandServerHostKey           = pre(CommandServerKey) + "host"
	CommandServerKey               = pre(CommandRootKey) + "server"
	CommandServerPortKey           = pre(CommandServerKey) + "port"
	CommandServerTypeKey           = pre(CommandServerKey) + "type"
	CommandTLSCaKey                = pre(CommandTLSKey) + "ca"
	CommandTLSCertKey              = pre(CommandTLSKey) + "cert"
	CommandTLSKey                  = pre(CommandRootKey) + "tls"
	CommandTLSKeyKey               = pre(CommandTLSKey) + "key"
	CommandTLSServerNameKey        = pre(CommandRootKey) + "server_name"
	CommandTLSSkipVerifyKey        = pre(CommandTLSKey) + "skip_verify"
	LogLevelKey                    = pre(LogLevelRootKey) + "level"
	LogPathKey                     = pre(LogLevelRootKey) + "path"
	NginxReloadMonitoringPeriodKey = pre(DataPlaneConfigRootKey, "nginx") + "reload_monitoring_period"
	NginxTreatWarningsAsErrorsKey  = pre(DataPlaneConfigRootKey, "nginx") + "treat_warnings_as_error"
	OTLPExportURLKey               = pre(CollectorRootKey) + "otlp_export_url"
	OTLPReceiverURLKey             = pre(CollectorRootKey) + "otlp_receiver_url"
)
View Source
var CompletionCommand = &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.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
	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 {
			slog.Warn("Error sending command", "error", err)
		}
	},
}
View Source
var RootCommand = &cobra.Command{
	Use:   "nginx-agent [flags]",
	Short: "nginx-agent",
}

Functions

func Execute

func Execute(ctx context.Context) error

func Init

func Init(version, commit string)

func RegisterConfigFile

func RegisterConfigFile() error

func RegisterRunner

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

Types

type AuthConfig

type AuthConfig struct {
	Token string `yaml:"-" mapstructure:"token"`
}

type Client

type Client struct {
	Timeout             time.Duration `yaml:"-" mapstructure:"timeout"`
	Time                time.Duration `yaml:"-" mapstructure:"time"`
	PermitWithoutStream bool          `yaml:"-" mapstructure:"permit_without_stream"`
}

type Collector

type Collector struct {
	ConfigPath string        `yaml:"-" mapstructure:"config_path"`
	Exporters  []Exporter    `yaml:"-" mapstructure:"exporters"`
	Health     *ServerConfig `yaml:"-" mapstructure:"health"`
	Processors []Processor   `yaml:"-" mapstructure:"processors"`
	Receivers  []Receiver    `yaml:"-" mapstructure:"receivers"`
}

func (*Collector) Validate

func (col *Collector) Validate(allowedDirectories []string) error

type Command

type Command struct {
	Server *ServerConfig `yaml:"-" mapstructure:"server"`
	Auth   *AuthConfig   `yaml:"-" mapstructure:"auth"`
	TLS    *TLSConfig    `yaml:"-" mapstructure:"tls"`
}

type CommonSettings

type CommonSettings struct {
	InitialInterval     time.Duration `yaml:"-" mapstructure:"initial_interval"`
	MaxInterval         time.Duration `yaml:"-" mapstructure:"max_interval"`
	MaxElapsedTime      time.Duration `yaml:"-" mapstructure:"max_elapsed_time"`
	RandomizationFactor float64       `yaml:"-" mapstructure:"randomization_factor"`
	Multiplier          float64       `yaml:"-" mapstructure:"multiplier"`
}

type Config

type Config struct {
	UUID               string           `yaml:"-"`
	Version            string           `yaml:"-"`
	Path               string           `yaml:"-"`
	Log                *Log             `yaml:"-" mapstructure:"log"`
	DataPlaneConfig    *DataPlaneConfig `yaml:"-" mapstructure:"data_plane_config"`
	Client             *Client          `yaml:"-" mapstructure:"client"`
	ConfigDir          string           `yaml:"-" mapstructure:"config-dirs"`
	AllowedDirectories []string         `yaml:"-"`
	Collector          *Collector       `yaml:"-" mapstructure:"collector"`
	Command            *Command         `yaml:"-" mapstructure:"command"`
	File               *File            `yaml:"-" mapstructure:"file"`
	Common             *CommonSettings  `yaml:"-"`
	Watchers           *Watchers        `yaml:"-"`
}

func ResolveConfig

func ResolveConfig() (*Config, error)

func (*Config) IsDirectoryAllowed

func (c *Config) IsDirectoryAllowed(directory string) bool

type DataPlaneConfig

type DataPlaneConfig struct {
	Nginx *NginxDataPlaneConfig `yaml:"-" mapstructure:"nginx"`
}

type Exporter

type Exporter struct {
	Type   string        `yaml:"-" mapstructure:"type"`
	Server *ServerConfig `yaml:"-" mapstructure:"server"`
	Auth   *AuthConfig   `yaml:"-" mapstructure:"auth"`
	TLS    *TLSConfig    `yaml:"-" mapstructure:"tls"`
}

OTel Collector Exporter configuration.

type File

type File struct {
	Location string `yaml:"-" mapstructure:"location"`
}

type GRPC

type GRPC struct {
	Target         string        `yaml:"-" mapstructure:"target"`
	ConnTimeout    time.Duration `yaml:"-" mapstructure:"connection_timeout"`
	MinConnTimeout time.Duration `yaml:"-" mapstructure:"minimum_connection_timeout"`
	BackoffDelay   time.Duration `yaml:"-" mapstructure:"backoff_delay"`
}

type InstanceHealthWatcher

type InstanceHealthWatcher struct {
	MonitoringFrequency time.Duration `yaml:"-" mapstructure:"monitoring_frequency"`
}

type InstanceWatcher

type InstanceWatcher struct {
	MonitoringFrequency time.Duration `yaml:"-" mapstructure:"monitoring_frequency"`
}

type Log

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

type NginxDataPlaneConfig

type NginxDataPlaneConfig struct {
	ReloadMonitoringPeriod time.Duration `yaml:"-" mapstructure:"reload_monitoring_period"`
	TreatWarningsAsError   bool          `yaml:"-" mapstructure:"treat_warnings_as_error"`
}

type Processor

type Processor struct {
	Type string `yaml:"-" mapstructure:"type"`
}

OTel Collector Processor configuration.

type Receiver

type Receiver struct {
	Type   string        `yaml:"-" mapstructure:"type"`
	Server *ServerConfig `yaml:"-" mapstructure:"server"`
	Auth   *AuthConfig   `yaml:"-" mapstructure:"auth"`
	TLS    *TLSConfig    `yaml:"-" mapstructure:"tls"`
}

OTel Collector Receiver configuration.

type ServerConfig

type ServerConfig struct {
	Host string     `yaml:"-" mapstructure:"host"`
	Port int        `yaml:"-" mapstructure:"port"`
	Type ServerType `yaml:"-" mapstructure:"type"`
}

type ServerType

type ServerType int
const (
	Grpc ServerType = iota + 1
)

type TLSConfig

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

type Watchers

type Watchers struct {
	InstanceWatcher       InstanceWatcher       `yaml:"-" mapstructure:"instance_watcher"`
	InstanceHealthWatcher InstanceHealthWatcher `yaml:"-" mapstructure:"instance_health_watcher"`
}

Jump to

Keyboard shortcuts

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