config

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 12 Imported by: 62

Documentation

Overview

Package config provides general configuration mechanism.

Index

Constants

View Source
const (
	// UnknownProjectName represents the "default" value
	// that indicates the project name is absent.
	UnknownProjectName = "unknown_go_service"

	ConfFilePathEnvKey = "SENTINEL_CONFIG_FILE_PATH"
	AppNameEnvKey      = "SENTINEL_APP_NAME"
	AppTypeEnvKey      = "SENTINEL_APP_TYPE"
	LogDirEnvKey       = "SENTINEL_LOG_DIR"
	LogNamePidEnvKey   = "SENTINEL_LOG_USE_PID"

	DefaultConfigFilename       = "sentinel.yml"
	DefaultAppType        int32 = 0

	DefaultMetricLogFlushIntervalSec   uint32 = 1
	DefaultMetricLogSingleFileMaxSize  uint64 = 1024 * 1024 * 50
	DefaultMetricLogMaxFileAmount      uint32 = 8
	DefaultSystemStatCollectIntervalMs uint32 = 1000
	DefaultLoadStatCollectIntervalMs   uint32 = 1000
	DefaultCpuStatCollectIntervalMs    uint32 = 1000
	DefaultMemoryStatCollectIntervalMs uint32 = 150
	DefaultWarmUpColdFactor            uint32 = 3
)

Variables

This section is empty.

Functions

func AppName

func AppName() string

func AppType

func AppType() int32

func CheckValid added in v0.5.0

func CheckValid(entity *Entity) error

func CpuStatCollectIntervalMs added in v1.0.3

func CpuStatCollectIntervalMs() uint32

func GetDefaultLogDir

func GetDefaultLogDir() string

func GlobalStatisticBucketLengthInMs added in v1.0.0

func GlobalStatisticBucketLengthInMs() uint32

func GlobalStatisticIntervalMsTotal added in v1.0.0

func GlobalStatisticIntervalMsTotal() uint32

func GlobalStatisticSampleCountTotal added in v1.0.0

func GlobalStatisticSampleCountTotal() uint32

func InitConfigWithYaml added in v1.0.0

func InitConfigWithYaml(filePath string) (err error)

InitConfigWithYaml loads general configuration from the YAML file under provided path.

func LoadStatCollectIntervalMs added in v1.0.3

func LoadStatCollectIntervalMs() uint32

func LogBaseDir

func LogBaseDir() string

func LogUsePid

func LogUsePid() bool

LogUsePid returns whether the log file name contains the PID suffix.

func Logger added in v0.6.0

func Logger() logging.Logger

func MemoryStatCollectIntervalMs added in v1.0.3

func MemoryStatCollectIntervalMs() uint32

func MetricExportHTTPAddr added in v1.0.4

func MetricExportHTTPAddr() string

func MetricExportHTTPPath added in v1.0.4

func MetricExportHTTPPath() string

func MetricLogFlushIntervalSec

func MetricLogFlushIntervalSec() uint32

func MetricLogMaxFileAmount

func MetricLogMaxFileAmount() uint32

func MetricLogSingleFileMaxSize

func MetricLogSingleFileMaxSize() uint64

func MetricStatisticIntervalMs added in v1.0.0

func MetricStatisticIntervalMs() uint32

func MetricStatisticSampleCount added in v1.0.0

func MetricStatisticSampleCount() uint32

func OverrideConfigFromEnvAndInitLog added in v0.5.0

func OverrideConfigFromEnvAndInitLog() error

func ResetGlobalConfig added in v1.0.0

func ResetGlobalConfig(config *Entity)

func SystemStatCollectIntervalMs

func SystemStatCollectIntervalMs() uint32

func UseCacheTime added in v0.4.0

func UseCacheTime() bool

Types

type Entity

type Entity struct {
	// Version represents the format version of the entity.
	Version string

	Sentinel SentinelConfig
}

func NewDefaultConfig

func NewDefaultConfig() *Entity

NewDefaultConfig creates a new default config entity.

func (*Entity) AppName added in v0.5.0

func (entity *Entity) AppName() string

func (*Entity) AppType added in v0.5.0

func (entity *Entity) AppType() int32

func (*Entity) CpuStatCollectIntervalMs added in v1.0.3

func (entity *Entity) CpuStatCollectIntervalMs() uint32

func (*Entity) GlobalStatisticIntervalMsTotal added in v1.0.0

func (entity *Entity) GlobalStatisticIntervalMsTotal() uint32

func (*Entity) GlobalStatisticSampleCountTotal added in v1.0.0

func (entity *Entity) GlobalStatisticSampleCountTotal() uint32

func (*Entity) LoadStatCollectIntervalMs added in v1.0.3

func (entity *Entity) LoadStatCollectIntervalMs() uint32

func (*Entity) LogBaseDir added in v0.5.0

func (entity *Entity) LogBaseDir() string

func (*Entity) LogUsePid added in v0.5.0

func (entity *Entity) LogUsePid() bool

LogUsePid returns whether the log file name contains the PID suffix.

func (*Entity) Logger added in v0.6.0

func (entity *Entity) Logger() logging.Logger

func (*Entity) MemoryStatCollectIntervalMs added in v1.0.3

func (entity *Entity) MemoryStatCollectIntervalMs() uint32

func (*Entity) MetricExportHTTPAddr added in v1.0.4

func (entity *Entity) MetricExportHTTPAddr() string

func (*Entity) MetricExportHTTPPath added in v1.0.4

func (entity *Entity) MetricExportHTTPPath() string

func (*Entity) MetricLogFlushIntervalSec added in v0.5.0

func (entity *Entity) MetricLogFlushIntervalSec() uint32

func (*Entity) MetricLogMaxFileAmount added in v0.5.0

func (entity *Entity) MetricLogMaxFileAmount() uint32

func (*Entity) MetricLogSingleFileMaxSize added in v0.5.0

func (entity *Entity) MetricLogSingleFileMaxSize() uint64

func (*Entity) MetricStatisticIntervalMs added in v1.0.0

func (entity *Entity) MetricStatisticIntervalMs() uint32

func (*Entity) MetricStatisticSampleCount added in v1.0.0

func (entity *Entity) MetricStatisticSampleCount() uint32

func (*Entity) String added in v1.0.0

func (entity *Entity) String() string

func (*Entity) SystemStatCollectIntervalMs added in v0.5.0

func (entity *Entity) SystemStatCollectIntervalMs() uint32

func (*Entity) UseCacheTime added in v0.5.0

func (entity *Entity) UseCacheTime() bool

type ExporterConfig added in v1.0.4

type ExporterConfig struct {
	Metric MetricExporterConfig
}

ExporterConfig represents configuration items related to exporter, like metric exporter.

type LogConfig

type LogConfig struct {
	// Logger indicates that using logger to replace default logging.
	Logger logging.Logger
	// Dir represents the log directory path.
	Dir string
	// UsePid indicates whether the filename ends with the process ID (PID).
	UsePid bool `yaml:"usePid"`
	// Metric represents the configuration items of the metric log.
	Metric MetricLogConfig
}

LogConfig represent the configuration of logging in Sentinel.

type MetricExporterConfig added in v1.0.4

type MetricExporterConfig struct {
	// HttpAddr is the http server listen address, like ":8080".
	HttpAddr string `yaml:"http_addr"`
	// HttpPath is the http request path of access metrics, like "/metrics".
	HttpPath string `yaml:"http_path"`
}

MetricExporterConfig represents configuration of metric exporter.

type MetricLogConfig

type MetricLogConfig struct {
	SingleFileMaxSize uint64 `yaml:"singleFileMaxSize"`
	MaxFileCount      uint32 `yaml:"maxFileCount"`
	FlushIntervalSec  uint32 `yaml:"flushIntervalSec"`
}

MetricLogConfig represents the configuration items of the metric log.

type SentinelConfig

type SentinelConfig struct {
	App struct {
		// Name represents the name of current running service.
		Name string
		// Type indicates the classification of the service (e.g. web service, API gateway).
		Type int32
	}
	// Exporter represents configuration items related to exporter, like metric exporter.
	Exporter ExporterConfig
	// Log represents configuration items related to logging.
	Log LogConfig
	// Stat represents configuration items related to statistics.
	Stat StatConfig
	// UseCacheTime indicates whether to cache time(ms)
	UseCacheTime bool `yaml:"useCacheTime"`
}

SentinelConfig represent the general configuration of Sentinel.

type StatConfig

type StatConfig struct {
	// GlobalStatisticSampleCountTotal and GlobalStatisticIntervalMsTotal is the per resource's global default statistic sliding window config
	GlobalStatisticSampleCountTotal uint32 `yaml:"globalStatisticSampleCountTotal"`
	GlobalStatisticIntervalMsTotal  uint32 `yaml:"globalStatisticIntervalMsTotal"`

	// MetricStatisticSampleCount and MetricStatisticIntervalMs is the per resource's default readonly metric statistic
	// This default readonly metric statistic must be reusable based on global statistic.
	MetricStatisticSampleCount uint32 `yaml:"metricStatisticSampleCount"`
	MetricStatisticIntervalMs  uint32 `yaml:"metricStatisticIntervalMs"`

	System SystemStatConfig `yaml:"system"`
}

StatConfig represents the configuration items of statistics.

type SystemStatConfig

type SystemStatConfig struct {
	// CollectIntervalMs represents the collecting interval of the system metrics collector.
	CollectIntervalMs uint32 `yaml:"collectIntervalMs"`
	// CollectLoadIntervalMs represents the collecting interval of the system load collector.
	CollectLoadIntervalMs uint32 `yaml:"collectLoadIntervalMs"`
	// CollectCpuIntervalMs represents the collecting interval of the system cpu usage collector.
	CollectCpuIntervalMs uint32 `yaml:"collectCpuIntervalMs"`
	// CollectMemoryIntervalMs represents the collecting interval of the system memory usage collector.
	CollectMemoryIntervalMs uint32 `yaml:"collectMemoryIntervalMs"`
}

SystemStatConfig represents the configuration items of system statistics.

Jump to

Keyboard shortcuts

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