framework

package module
v0.10.33 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 41 Imported by: 22

README

Framework

Modular and data-driven harness for Chainlink on-chain and off-chain components.

Documentation

Documentation

Index

Constants

View Source
const (
	EnvVarTestConfigs = "CTF_CONFIGS"
	//nolint
	EnvVarAWSSecretsManager = "CTF_AWS_SECRETS_MANAGER"
	// EnvVarCI this is a default env variable many CI runners use so code can detect we run in CI
	EnvVarCI = "CI"
)
View Source
const (
	DefaultConfigFilePath    = "env.toml"
	DefaultOverridesFilePath = "overrides.toml"
)
View Source
const (
	LocalGrafanaBaseURL    = "http://localhost:3000"
	LocalLokiBaseURL       = "http://localhost:3030"
	LocalPrometheusBaseURL = "http://localhost:9099"
	LocalCLNodeErrorsURL   = "http://localhost:3000/d/a7de535b-3e0f-4066-bed7-d505b6ec9ef1/cl-node-errors?orgId=1&refresh=5s"
	LocalWorkflowEngineURL = "http://localhost:3000/d/ce589a98-b4be-4f80-bed1-bc62f3e4414a/workflow-engine?orgId=1&refresh=5s&from=now-15m&to=now"
	LocalLogsURL           = "" /* 410-byte string literal not displayed */
	LocalPrometheusURL     = "" /* 350-byte string literal not displayed */
	LocalPostgresDebugURL  = "" /* 262-byte string literal not displayed */
	LocalPyroScopeURL      = "" /* 134-byte string literal not displayed */
)
View Source
const (
	DefaultCTFLogsDir = "logs/docker"
)
View Source
const (
	DefaultConfigDir = "."
)
View Source
const (
	EnvVarIgnoreCriticalLogs = "CTF_IGNORE_CRITICAL_LOGS"
)
View Source
const (
	EnvVarLogLevel = "CTF_LOG_LEVEL"
)

Variables

View Source
var (
	DefaultNetworkName  = "ctf"
	Validator           = validator.New(validator.WithRequiredStructEnabled())
	ValidatorTranslator ut.Translator
)
View Source
var EmbeddedObservabilityFiles embed.FS
View Source
var (
	PathRoot = filepath.Join(filepath.Dir(b), ".")
)

Functions

func BaseCacheName added in v0.1.17

func BaseCacheName() (string, error)

BaseCacheName returns base cache file name, ex.: env.toml -> env-cache.toml

func BaseConfigName added in v0.1.17

func BaseConfigName() (string, error)

BaseConfigName returns base config name, ex. env.toml -> env

func BaseConfigPath added in v0.1.17

func BaseConfigPath() (string, error)

BaseConfigPath returns base config path, ex. env.toml,overrides.toml -> env.toml

func BlockScoutDown added in v0.1.17

func BlockScoutDown(url string) error

func BlockScoutUp added in v0.1.17

func BlockScoutUp(url, chainID string) error

func BuildImage added in v0.1.17

func BuildImage(dctx, dfile, nameAndTag string, buildArgs map[string]string) error

func BuildImageOnce added in v0.1.17

func BuildImageOnce(once *sync.Once, dctx, dfile, nameAndTag string, buildArgs map[string]string) error

func CheckCLNodeContainerErrors added in v0.1.17

func CheckCLNodeContainerErrors() error

CheckCLNodeContainerErrors check if any CL node container logs has errors

func DefaultNetwork added in v0.1.1

func DefaultNetwork(_ *sync.Once) error

func DefaultTCLabels

func DefaultTCLabels() map[string]string

func DefaultTCName

func DefaultTCName(name string) string

func GenerateCustomPortsData added in v0.1.17

func GenerateCustomPortsData(portsProvided []string) ([]string, nat.PortMap, error)

GenerateCustomPortsData generate custom ports data: exposed and forwarded port map

func GetHost

func GetHost(container tc.Container) (string, error)

func HostDockerInternal added in v0.1.17

func HostDockerInternal() string

HostDockerInternal returns host.docker.internal that works both locally and in GHA

func IsDockerRunning added in v0.1.6

func IsDockerRunning() bool

func Load

func Load[X any](t *testing.T) (*X, error)

func LoadCache added in v0.1.17

func LoadCache[X any](t *testing.T) (*X, error)

LoadCache loads cached config with environment values

func MapTheSamePort

func MapTheSamePort(ports ...string) nat.PortMap

func MustParseDuration added in v0.1.17

func MustParseDuration(s string) time.Duration

MustParseDuration parses a duration string in Go's format and returns the corresponding time.Duration. It panics if the string cannot be parsed, ensuring that the caller receives a valid duration.

func NewPromtail added in v0.1.6

func NewPromtail() error

func NoDNS added in v0.1.17

func NoDNS(noDNS bool, hc *container.HostConfig)

NoDNS removes default DNS server and sets it to localhost

func ObservabilityDown added in v0.1.17

func ObservabilityDown() error

func ObservabilityUp added in v0.1.17

func ObservabilityUp() error

func ObservabilityUpFull added in v0.1.17

func ObservabilityUpFull() error

func RemoveTestContainers added in v0.1.17

func RemoveTestContainers() error

RemoveTestContainers removes all test containers, volumes and CTF docker network

func RemoveTestStack added in v0.1.17

func RemoveTestStack(name string) error

func RenderTemplate

func RenderTemplate(tmpl string, data interface{}) (string, error)

func ResourceLimitsFunc added in v0.1.17

func ResourceLimitsFunc(h *container.HostConfig, resources *ContainerResources)

ResourceLimitsFunc returns a function to configure container resources based on the human-readable CPUs and memory in Mb

func RunCommand added in v0.1.17

func RunCommand(name string, args ...string) error

RunCommand executes a command and prints the output.

func RunCommandDir added in v0.1.17

func RunCommandDir(dir, name string, args ...string) error

RunCommandDir executes a command in some directory and prints the output

func SaveAndCheckLogs added in v0.1.17

func SaveAndCheckLogs(t *testing.T) error

func SaveContainerLogs added in v0.1.17

func SaveContainerLogs(dir string) ([]string, error)

SaveContainerLogs writes all Docker container logs to some directory

func SearchLogFile added in v0.1.17

func SearchLogFile(fp string, regex string) ([]string, error)

SearchLogFile searches logfile using regex and return matches or error

func Store

func Store[T any](cfg *T) error

func ToLabelsMap added in v0.1.17

func ToLabelsMap(response *PrometheusQueryResponse) map[string][]interface{}

ToLabelsMap converts PrometheusQueryResponse.Data.Result into a map where keys are metric labels in "k:v" format and values are slices of all values with that label

Types

type APIError added in v0.1.17

type APIError struct {
	StatusCode int
	Message    string
}

APIError is a custom error type for handling non-200 responses from the Loki API

func (*APIError) Error added in v0.1.17

func (e *APIError) Error() string

Implement the `Error` interface for APIError

type Annotation added in v0.1.17

type Annotation struct {
	PanelID      *int
	DashboardUID []string
	StartTime    *time.Time
	EndTime      *time.Time
	Tags         []string
	Text         string
}

func A added in v0.1.17

func A(ns, text string, dashboardUIDs []string, from, to *time.Time) Annotation

A is just a short-cut for default annotation

type BasicAuth added in v0.1.17

type BasicAuth struct {
	Login    string
	Password string
}

BasicAuth holds the authentication details for Loki

type Config

type Config struct {
	LokiURL               string
	LokiTenantID          string
	LokiBasicAuthUsername string
	LokiBasicAuthPassword string
}

type ContainerResources added in v0.1.17

type ContainerResources struct {
	CPUs     float64 `toml:"cpus" validate:"gte=0"`
	MemoryMb uint    `toml:"memory_mb"`
}

type DockerClient added in v0.1.17

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

DockerClient wraps a Docker API client and provides convenience methods

func NewDockerClient added in v0.1.17

func NewDockerClient() (*DockerClient, error)

NewDockerClient creates a new instance of DockerClient

func (*DockerClient) CopyFile added in v0.1.17

func (dc *DockerClient) CopyFile(containerName, sourceFile, targetPath string) error

CopyFile copies a file into a container by name

func (*DockerClient) ExecContainer added in v0.1.17

func (dc *DockerClient) ExecContainer(containerName string, command []string) (string, error)

ExecContainer executes a command inside a running container by name and returns the combined stdout/stderr.

type GrafanaClient added in v0.1.17

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

func NewGrafanaClient added in v0.1.17

func NewGrafanaClient(url, bearerToken string) *GrafanaClient

NewGrafanaClient initializes a new Grafana client with the specified URL and API key.

func (*GrafanaClient) Annotate added in v0.1.17

func (c *GrafanaClient) Annotate(annotation Annotation) ([]PostAnnotationResponse, []*resty.Response, error)

Annotate adds annotation to all the dashboards, works for both single point annotation with just StartTime and for ranges with StartTime/EndTime

type JSONStrDuration added in v0.1.1

type JSONStrDuration struct {
	time.Duration
}

JSONStrDuration is JSON friendly duration that can be parsed from "1h2m0s" Go format

func (*JSONStrDuration) MarshalJSON added in v0.1.1

func (d *JSONStrDuration) MarshalJSON() ([]byte, error)

func (*JSONStrDuration) UnmarshalJSON added in v0.1.1

func (d *JSONStrDuration) UnmarshalJSON(b []byte) error

type LogEntry added in v0.1.17

type LogEntry struct {
	Timestamp string
	Log       string
}

LogEntry represents a single log entry with a timestamp and raw log message

type LokiClient added in v0.1.17

type LokiClient struct {
	BaseURL     string
	TenantID    string
	BasicAuth   BasicAuth
	QueryParams QueryParams
	RestyClient *resty.Client
}

LokiClient represents a client to interact with Loki for querying logs

func NewLokiQueryClient added in v0.1.17

func NewLokiQueryClient(baseURL, tenantID string, auth BasicAuth, queryParams QueryParams) *LokiClient

NewLokiQueryClient creates a new Loki client with the given parameters, initializes a logger, and configures Resty with debug mode

func (*LokiClient) QueryRange added in v0.1.17

func (lc *LokiClient) QueryRange(ctx context.Context) ([]LogEntry, error)

QueryRange queries Loki logs based on the query parameters and returns the raw log entries

type PostAnnotationResponse added in v0.1.17

type PostAnnotationResponse struct {
	Message string `json:"message"`
	ID      int64  `json:"id"`
}

type PrometheusQueryClient added in v0.1.17

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

PrometheusQueryClient is a client for querying Prometheus metrics

func NewPrometheusQueryClient added in v0.1.17

func NewPrometheusQueryClient(baseURL string) *PrometheusQueryClient

NewPrometheusQueryClient creates a new PrometheusQueryClient

func (*PrometheusQueryClient) Query added in v0.1.17

func (p *PrometheusQueryClient) Query(query string, timestamp time.Time) (*PrometheusQueryResponse, error)

Query executes an instant query against the Prometheus API

func (*PrometheusQueryClient) QueryRange added in v0.1.17

QueryRange executes a range query against the Prometheus API

type PrometheusQueryResponse added in v0.1.17

type PrometheusQueryResponse struct {
	Status string `json:"status"`
	Data   struct {
		ResultType string `json:"resultType"`
		Result     []struct {
			Metric map[string]string `json:"metric"`
			Value  []interface{}     `json:"value"`
		} `json:"result"`
	} `json:"data"`
}

PrometheusQueryResponse represents the response from Prometheus API

type QueryParams added in v0.1.17

type QueryParams struct {
	Query     string
	StartTime time.Time
	EndTime   time.Time
	Limit     int
}

QueryParams holds the parameters required for querying Loki

type QueryRangeParams added in v0.1.17

type QueryRangeParams struct {
	Query string
	Start time.Time
	End   time.Time
	Step  time.Duration
}

QueryRangeParams contains parameters for range queries

type QueryRangeResponse added in v0.1.17

type QueryRangeResponse struct {
	Status string `json:"status"`
	Data   struct {
		ResultType string `json:"resultType"`
		Result     []struct {
			Metric map[string]string `json:"metric"`
			Values [][]interface{}   `json:"values"`
		} `json:"result"`
	} `json:"data"`
}

QueryRangeResponse represents the response from Prometheus range query API

type Response added in v0.1.17

type Response struct {
	Data struct {
		Result []struct {
			Stream map[string]string `json:"stream"`
			Values [][]interface{}   `json:"values"`
		} `json:"result"`
	} `json:"data"`
}

Response represents the structure of the response from Loki

type ValidationError

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

Directories

Path Synopsis
components
jd
dockercompose module
fake module

Jump to

Keyboard shortcuts

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