Documentation
¶
Index ¶
- Constants
- Variables
- func BaseCacheName() (string, error)
- func BaseConfigName() (string, error)
- func BaseConfigPath() (string, error)
- func BlockScoutDown(url string) error
- func BlockScoutUp(url, chainID string) error
- func BuildImage(dctx, dfile, nameAndTag string, buildArgs map[string]string) error
- func BuildImageOnce(once *sync.Once, dctx, dfile, nameAndTag string, buildArgs map[string]string) error
- func CheckCLNodeContainerErrors() error
- func DefaultNetwork(_ *sync.Once) error
- func DefaultTCLabels() map[string]string
- func DefaultTCName(name string) string
- func GenerateCustomPortsData(portsProvided []string) ([]string, nat.PortMap, error)
- func GetHost(container tc.Container) (string, error)
- func HostDockerInternal() string
- func IsDockerRunning() bool
- func Load[X any](t *testing.T) (*X, error)
- func LoadCache[X any](t *testing.T) (*X, error)
- func MapTheSamePort(ports ...string) nat.PortMap
- func MustParseDuration(s string) time.Duration
- func NewPromtail() error
- func NoDNS(noDNS bool, hc *container.HostConfig)
- func ObservabilityDown() error
- func ObservabilityUp() error
- func ObservabilityUpFull() error
- func RemoveTestContainers() error
- func RemoveTestStack(name string) error
- func RenderTemplate(tmpl string, data interface{}) (string, error)
- func ResourceLimitsFunc(h *container.HostConfig, resources *ContainerResources)
- func RunCommand(name string, args ...string) error
- func RunCommandDir(dir, name string, args ...string) error
- func SaveAndCheckLogs(t *testing.T) error
- func SaveContainerLogs(dir string) ([]string, error)
- func SearchLogFile(fp string, regex string) ([]string, error)
- func Store[T any](cfg *T) error
- func ToLabelsMap(response *PrometheusQueryResponse) map[string][]interface{}
- type APIError
- type Annotation
- type BasicAuth
- type Config
- type ContainerResources
- type DockerClient
- type GrafanaClient
- type JSONStrDuration
- type LogEntry
- type LokiClient
- type PostAnnotationResponse
- type PrometheusQueryClient
- type PrometheusQueryResponse
- type QueryParams
- type QueryRangeParams
- type QueryRangeResponse
- type Response
- type ValidationError
Constants ¶
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" )
const ( DefaultConfigFilePath = "env.toml" DefaultOverridesFilePath = "overrides.toml" )
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 */ )
const (
DefaultCTFLogsDir = "logs/docker"
)
const (
DefaultConfigDir = "."
)
const (
EnvVarIgnoreCriticalLogs = "CTF_IGNORE_CRITICAL_LOGS"
)
const (
EnvVarLogLevel = "CTF_LOG_LEVEL"
)
Variables ¶
var ( DefaultNetworkName = "ctf" Validator = validator.New(validator.WithRequiredStructEnabled()) ValidatorTranslator ut.Translator )
var EmbeddedObservabilityFiles embed.FS
var (
L zerolog.Logger
)
var (
PathRoot = filepath.Join(filepath.Dir(b), ".")
)
Functions ¶
func BaseCacheName ¶ added in v0.1.17
BaseCacheName returns base cache file name, ex.: env.toml -> env-cache.toml
func BaseConfigName ¶ added in v0.1.17
BaseConfigName returns base config name, ex. env.toml -> env
func BaseConfigPath ¶ added in v0.1.17
BaseConfigPath returns base config path, ex. env.toml,overrides.toml -> env.toml
func BlockScoutDown ¶ added in v0.1.17
func BlockScoutUp ¶ added in v0.1.17
func BuildImage ¶ added in v0.1.17
func BuildImageOnce ¶ added in v0.1.17
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 DefaultTCLabels ¶
func DefaultTCName ¶
func GenerateCustomPortsData ¶ added in v0.1.17
GenerateCustomPortsData generate custom ports data: exposed and forwarded port map
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 MapTheSamePort ¶
func MustParseDuration ¶ added in v0.1.17
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 RenderTemplate ¶
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
RunCommand executes a command and prints the output.
func RunCommandDir ¶ added in v0.1.17
RunCommandDir executes a command in some directory and prints the output
func SaveAndCheckLogs ¶ added in v0.1.17
func SaveContainerLogs ¶ added in v0.1.17
SaveContainerLogs writes all Docker container logs to some directory
func SearchLogFile ¶ added in v0.1.17
SearchLogFile searches logfile using regex and return matches or 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
APIError is a custom error type for handling non-200 responses from the Loki API
type Annotation ¶ added in v0.1.17
type ContainerResources ¶ added in v0.1.17
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
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
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 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
func (p *PrometheusQueryClient) QueryRange(params QueryRangeParams) (*QueryRangeResponse, error)
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
QueryParams holds the parameters required for querying Loki
type QueryRangeParams ¶ added in v0.1.17
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