配置结构

简要概述

主要展示 cortex 可配置结构。

查看所有模块:

$ ./cortex -modules
alertmanager
all
compactor
configs
distributor *
flusher
ingester *
overrides-exporter
purger *
querier *
query-frontend *
query-scheduler
ruler *
store-gateway *

Modules marked with * are included in target All.

配置示列

最小化

配置结构

target: all
auth_enabled: false
http_prefix: /api/prom

api:
  ...

# server.Config
server:
  ...

# distributor.Config
distributor:
  ...

# querier.Config
querier:
  ...

ingester_client:
  ...

ingester:
  ...

flusher:
  ...

# 数据存储
storage:
  ...

# 资源限制
limits:
  ...

prealloc:
  ...

frontend_worker:
  ...

# Query Frontend
frontend:
  ...

# Query Frontend
query_range:
  ...

# 数据存储
# tsdb.BlocksStorageConfig
blocks_storage:
  ...

# Compactor
# compactor.Config
compactor:
  ...

# storegateway.Config
store_gateway:
  ...

tenant_federation:
  ...

# Ruler
# ruler.Config
ruler:
  ...

# Ruler
# rulestore.Config
ruler_storage:
  ...

configs:
  ...

# Alertmanager
# alertmanager.MultitenantAlertmanagerConfig
alertmanager:
  ...

# Alertmanager
# alertstore.Config
alertmanager_storage:
  ...

runtime_config:
  ...

memberlist:
  ...

# scheduler.Config
query_scheduler:
  ...

tracing:
  ...

数据结构

Config

github.com/cortexproject/cortex/pkg/cortex/cortex.go

// Config is the root config for Cortex.
type Config struct {
    Target      flagext.StringSliceCSV `yaml:"target"`
    AuthEnabled bool                   `yaml:"auth_enabled"`
    PrintConfig bool                   `yaml:"-"`
    HTTPPrefix  string                 `yaml:"http_prefix"`

    ExternalQueryable prom_storage.Queryable `yaml:"-"`
    ExternalPusher    ruler.Pusher           `yaml:"-"`

    API              api.Config                      `yaml:"api"`
    Server           server.Config                   `yaml:"server"`
    Distributor      distributor.Config              `yaml:"distributor"`
    Querier          querier.Config                  `yaml:"querier"`
    IngesterClient   client.Config                   `yaml:"ingester_client"`
    Ingester         ingester.Config                 `yaml:"ingester"`
    Flusher          flusher.Config                  `yaml:"flusher"`
    Storage          storage.Config                  `yaml:"storage"`
    LimitsConfig     validation.Limits               `yaml:"limits"`
    Prealloc         cortexpb.PreallocConfig         `yaml:"prealloc" doc:"hidden"`
    Worker           querier_worker.Config           `yaml:"frontend_worker"`
    Frontend         frontend.CombinedFrontendConfig `yaml:"frontend"`
    QueryRange       queryrange.Config               `yaml:"query_range"`
    BlocksStorage    tsdb.BlocksStorageConfig        `yaml:"blocks_storage"`
    Compactor        compactor.Config                `yaml:"compactor"`
    StoreGateway     storegateway.Config             `yaml:"store_gateway"`
    TenantFederation tenantfederation.Config         `yaml:"tenant_federation"`

    Ruler               ruler.Config                               `yaml:"ruler"`
    RulerStorage        rulestore.Config                           `yaml:"ruler_storage"`
    Configs             configs.Config                             `yaml:"configs"`
    Alertmanager        alertmanager.MultitenantAlertmanagerConfig `yaml:"alertmanager"`
    AlertmanagerStorage alertstore.Config                          `yaml:"alertmanager_storage"`
    RuntimeConfig       runtimeconfig.Config                       `yaml:"runtime_config"`
    MemberlistKV        memberlist.KVConfig                        `yaml:"memberlist"`
    QueryScheduler      scheduler.Config                           `yaml:"query_scheduler"`

    Tracing tracing.Config `yaml:"tracing"`
}

api.Config

github.com/cortexproject/cortex/pkg/api/api.go

type Config struct {
    ResponseCompression bool `yaml:"response_compression_enabled"`

    AlertmanagerHTTPPrefix string `yaml:"alertmanager_http_prefix"`
    PrometheusHTTPPrefix   string `yaml:"prometheus_http_prefix"`

    // The following configs are injected by the upstream caller.
    ServerPrefix       string               `yaml:"-"`
    LegacyHTTPPrefix   string               `yaml:"-"`
    HTTPAuthMiddleware middleware.Interface `yaml:"-"`

    // This allows downstream projects to wrap the distributor push function
    // and access the deserialized write requests before/after they are pushed.
    DistributorPushWrapper DistributorPushWrapper `yaml:"-"`

    // The CustomConfigHandler allows for providing a different handler for the
    // `/config` endpoint. If this field is set _before_ the API module is
    // initialized, the custom config handler will be used instead of
    // DefaultConfigHandler.
    CustomConfigHandler ConfigHandler `yaml:"-"`

    // Allows and is used to configure the addition of HTTP Header fields to logs
    HTTPRequestHeadersToLog flagext.StringSlice `yaml:"http_request_headers_to_log"`
}

server.Config

github.com/weaveworks/common/server

服务监听

distributor.Config

github.com/cortexproject/cortex/pkg/distributor/distributor.go

Distributor

querier.Config

github.com/cortexproject/cortex/pkg/querier/querier.go

Querier

client.Config

github.com/cortexproject/cortex/pkg/ingester/client/client.go

Ingester

ingester.Config

github.com/cortexproject/cortex/pkg/ingester/ingester.go

Ingester

flusher.Config

github.com/cortexproject/cortex/pkg/flusher/flusher.go

TODO;

storage.Config

TODO;

validation.Limits

github.com/cortexproject/cortex/pkg/util/validation/limits.go

资源限制

cortexpb.PreallocConfig

TODO;

querier_worker.Config

github.com/cortexproject/cortex/pkg/querier/worker/worker.go

type Config struct {
    FrontendAddress  string        `yaml:"frontend_address"`
    SchedulerAddress string        `yaml:"scheduler_address"`
    DNSLookupPeriod  time.Duration `yaml:"dns_lookup_duration"`

    Parallelism           int  `yaml:"parallelism"`
    MatchMaxConcurrency   bool `yaml:"match_max_concurrent"`
    MaxConcurrentRequests int  `yaml:"-"` // Must be same as passed to PromQL Engine.

    QuerierID string `yaml:"id"`

    GRPCClientConfig grpcclient.Config `yaml:"grpc_client_config"`
}

frontend.CombinedFrontendConfig

github.com/cortexproject/cortex/pkg/frontend/config.go

Frontend

queryrange.Config

github.com/cortexproject/cortex/pkg/querier/tripperware/queryrange/query_range_middlewares.go

// Config for query_range middleware chain.
type Config struct {
    SplitQueriesByInterval time.Duration `yaml:"split_queries_by_interval"`
    AlignQueriesWithStep   bool          `yaml:"align_queries_with_step"`
    ResultsCacheConfig     `yaml:"results_cache"`
    CacheResults           bool `yaml:"cache_results"`
    MaxRetries             int  `yaml:"max_retries"`
    // List of headers which query_range middleware chain would forward to downstream querier.
    ForwardHeaders flagext.StringSlice `yaml:"forward_headers_list"`

    // Populated based on the query configuration
    VerticalShardSize int `yaml:"-"`
}

tsdb.BlocksStorageConfig

github.com/cortexproject/cortex/pkg/storage/tsdb/config.go

数据存储

compactor.Config

github.com/cortexproject/cortex/pkg/compactor/compactor.go

Compactor

storegateway.Config

github.com/cortexproject/cortex/pkg/storegateway/

Store Gateway

tenantfederation.Config

github.com/cortexproject/cortex/pkg/querier/tenantfederation/tenant_federation.go

type Config struct {
    // Enabled switches on support for multi tenant query federation
    Enabled bool `yaml:"enabled"`
}

ruler.Config

github.com/cortexproject/cortex/pkg/ruler/ruler.go

Ruler

rulestore.Config

github.com/cortexproject/cortex/pkg/ruler/rulestore/config.go

Ruler

configs.Config

github.com/cortexproject/cortex/pkg/configs/config.go

type Config struct {
    DB  db.Config  `yaml:"database"`
    API api.Config `yaml:"api"`
}

TODO;

alertmanager.MultitenantAlertmanagerConfig

github.com/cortexproject/cortex/pkg/alertmanager/multitenant.go

Alertmanager

alertstore.Config

github.com/cortexproject/cortex/pkg/alertmanager/alertstore/config.go

Alertmanager

runtimeconfig.Config

github.com/cortexproject/cortex/pkg/util/runtimeconfig/manager.go

// Config holds the config for an Manager instance.
// It holds config related to loading per-tenant config.
type Config struct {
    ReloadPeriod time.Duration `yaml:"period"`
    // LoadPath contains the path to the runtime config file, requires an
    // non-empty value
    LoadPath string `yaml:"file"`
    Loader   Loader `yaml:"-"`
}

memberlist.KVConfig

github.com/cortexproject/cortex/pkg/ring/kv/memberlist/

Distributor memberlist.KVConfig

scheduler.Config

github.com/cortexproject/cortex/pkg/scheduler/scheduler.go

type Config struct {
    MaxOutstandingPerTenant int               `yaml:"max_outstanding_requests_per_tenant"`
    QuerierForgetDelay      time.Duration     `yaml:"querier_forget_delay"`
    GRPCClientConfig        grpcclient.Config `yaml:"grpc_client_config" doc:"description=This configures the gRPC client used to report errors back to the query-frontend."`
}

tracing.Config

github.com/cortexproject/cortex/pkg/tracing/tracing.go

type Config struct {
    Type string `yaml:"type" json:"type"`
    Otel Otel   `yaml:"otel" json:"otel"`
}

type Otel struct {
    OltpEndpoint   string              `yaml:"oltp_endpoint" json:"oltp_endpoint" doc:"hidden"`
    OtlpEndpoint   string              `yaml:"otlp_endpoint" json:"otlp_endpoint"`
    ExporterType   string              `yaml:"exporter_type" json:"exporter_type"`
    SampleRatio    float64             `yaml:"sample_ratio" json:"sample_ratio"`
    TLSEnabled     bool                `yaml:"tls_enabled"`
    TLS            tls.ClientConfig    `yaml:"tls"`
    ExtraDetectors []resource.Detector `yaml:"-"`
}



最后修改 2023.09.24: refactor: update cortex (ba4ddf9)