plugins

package
v2.6.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 18 Imported by: 0

README

LOOP Plugins

⚠ Experimental ⚠

This directory supports Local-Out-Of-Process (LOOP) Plugins, an alternative node runtime where some systems execute in separate processes, plug-in via github.com/hashicorp/go-plugin, and communicate via GRPC.

There are currently two kinds of plugins, and one implementation of each: a Solana Relayer plugin, and a Median Reporting plugin. The cmd directory contains their package mains for now. These can be built via make install-solana and make install-median.

How to use

chainlink.Dockerfile extends the regular core/chainlink.Dockerfile to include the plugin binaries, and enables support by setting CL_SOLANA_CMD, CL_STARKNET_CMD, and CL_MEDIAN_CMD. Either plugin can be disabled by un-setting the environment variable, which will revert to the original in-process runtime. Images built from this Dockerfile can otherwise be used normally, provided that the pre-requisites have been met.

Pre-requisites
Timeouts

LOOPPs communicate over GRPC, which always includes a context.Context and requires realistic timeouts. Placeholder/dummy values (e.g. MaxDurationQuery = 0) will not work and must be updated to realistic values. In lieu of reconfiguring already deployed contracts on Solana, the environment variable CL_MIN_OCR2_MAX_DURATION_QUERY can be set establish a new minimum via libocr's LocalConfig.MinOCR2MaxDurationQuery. If left unset, the default value is 100ms.

Prometheus

LOOPPs are dynamic, and so must be monitoring. We use Plugin discovery to dynamically determine what to monitor based on what plugins are running and we route external prom scraping to the plugins without exposing them directly

The endpoints are

/discovery : HTTP Service Discovery [https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config] Prometheus server is configured to poll this url to discover new endpoints to monitor. The node serves the response based on what plugins are running,

/plugins/<name>/metrics: The node acts as very thin middleware to route from Prometheus server scrape requests to individual plugin /metrics endpoint Once a plugin is discovered via the discovery mechanism above, the Prometheus service calls the target endpoint at the scrape interval The node acts as middleware to route the request to the /metrics endpoint of the requested plugin

The simplest change to monitor LOOPPs is to add a service discovery to the scrape configuration

  • job_name: 'chainlink_node' ...
  • http_sd_configs:
  •  - url: "http://127.0.0.1:6688/discovery"
    
  •    refresh_interval: 30s
    

See the Prometheus documentation for full details [https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExists = errors.New("plugin already registered")

Functions

func NewCmdFactory added in v2.3.0

func NewCmdFactory(register func(id string) (*RegisteredLoop, error), lcfg CmdConfig) (func() *exec.Cmd, error)

NewCmdFactory is helper to ensure synchronization between the loop registry and os cmd to exec the LOOP

func SetCmdEnvFromConfig

func SetCmdEnvFromConfig(cmd *exec.Cmd, cfg EnvConfig)

SetCmdEnvFromConfig sets LOOP-specific vars in the env of the given cmd.

Types

type Base added in v2.3.0

type Base struct {
	Logger logger.Logger
	// contains filtered or unexported fields
}

Base is a base layer for plugins to easily manage sub-[types.Service]s.

func (*Base) Close added in v2.3.0

func (p *Base) Close() (err error)

func (*Base) HealthReport added in v2.3.0

func (p *Base) HealthReport() map[string]error

func (*Base) Name added in v2.3.0

func (p *Base) Name() string

func (*Base) Ready added in v2.3.0

func (p *Base) Ready() error

func (*Base) SubService added in v2.3.0

func (p *Base) SubService(s types.Service)

type CmdConfig added in v2.3.0

type CmdConfig struct {
	ID  string // unique string used by the node to track the LOOP. typically supplied by the loop logger name
	Cmd string // string value of executable to exec
}

CmdConfig is configuration used to register the LOOP and generate an exec

type EnvConfig

type EnvConfig interface {
	PrometheusPort() int
}

EnvConfig is the configuration interface between the application and the LOOP executable. The values are fully resolved and static and passed via the environment.

func GetEnvConfig

func GetEnvConfig() (EnvConfig, error)

GetEnvConfig deserializes LOOP-specific environment variables to an EnvConfig

func NewEnvConfig

func NewEnvConfig(prometheusPort int) EnvConfig

type LoopRegistry

type LoopRegistry struct {
	// contains filtered or unexported fields
}

LoopRegistry is responsible for assigning ports to plugins that are to be used for the plugin's prometheus HTTP server

func NewLoopRegistry

func NewLoopRegistry(lggr logger.Logger) *LoopRegistry

func (*LoopRegistry) Get

func (m *LoopRegistry) Get(id string) (*RegisteredLoop, bool)

Get plugin by id. Safe for concurrent use.

func (*LoopRegistry) List

func (m *LoopRegistry) List() []*RegisteredLoop

Return slice sorted by plugin name. Safe for concurrent use.

func (*LoopRegistry) Register

func (m *LoopRegistry) Register(id string) (*RegisteredLoop, error)

Register creates a port of the plugin. It is not idempotent. Duplicate calls to Register will return ErrExists Safe for concurrent use.

type PromServer

type PromServer struct {
	// contains filtered or unexported fields
}

func NewPromServer

func NewPromServer(port int, lggr logger.Logger, opts ...PromServerOpt) *PromServer

func (*PromServer) Close

func (p *PromServer) Close() error

Close shutdowns down the underlying HTTP server. See http.Server.Close for details

func (*PromServer) Name

func (p *PromServer) Name() string

Name of the server

func (*PromServer) Port

func (p *PromServer) Port() int

Port is the resolved port and is only known after Start(). returns -1 before it is resolved or if there was an error during resolution.

func (*PromServer) Start

func (p *PromServer) Start() error

Start start HTTP server on specified port to handle metrics requests

type PromServerOpt

type PromServerOpt func(*PromServer)

func WithHandler added in v2.3.0

func WithHandler(h http.Handler) PromServerOpt

type RegisteredLoop

type RegisteredLoop struct {
	Name   string
	EnvCfg EnvConfig
}

type RegistrarConfig

type RegistrarConfig interface {
	RegisterLOOP(loopId string, cmdName string) (func() *exec.Cmd, loop.GRPCOpts, error)
}

RegistrarConfig generates contains static configuration inher

func NewRegistrarConfig

func NewRegistrarConfig(grpcOpts loop.GRPCOpts, loopRegistrationFn func(loopId string) (*RegisteredLoop, error)) RegistrarConfig

NewRegistrarConfig creates a RegistarConfig loopRegistrationFn must act as a global registry function of LOOPs and must be idempotent. The [func() *exec.Cmd] for a LOOP should be generated by calling [RegistrarConfig.RegisterLOOP]

type Server added in v2.3.0

type Server struct {
	loop.GRPCOpts
	Logger logger.SugaredLogger
	*PromServer
	services.Checker
}

Server holds common plugin server fields.

func MustNewStartedServer added in v2.6.0

func MustNewStartedServer(loggerName string) *Server

MustNewStartedServer returns a new started Server like NewStartedServer, but logs and exits in the event of error. The caller is responsible for calling Server.Stop().

func NewStartedServer added in v2.6.0

func NewStartedServer(loggerName string) (*Server, error)

NewStartedServer returns a started Server. The caller is responsible for calling Server.Stop().

func (*Server) MustRegister added in v2.3.0

func (s *Server) MustRegister(c services.Checkable)

MustRegister registers the Checkable with services.Checker, or exits upon failure.

func (*Server) Stop added in v2.3.0

func (s *Server) Stop()

Stop closes resources and flushes logs.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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