Documentation
¶
Overview ¶
Package ha implements a high availability clustering mode for the agent. It is also referred to as the "scraping service" mode, as this is a fairly accurate description of what it does: a series of configs are stored in a KV store and a cluster of agents pulls configs from the store and shards them amongst the cluster, thereby distributing scraping load.
Index ¶
- func GetCodec() codec.Codec
- type APIHandler
- type Config
- type ConfigManager
- type ReadRing
- type Server
- func (s *Server) AllConfigs(ctx context.Context) (<-chan instance.Config, error)
- func (s *Server) DeleteConfiguration(r *http.Request) (interface{}, error)
- func (s *Server) Flush()
- func (s *Server) GetConfiguration(r *http.Request) (interface{}, error)
- func (s *Server) ListConfigurations(r *http.Request) (interface{}, error)
- func (s *Server) PutConfiguration(r *http.Request) (interface{}, error)
- func (s *Server) Reshard(ctx context.Context, _ *agentproto.ReshardRequest) (_ *empty.Empty, err error)
- func (s *Server) Stop() error
- func (s *Server) TransferOut(ctx context.Context) error
- func (s *Server) WireAPI(r *mux.Router)
- func (s *Server) WireGRPC(srv *grpc.Server)
- func (s *Server) WrapHandler(next APIHandler) http.HandlerFunc
- type ShardingConfigManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIHandler ¶
type APIHandler func(r *http.Request) (interface{}, error)
APIHandler is a function that returns a configapi Response type and optionally an error.
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
ReshardInterval time.Duration `yaml:"reshard_interval"`
KVStore kv.Config `yaml:"kvstore"`
Lifecycler ring.LifecyclerConfig `yaml:"lifecycler"`
}
Config describes how to instantiate a scraping service Server instance.
func (*Config) RegisterFlags ¶
func (c *Config) RegisterFlags(f *flag.FlagSet)
RegisterFlags adds the flags required to config the Server to the given FlagSet.
func (*Config) RegisterFlagsWithPrefix ¶
func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet with a specified prefix.
type ConfigManager ¶
type ConfigManager interface {
// ListConfigs gets the list of currently known configs.
ListConfigs() map[string]instance.Config
// ApplyConfig adds or updates a config.
ApplyConfig(c instance.Config)
// DeleteConfig deletes a config by name, uniquely keyed by the
// Name field in instance.Config.
DeleteConfig(name string) error
}
ConfigManager is an interface to manipulating a set of running instance.Configs. It is satisfied by the ConfigManager struct in pkg/prometheus, but is provided as an interface here for testing and avoiding import cycles.
type ReadRing ¶
type ReadRing interface {
http.Handler
Get(key uint32, op ring.Operation, buf []ring.IngesterDesc) (ring.ReplicationSet, error)
GetAll() (ring.ReplicationSet, error)
}
ReadRing is a subset of the Cortex ring.ReadRing interface with only the functionality used by the HA server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements the HA scraping service.
func New ¶
func New(cfg Config, clientConfig client.Config, logger log.Logger, cm ConfigManager) (*Server, error)
New creates a new HA scraping service instance.
func (*Server) AllConfigs ¶
func (s *Server) AllConfigs(ctx context.Context) (<-chan instance.Config, error)
AllConfigs gets all configs known to the KV store.
func (*Server) DeleteConfiguration ¶
func (s *Server) DeleteConfiguration(r *http.Request) (interface{}, error)
DeleteConfiguration deletes an existing named configuration.
func (*Server) Flush ¶
func (s *Server) Flush()
Flush satisfies ring.FlushTransferer. It is a no-op for the Agent.
func (*Server) GetConfiguration ¶
func (s *Server) GetConfiguration(r *http.Request) (interface{}, error)
GetConfiguration returns an existing named configuration.
func (*Server) ListConfigurations ¶
func (s *Server) ListConfigurations(r *http.Request) (interface{}, error)
ListConfigurations returns a list of the named configurations or all configurations associated with the Prometheus agent.
func (*Server) PutConfiguration ¶
func (s *Server) PutConfiguration(r *http.Request) (interface{}, error)
PutConfiguration creates or updates a named configuration. Completely overrides the previous configuration if it exists.
func (*Server) Reshard ¶
func (s *Server) Reshard(ctx context.Context, _ *agentproto.ReshardRequest) (_ *empty.Empty, err error)
Reshard initiates an entire reshard of the current HA scraping service instance. All configs will be reloaded from the KV store and the scraping service instance will see what should be managed locally.
Satisfies agentproto.ScrapingServiceServer.
func (*Server) TransferOut ¶
func (s *Server) TransferOut(ctx context.Context) error
TransferOut satisfies ring.FlushTransferer. It connects to all other healthy agents in the cluster and tells them to reshard.
func (*Server) WireAPI ¶
func (s *Server) WireAPI(r *mux.Router)
WireAPI injects routes into the provided mux router for the config management API.
func (*Server) WireGRPC ¶
func (s *Server) WireGRPC(srv *grpc.Server)
WireGRPC injects gRPC server handlers into the provided gRPC server.
func (*Server) WrapHandler ¶
func (s *Server) WrapHandler(next APIHandler) http.HandlerFunc
WrapHandler is responsible for turning an APIHandler into an HTTP handler by wrapping responses and writing them as JSON.
type ShardingConfigManager ¶
type ShardingConfigManager struct {
// contains filtered or unexported fields
}
ShardingConfigManager wraps around an existing ConfigManager and uses a hash ring to determine if a config should be applied. If an applied config used to be owned by the local address but no longer does, it will be deleted on the next apply.
func NewShardingConfigManager ¶
func NewShardingConfigManager(logger log.Logger, wrap ConfigManager, ring ReadRing, addr string) ShardingConfigManager
NewShardingConfigManager creates a new ShardingConfigManager. The wrap argument holds the underlying config manager, while ring and addr are used together to do hash ring lookups: for a given hash, a config is owned by the ShardingConfigManager if the address of a node from a lookup matches the addr argument passed to NewShardingConfigManager.
func (ShardingConfigManager) ApplyConfig ¶
func (m ShardingConfigManager) ApplyConfig(c instance.Config)
ApplyConfig implements ConfigManager.ApplyConfig.
func (ShardingConfigManager) DeleteConfig ¶
func (m ShardingConfigManager) DeleteConfig(name string) error
DeleteConfig implements ConfigManager.DeleteConfig.
func (ShardingConfigManager) ListConfigs ¶
func (m ShardingConfigManager) ListConfigs() map[string]instance.Config
ListConfigs implements ConfigManager.ListConfigs.