client

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 18 Imported by: 6

README

Client

Contains code to interact with Chainlink nodes, and other HTTP services.

Documentation

Index

Constants

View Source
const (
	DefaultCallTimeout       = 1 * time.Minute
	DefaultStatsPollInterval = 10 * time.Second
	UntilStopDuration        = 99999 * time.Hour
)
View Source
const (
	QueryMemoryUsage          = `` /* 201-byte string literal not displayed */
	QueryAllCPUBusyPercentage = `100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[%s])) * 100)`
)

Query constants

Variables

View Source
var (
	ErrNoCfg                 = errors.New("config is nil")
	ErrNoGun                 = errors.New("no gun implementation provided")
	ErrStaticRPS             = errors.New("static RPS must be > 0")
	ErrCallTimeout           = errors.New("generator request call timeout")
	ErrStartRPS              = errors.New("StartRPS must be > 0")
	ErrIncreaseRPS           = errors.New("IncreaseRPS must be > 0")
	ErrIncreaseAfterDuration = errors.New("IncreaseAfter must be > 1sec")
	ErrHoldRPS               = errors.New("HoldRPS must be > 0")
)

Functions

This section is empty.

Types

type AdapterResponse

type AdapterResponse struct {
	Id    string        `json:"id"`
	Data  AdapterResult `json:"data"`
	Error interface{}   `json:"error"`
}

AdapterResponse represents a response from an adapter

type AdapterResult

type AdapterResult struct {
	Result int `json:"result"`
}

AdapterResult represents an int result for an adapter

type CallResult added in v1.6.3

type CallResult struct {
	Duration time.Duration
	Data     interface{}
	Error    error
}

CallResult represents basic call result info

type ContractInfoJSON

type ContractInfoJSON struct {
	ContractAddress string `json:"contractAddress"`
	ContractVersion int    `json:"contractVersion"`
	Path            string `json:"path"`
	Status          string `json:"status"`
}

ContractInfoJSON represents an element of the contracts array used to deliver configs to otpe

type ExplorerClient

type ExplorerClient struct {
	APIClient *resty.Client
	Config    *ExplorerConfig
}

ExplorerClient is used to call Explorer API endpoints

func NewExplorerClient

func NewExplorerClient(cfg *ExplorerConfig) *ExplorerClient

NewExplorerClient creates a new explorer mock client

func (*ExplorerClient) PostAdminNodes

func (em *ExplorerClient) PostAdminNodes(nodeName string) (NodeAccessKeys, error)

PostAdminNodes is used to exercise the POST /api/v1/admin/nodes endpoint This endpoint is used to create access keys for nodes

type ExplorerConfig

type ExplorerConfig struct {
	URL           string
	AdminUsername string
	AdminPassword string
}

ExplorerConfig holds config information for ExplorerClient

type GeneratorStats added in v1.6.3

type GeneratorStats struct {
	Success     atomic.Int64
	Failed      atomic.Int64
	CallTimeout atomic.Int64
}

GeneratorStats basic generator load stats

type HttpInitializer

type HttpInitializer struct {
	Id       string       `json:"id"`
	Request  HttpRequest  `json:"httpRequest"`
	Response HttpResponse `json:"httpResponse"`
}

HttpInitializer represents an element of the initializer array used in the mockserver initializer

type HttpRequest

type HttpRequest struct {
	Path string `json:"path"`
}

HttpRequest represents the httpRequest json object used in the mockserver initializer

type HttpResponse

type HttpResponse struct {
	Body interface{} `json:"body"`
}

HttpResponse represents the httpResponse json object used in the mockserver initializer

type KafkaRestClient

type KafkaRestClient struct {
	APIClient *resty.Client
	Config    *KafkaRestConfig
}

KafkaRestClient kafka-rest client

func NewKafkaRestClient

func NewKafkaRestClient(cfg *KafkaRestConfig) *KafkaRestClient

NewKafkaRestClient creates a new KafkaRestClient

func (*KafkaRestClient) GetTopics

func (krc *KafkaRestClient) GetTopics() ([]string, error)

GetTopics Get a list of Kafka topics.

type KafkaRestConfig

type KafkaRestConfig struct {
	URL string
}

KafkaRestConfig holds config information for KafkaRestClient

type LoadGenerator added in v1.6.3

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

LoadGenerator generates load on chain with some RPS

func NewLoadGenerator added in v1.6.3

func NewLoadGenerator(cfg *LoadGeneratorConfig) (*LoadGenerator, error)

NewLoadGenerator creates a new instance for a contract, shoots for scheduled RPS until timeout, test logic is defined through LoadTestable

func (*LoadGenerator) Errors added in v1.6.3

func (l *LoadGenerator) Errors() []error

Errors get all calls errors

func (*LoadGenerator) GetData added in v1.6.3

func (l *LoadGenerator) GetData() *ResponseData

GetData get all calls data

func (*LoadGenerator) PrintStats added in v1.6.3

func (l *LoadGenerator) PrintStats()

PrintStats prints some runtime LoadGenerator.stats

func (*LoadGenerator) Run added in v1.6.3

func (l *LoadGenerator) Run()

Run runs load loop until timeout or stop

func (*LoadGenerator) Stats added in v1.6.3

func (l *LoadGenerator) Stats() *GeneratorStats

Stats get all load stats

func (*LoadGenerator) Stop added in v1.6.3

func (l *LoadGenerator) Stop() (interface{}, bool)

Stop stops load generator, waiting for all calls for either finish or timeout

func (*LoadGenerator) Wait added in v1.6.3

func (l *LoadGenerator) Wait() (interface{}, bool)

Wait waits until test ends

type LoadGeneratorConfig added in v1.6.3

type LoadGeneratorConfig struct {
	RPS                  int
	Schedule             *LoadSchedule
	Duration             time.Duration
	StatsPollInterval    time.Duration
	CallFailThreshold    int64
	CallTimeoutThreshold int64
	CallTimeout          time.Duration
	Gun                  LoadTestable
	SharedData           interface{}
}

LoadGeneratorConfig is for shared load test data and configuration

func (*LoadGeneratorConfig) Validate added in v1.6.3

func (lgc *LoadGeneratorConfig) Validate() error

type LoadSchedule added in v1.6.3

type LoadSchedule struct {
	StartRPS      int
	IncreaseRPS   int
	IncreaseAfter time.Duration
	HoldRPS       int
}

LoadSchedule load test schedule

func (*LoadSchedule) Validate added in v1.6.3

func (ls *LoadSchedule) Validate() error

type LoadTestable added in v1.6.3

type LoadTestable interface {
	Call(data interface{}) CallResult
}

LoadTestable is basic interface to run limited load with a contract call and save all transactions

type MockGun added in v1.6.3

type MockGun struct {
	Data []string
	// contains filtered or unexported fields
}

func NewMockGun added in v1.6.3

func NewMockGun(cfg *MockGunConfig) *MockGun

func (*MockGun) Call added in v1.6.3

func (m *MockGun) Call(data interface{}) CallResult

type MockGunConfig added in v1.6.3

type MockGunConfig struct {
	Fail        bool
	CallSleep   time.Duration
	VerifySleep time.Duration
}

type MockserverClient

type MockserverClient struct {
	APIClient *resty.Client
	Config    *MockserverConfig
}

MockserverClient mockserver client

func ConnectMockServer

func ConnectMockServer(e *environment.Environment) (*MockserverClient, error)

ConnectMockServer creates a connection to a deployed mockserver in the environment

func NewMockserverClient

func NewMockserverClient(cfg *MockserverConfig) *MockserverClient

NewMockserverClient returns a mockserver client

func (*MockserverClient) ClearExpectation

func (em *MockserverClient) ClearExpectation(body interface{}) error

ClearExpectation clears expectations

func (*MockserverClient) PutExpectations

func (em *MockserverClient) PutExpectations(body interface{}) error

PutExpectations sets the expectations (i.e. mocked responses)

func (*MockserverClient) SetAnyValuePath added in v1.6.0

func (em *MockserverClient) SetAnyValuePath(path string, v interface{}) error

SetAnyValuePath sets any type of value for a path

func (*MockserverClient) SetValuePath

func (em *MockserverClient) SetValuePath(path string, v int) error

SetValuePath sets an int for a path

type MockserverConfig

type MockserverConfig struct {
	LocalURL   string
	ClusterURL string
}

MockserverConfig holds config information for MockserverClient

type Name

type Name struct {
	Name string `json:"name"`
}

Name is the body of the request

type NodeAccessKeys

type NodeAccessKeys struct {
	ID        string `json:"id"`
	AccessKey string `json:"accessKey"`
	Secret    string `json:"secret"`
}

NodeAccessKeys is the body of the response

type NodeInfoJSON

type NodeInfoJSON struct {
	ID          string   `json:"id"`
	NodeAddress []string `json:"nodeAddress"`
}

NodeInfoJSON represents an element of the nodes array used to deliver configs to otpe

type PathSelector

type PathSelector struct {
	Path string `json:"path"`
}

PathSelector represents the json object used to find expectations by path

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
}

PostgresConfig postgres config for connection string

type PostgresConnector

type PostgresConnector struct {
	*sqlx.DB
	Cfg *PostgresConfig
}

PostgresConnector sqlx postgres connector

func ConnectDB added in v1.6.3

func ConnectDB(nodeNum int, e *environment.Environment) (*PostgresConnector, error)

func NewPostgresConnector

func NewPostgresConnector(cfg *PostgresConfig) (*PostgresConnector, error)

NewPostgresConnector creates new sqlx postgres connector

type Prometheus

type Prometheus struct {
	v1.API
}

Prometheus ease of use for v1.API

func NewPrometheusClient

func NewPrometheusClient(url string) (*Prometheus, error)

NewPrometheusClient returns a prometheus client

func (*Prometheus) CPUBusyPercentage

func (p *Prometheus) CPUBusyPercentage() (float64, error)

CPUBusyPercentage host CPU busy percentage

func (*Prometheus) GetAlerts

func (p *Prometheus) GetAlerts() (v1.AlertsResult, error)

GetAlerts returns all firing alerts

func (*Prometheus) GetQuery

func (p *Prometheus) GetQuery(query string) (model.Value, error)

GetQuery returns the result of applying a PromQL query

func (*Prometheus) MemoryUsage

func (p *Prometheus) MemoryUsage() (float64, error)

MemoryUsage total memory used by interval

func (*Prometheus) ResourcesSummary

func (p *Prometheus) ResourcesSummary() (float64, float64, error)

ResourcesSummary returns a summary of memory and cpu used

type ResourcesSummary

type ResourcesSummary struct {
	MemoryUsage   float64
	CPUPercentage float64
}

ResourcesSummary Data for memory and cpu usage

type ResponseData added in v1.6.3

type ResponseData struct {
	OKData []interface{}

	OKResponses []CallResult

	FailResponses []CallResult
	// contains filtered or unexported fields
}

ResponseData includes any request/response data that a gun might store ok* slices usually contains successful responses and their verifications if their done async fail* slices contains CallResult with response data and an error

Jump to

Keyboard shortcuts

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