Config

公共资源配置

alertmanagers

配置实例

alertmanagers:
- http_config:
    basic_auth:
      username: ""
      password: ""
      password_file: ""
    bearer_token: ""
    bearer_token_file: ""
    proxy_url: ""
    tls_config:
      ca_file: ""
      cert_file: ""
      key_file: ""
      server_name: ""
      insecure_skip_verify: false
  static_configs: []
  file_sd_configs:
  - files: []
    refresh_interval: 0s
  scheme: http
  path_prefix: ""
  timeout: 10s
  api_version: v2

数据结构

type AlertingConfig struct {
        Alertmanagers []AlertmanagerConfig `yaml:"alertmanagers"`
}

// AlertmanagerConfig represents a client to a cluster of Alertmanager endpoints.
type AlertmanagerConfig struct {
        HTTPClientConfig httpconfig.ClientConfig    `yaml:"http_config"`
        EndpointsConfig  httpconfig.EndpointsConfig `yaml:",inline"`
        Timeout          model.Duration             `yaml:"timeout"`
        APIVersion       APIVersion                 `yaml:"api_version"`
}

httpconfig.ClientConfig

// ClientConfig configures an HTTP client.
type ClientConfig struct {
        // The HTTP basic authentication credentials for the targets.
        BasicAuth BasicAuth `yaml:"basic_auth"`
        // The bearer token for the targets.
        BearerToken string `yaml:"bearer_token"`
        // The bearer token file for the targets.
        BearerTokenFile string `yaml:"bearer_token_file"`
        // HTTP proxy server to use to connect to the targets.
        ProxyURL string `yaml:"proxy_url"`
        // TLSConfig to use to connect to the targets.
        TLSConfig TLSConfig `yaml:"tls_config"`
        // TransportConfig for Client transport properties
        TransportConfig TransportConfig `yaml:"transport_config"`
        // ClientMetrics contains metrics that will be used to instrument
        // the client that will be created with this config.
        ClientMetrics *extpromhttp.ClientMetrics `yaml:"-"`
}

// BasicAuth configures basic authentication for HTTP clients.
type BasicAuth struct {
        Username     string `yaml:"username"`
        Password     string `yaml:"password"`
        PasswordFile string `yaml:"password_file"`
}

// TLSConfig configures TLS connections.
type TLSConfig struct {
        // The CA cert to use for the targets.
        CAFile string `yaml:"ca_file"`
        // The client cert file for the targets.
        CertFile string `yaml:"cert_file"`
        // The client key file for the targets.
        KeyFile string `yaml:"key_file"`
        // Used to verify the hostname for the targets. See https://tools.ietf.org/html/rfc4366#section-3.1
        ServerName string `yaml:"server_name"`
        // Disable target certificate validation.
        InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
}

// Transport configures client's transport properties.
type TransportConfig struct {
        MaxIdleConns          int   `yaml:"max_idle_conns"`
        MaxIdleConnsPerHost   int   `yaml:"max_idle_conns_per_host"`
        IdleConnTimeout       int64 `yaml:"idle_conn_timeout"`
        ResponseHeaderTimeout int64 `yaml:"response_header_timeout"`
        ExpectContinueTimeout int64 `yaml:"expect_continue_timeout"`
        MaxConnsPerHost       int   `yaml:"max_conns_per_host"`
        DisableCompression    bool  `yaml:"disable_compression"`
        TLSHandshakeTimeout   int64 `yaml:"tls_handshake_timeout"`
}

httpconfig.EndpointsConfig

// EndpointsConfig configures a cluster of HTTP endpoints from static addresses and
// file service discovery.
type EndpointsConfig struct {
        // List of addresses with DNS prefixes.
        StaticAddresses []string `yaml:"static_configs"`
        // List of file  configurations (our FileSD supports different DNS lookups).
        FileSDConfigs []FileSDConfig `yaml:"file_sd_configs"`

        // The URL scheme to use when talking to targets.
        Scheme string `yaml:"scheme"`

        // Path prefix to add in front of the endpoint path.
        PathPrefix string `yaml:"path_prefix"`
}

// FileSDConfig represents a file service discovery configuration.
type FileSDConfig struct {
        Files           []string       `yaml:"files"`
        RefreshInterval model.Duration `yaml:"refresh_interval"`
}

objstore

配置示例

type: S3
config:
  bucket: ""
  endpoint: ""
  region: ""
  aws_sdk_auth: false
  access_key: ""
  insecure: false
  signature_version2: false
  secret_key: ""
  put_user_metadata: {}
  http_config:
    idle_conn_timeout: 1m30s
    response_header_timeout: 2m
    insecure_skip_verify: false
    tls_handshake_timeout: 10s
    expect_continue_timeout: 1s
    max_idle_conns: 100
    max_idle_conns_per_host: 100
    max_conns_per_host: 0
    tls_config:
      ca_file: ""
      cert_file: ""
      key_file: ""
      server_name: ""
      insecure_skip_verify: false
    disable_compression: false
  trace:
    enable: false
  list_objects_version: ""
  bucket_lookup_type: auto
  part_size: 67108864
  sse_config:
    type: ""
    kms_key_id: ""
    kms_encryption_context: {}
    encryption_key: ""
  sts_endpoint: ""
prefix: ""

数据结构

type ObjProvider string

const (
        FILESYSTEM ObjProvider = "FILESYSTEM"
        GCS        ObjProvider = "GCS"
        S3         ObjProvider = "S3"
        AZURE      ObjProvider = "AZURE"
        SWIFT      ObjProvider = "SWIFT"
        COS        ObjProvider = "COS"
        ALIYUNOSS  ObjProvider = "ALIYUNOSS"
        BOS        ObjProvider = "BOS"
)

type BucketConfig struct {
        Type   ObjProvider `yaml:"type"`
        Config interface{} `yaml:"config"`
        Prefix string      `yaml:"prefix" default:""`
}
  • ObjProvider 为 FILESYSTEM 的 Config
// Config stores the configuration for storing and accessing blobs in filesystem.
type Config struct {
	Directory string `yaml:"directory"`
}
  • ObjProvider 为 S3 的 Config
// Config stores the configuration for s3 bucket.
type Config struct {
        Bucket             string            `yaml:"bucket"`
        Endpoint           string            `yaml:"endpoint"`
        Region             string            `yaml:"region"`
        AWSSDKAuth         bool              `yaml:"aws_sdk_auth"`
        AccessKey          string            `yaml:"access_key"`
        Insecure           bool              `yaml:"insecure"`
        SignatureV2        bool              `yaml:"signature_version2"`
        SecretKey          string            `yaml:"secret_key"`
        PutUserMetadata    map[string]string `yaml:"put_user_metadata"`
        HTTPConfig         HTTPConfig        `yaml:"http_config"`
        TraceConfig        TraceConfig       `yaml:"trace"`
        ListObjectsVersion string            `yaml:"list_objects_version"`
        BucketLookupType   BucketLookupType  `yaml:"bucket_lookup_type"`
        // PartSize used for multipart upload. Only used if uploaded object size is known and larger than configured PartSize.
        // NOTE we need to make sure this number does not produce more parts than 10 000.
        PartSize    uint64    `yaml:"part_size"`
        SSEConfig   SSEConfig `yaml:"sse_config"`
        STSEndpoint string    `yaml:"sts_endpoint"`
}
  • ObjProvider 为 COS 的 Config
// Config encapsulates the necessary config values to instantiate an cos client.
type Config struct {
        Bucket     string     `yaml:"bucket"`
        Region     string     `yaml:"region"`
        AppId      string     `yaml:"app_id"`
        Endpoint   string     `yaml:"endpoint"`
        SecretKey  string     `yaml:"secret_key"`
        SecretId   string     `yaml:"secret_id"`
        HTTPConfig HTTPConfig `yaml:"http_config"`
}
  • ObjProvider 为 ALIYUNOSS 的 Config
// Config stores the configuration for oss bucket.
type Config struct {
        Endpoint        string `yaml:"endpoint"`
        Bucket          string `yaml:"bucket"`
        AccessKeyID     string `yaml:"access_key_id"`
        AccessKeySecret string `yaml:"access_key_secret"`
}

query.config

配置示例

- http_config:
    basic_auth:
      username: ""
      password: ""
      password_file: ""
    bearer_token: ""
    bearer_token_file: ""
    proxy_url: ""
    tls_config:
      ca_file: ""
      cert_file: ""
      key_file: ""
      server_name: ""
      insecure_skip_verify: false
  static_configs: []
  file_sd_configs:
  - files: []
    refresh_interval: 0s
  scheme: http
  path_prefix: ""

数据结构

var queryCfg []httpconfig.Config
var err error
if len(conf.queryConfigYAML) > 0 {
    queryCfg, err = httpconfig.LoadConfigs(conf.queryConfigYAML)
    if err != nil {
        return err
    }
}

httpconfig.Config

// Config is a structure that allows pointing to various HTTP endpoint, e.g ruler connecting to queriers.
type Config struct {
        HTTPClientConfig ClientConfig    `yaml:"http_config"`
        EndpointsConfig  EndpointsConfig `yaml:",inline"`
}

其中 ClientConfig 如上。

remote-write.config

配置示例

remote_write:
- url: http://10.59.107.169:19291/api/v1/receive
  name: thanos-receiver

数据结构

var rwCfg struct {
    RemoteWriteConfigs []*config.RemoteWriteConfig `yaml:"remote_write,omitempty"`
}
  • config.RemoteWriteConfig
// RemoteWriteConfig is the configuration for writing to remote storage.
type RemoteWriteConfig struct {
	URL                 *config.URL       `yaml:"url"`
	RemoteTimeout       model.Duration    `yaml:"remote_timeout,omitempty"`
	Headers             map[string]string `yaml:"headers,omitempty"`
	WriteRelabelConfigs []*relabel.Config `yaml:"write_relabel_configs,omitempty"`
	Name                string            `yaml:"name,omitempty"`
	SendExemplars       bool              `yaml:"send_exemplars,omitempty"`

	// We cannot do proper Go type embedding below as the parser will then parse
	// values arbitrarily into the overflow maps of further-down types.
	HTTPClientConfig config.HTTPClientConfig `yaml:",inline"`
	QueueConfig      QueueConfig             `yaml:"queue_config,omitempty"`
	MetadataConfig   MetadataConfig          `yaml:"metadata_config,omitempty"`
	SigV4Config      *sigv4.SigV4Config      `yaml:"sigv4,omitempty"`
}

request.logging-config

配置示例

http:
  config:
    - path: /api/v1/query
      port: 10904
  options:
    level: DEBUG
    decision:
      log_start: true
      log_end: true

grpc:
  config:
    - service: thanos.Store
      method: Info
  options:
    level: ERROR
    decision:
      log_start: false
      log_end: true    

数据结构

type RequestConfig struct {
        HTTP    HTTPProtocolConfigs `yaml:"http"`
        GRPC    GRPCProtocolConfigs `yaml:"grpc"`
        Options OptionsConfig       `yaml:"options"`
}

type HTTPProtocolConfigs struct {
        Options OptionsConfig        `yaml:"options"`
        Config  []HTTPProtocolConfig `yaml:"config"`
}

type GRPCProtocolConfigs struct {
        Options OptionsConfig        `yaml:"options"`
        Config  []GRPCProtocolConfig `yaml:"config"`
}

type OptionsConfig struct {
        Level    string         `yaml:"level"`
        Decision DecisionConfig `yaml:"decision"`
}

type DecisionConfig struct {
        LogStart bool `yaml:"log_start"`
        LogEnd   bool `yaml:"log_end"`
}

type HTTPProtocolConfig struct {
        Path string `yaml:"path"`
        Port uint64 `yaml:"port"`
}

type GRPCProtocolConfig struct {
        Service string `yaml:"service"`
        Method  string `yaml:"method"`
}

tracing.config

配置示例

type: JAEGER
config:
  service_name: ""
  disabled: false
  rpc_metrics: false
  tags: ""
  sampler_type: ""
  sampler_param: 0
  sampler_manager_host_port: ""
  sampler_max_operations: 0
  sampler_refresh_interval: 0s
  reporter_max_queue_size: 0
  reporter_flush_interval: 0s
  reporter_log_spans: false
  endpoint: ""
  user: ""
  password: ""
  agent_host: ""
  agent_port: 0
  traceid_128bit: false

数据结构

type TracingProvider string

const (
	Stackdriver TracingProvider = "STACKDRIVER"
	GoogleCloud TracingProvider = "GOOGLE_CLOUD"
	Jaeger      TracingProvider = "JAEGER"
	ElasticAPM  TracingProvider = "ELASTIC_APM"
	Lightstep   TracingProvider = "LIGHTSTEP"
)

type TracingConfig struct {
	Type   TracingProvider `yaml:"type"`
	Config interface{}     `yaml:"config"`
}
  • TracingProvider 为 Jaeger 的 Config
// Config - YAML configuration. For details see to https://github.com/jaegertracing/jaeger-client-go#environment-variables.
type Config struct {
	ServiceName            string        `yaml:"service_name"`
	Disabled               bool          `yaml:"disabled"`
	RPCMetrics             bool          `yaml:"rpc_metrics"`
	Tags                   string        `yaml:"tags"`
	SamplerType            string        `yaml:"sampler_type"`
	SamplerParam           float64       `yaml:"sampler_param"`
	SamplerManagerHostPort string        `yaml:"sampler_manager_host_port"`
	SamplerMaxOperations   int           `yaml:"sampler_max_operations"`
	SamplerRefreshInterval time.Duration `yaml:"sampler_refresh_interval"`
	ReporterMaxQueueSize   int           `yaml:"reporter_max_queue_size"`
	ReporterFlushInterval  time.Duration `yaml:"reporter_flush_interval"`
	ReporterLogSpans       bool          `yaml:"reporter_log_spans"`
	Endpoint               string        `yaml:"endpoint"`
	User                   string        `yaml:"user"`
	Password               string        `yaml:"password"`
	AgentHost              string        `yaml:"agent_host"`
	AgentPort              int           `yaml:"agent_port"`
	Gen128Bit              bool          `yaml:"traceid_128bit"`
}

cache.conf

配置示例

  • memory
type: IN-MEMORY
config:
  max_size: ""
  max_size_items: 0
  validity: 0s
  • memcached
type: MEMCACHED
config:
  addresses: []
  timeout: 0s
  max_idle_connections: 0
  max_async_concurrency: 0
  max_async_buffer_size: 0
  max_get_multi_concurrency: 0
  max_item_size: 0
  max_get_multi_batch_size: 0
  dns_provider_update_interval: 0s
  auto_discovery: false
  expiration: 0s
  • redis
type: REDIS
config:
  addr: ""
  username: ""
  password: ""
  db: 0
  dial_timeout: 5s
  read_timeout: 3s
  write_timeout: 3s
  pool_size: 100
  min_idle_conns: 10
  idle_timeout: 5m0s
  max_conn_age: 0s
  max_get_multi_concurrency: 100
  get_multi_batch_size: 100
  max_set_multi_concurrency: 100
  set_multi_batch_size: 100
  tls_enabled: false
  tls_config:
    ca_file: ""
    cert_file: ""
    key_file: ""
    server_name: ""
    insecure_skip_verify: false
  expiration: 24h0m0s

数据结构

type ResponseCacheProvider string

const (
	INMEMORY  ResponseCacheProvider = "IN-MEMORY"
	MEMCACHED ResponseCacheProvider = "MEMCACHED"
	REDIS     ResponseCacheProvider = "REDIS"
)

// CacheProviderConfig is the initial CacheProviderConfig struct holder before parsing it into a specific cache provider.
// Based on the config type the config is then parsed into a specific cache provider.
type CacheProviderConfig struct {
	Type   ResponseCacheProvider `yaml:"type"`
	Config interface{}           `yaml:"config"`
}
  • ResponseCacheProvider 为 IN-MEMORY 的 Config
// InMemoryResponseCacheConfig holds the configs for the in-memory cache provider.
type InMemoryResponseCacheConfig struct {
	// MaxSize represents overall maximum number of bytes cache can contain.
	MaxSize string `yaml:"max_size"`
	// MaxSizeItems represents the maximum number of entries in the cache.
	MaxSizeItems int `yaml:"max_size_items"`
	// Validity represents the expiry duration for the cache.
	Validity time.Duration `yaml:"validity"`
}
  • ResponseCacheProvider 为 MEMCACHED 的 Config
// MemcachedResponseCacheConfig holds the configs for the memcache cache provider.
type MemcachedResponseCacheConfig struct {
	Memcached cacheutil.MemcachedClientConfig `yaml:",inline"`
	// Expiration sets a global expiration limit for all cached items.
	Expiration time.Duration `yaml:"expiration"`
}
  • ResponseCacheProvider 为 REDIS 的 Config
// RedisResponseCacheConfig holds the configs for the redis cache provider.
type RedisResponseCacheConfig struct {
	Redis cacheutil.RedisClientConfig `yaml:",inline"`
	// Expiration sets a global expiration limit for all cached items.
	Expiration time.Duration `yaml:"expiration"`
}
// RedisClientConfig is the config accepted by RedisClient.
type RedisClientConfig struct {
	// Addr specifies the addresses of redis server.
	Addr string `yaml:"addr"`

	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string `yaml:"username"`
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string `yaml:"password"`

	// DB Database to be selected after connecting to the server.
	DB int `yaml:"db"`

	// DialTimeout specifies the client dial timeout.
	DialTimeout time.Duration `yaml:"dial_timeout"`

	// ReadTimeout specifies the client read timeout.
	ReadTimeout time.Duration `yaml:"read_timeout"`

	// WriteTimeout specifies the client write timeout.
	WriteTimeout time.Duration `yaml:"write_timeout"`

	// Maximum number of socket connections.
	PoolSize int `yaml:"pool_size"`

	// MinIdleConns specifies the minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int `yaml:"min_idle_conns"`

	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// -1 disables idle timeout check.
	IdleTimeout time.Duration `yaml:"idle_timeout"`

	// Connection age at which client retires (closes) the connection.
	// Default 0 is to not close aged connections.
	MaxConnAge time.Duration `yaml:"max_conn_age"`

	// MaxGetMultiConcurrency specifies the maximum number of concurrent GetMulti() operations.
	// If set to 0, concurrency is unlimited.
	MaxGetMultiConcurrency int `yaml:"max_get_multi_concurrency"`

	// GetMultiBatchSize specifies the maximum size per batch for mget.
	GetMultiBatchSize int `yaml:"get_multi_batch_size"`

	// MaxSetMultiConcurrency specifies the maximum number of concurrent SetMulti() operations.
	// If set to 0, concurrency is unlimited.
	MaxSetMultiConcurrency int `yaml:"max_set_multi_concurrency"`

	// SetMultiBatchSize specifies the maximum size per batch for pipeline set.
	SetMultiBatchSize int `yaml:"set_multi_batch_size"`
}