common

package module
v0.0.0-...-d6bf0fb Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 14 Imported by: 10

README

Synthetic-heart common package

This package contains code that is shared across all components

Folders

  • proto/: contains the proto files needed for communication with plugins
  • storage/: contains the code and interface for external storage (e.g. redis)
  • utils/: contains any common utility code that can be shared

Documentation

Index

Constants

View Source
const (
	DnsTestName        = "dns"
	SelfTestRxTestName = "selfTestRx"
	HttpPingTestName   = "httpPing"
	PingTestName       = "ping"
	NetDialTestName    = "netDial"
	CurlTestName       = "curl"
)

Test plugin names

View Source
const (
	TimeFormat                    = "2006-01-02T15:04:05.999999999Z07:00"
	BroadcasterPublishChannelSize = 1000
	DefaultSynTestSubChannelSize  = 1000
	DefaultChannelSize            = 1000
	MaxSynTestTimerJitter         = 10000 // milliseconds
	MaxConfigTimerJitter          = 5000  // milliseconds
	DefaultInitTimeout            = 10 * time.Second
	DefaultRunTimeout             = 10 * time.Second
	DefaultFinishTimeout          = 10 * time.Second
	DefaultLogWaitTime            = 15 * time.Millisecond
	DefaultRestartPolicy          = RestartAlways
)
View Source
const (
	TriggerTypeTimer = "timer"
	TriggerTypeTest  = "test"
)

Trigger Type Values

View Source
const (
	ImportanceCritical = "critical"
	ImportanceHigh     = "high"
	ImportanceMedium   = "medium"
	ImportanceLow      = "low"
)

Importance Values

View Source
const (
	ErrorKey      = "_error"      // special key for error details
	LogKey        = "_log"        // special key for logs
	PrometheusKey = "_prometheus" // special key for prometheus metrics
)

Special Keys in Details of TestDetailsMap

View Source
const ActiveClusterStatus = 1
View Source
const (
	DroppedTestResults = "dropped_test_results" // How many test results the broadcaster has dropped because the listener wasn't ready
)

Synthetic Heart Metric Names

Variables

View Source
var DefaultBackoff = wait.Backoff{
	Steps:    20,
	Duration: 10 * time.Millisecond,
	Factor:   3.0,
	Jitter:   0.1,
	Cap:      15 * time.Second,
}
View Source
var DefaultTestPluginHandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "SYNTEST_PLUGIN",
	MagicCookieValue: "synthetic-heart",
}

Handshake config for Hashicorp plugins to talk to syntest plugins

Functions

func AddPrometheusMetricsToResults

func AddPrometheusMetricsToResults(promMetric PrometheusMetrics, testResult proto.TestResult) error

Adds a prometheus metric to a test result

func ComputePluginId

func ComputePluginId(agentId string, testName string) string

Computes plugin id: Plugin Id is just a string representing the agentId (i.e. node) & the test name

func FailedTestResult

func FailedTestResult() proto.TestResult

Gets a failed test result

func GetAllActiveClusters

func GetAllActiveClusters(domain string) ([]string, error)

Get all active cluster names in target cloud by query cluster status DNS SRV record

func GetKafkaHeartBeatTag

func GetKafkaHeartBeatTag(clusterName string, clusterDomain string) string

Computes the tag for heartbeat send to LMA (used by LMA tests)

func GetPluginIdComponents

func GetPluginIdComponents(pluginId string) (agentId string, testName string, err error)

Splits the plugin Id into its agent Id and test name

func ParseYMLConfig

func ParseYMLConfig(configStr string, o interface{}) error

Parses a yaml config

Types

type AgentStatus

type AgentStatus struct {
	SynTests   []string `json:"syntests"`
	StatusTime string   `json:"statusTime"`
}

type ChronySource

type ChronySource struct {
	Mode                    string
	State                   string
	Ip                      string
	Stratum                 int
	Poll                    int
	ReachRegister           int
	LastRx                  string
	LastSampleOffset        string
	LastSampleActualOffset  string
	LastSampleMarginOfError string
}

type KafkaHeartBeat

type KafkaHeartBeat struct {
	Timestamp     string   `json:"timestamp"`
	ClusterName   string   `json:"clusterName"`
	ClusterDomain string   `json:"clusterDomain"`
	HostName      string   `json:"hostName"`
	Tags          []string `json:"tags"`
}

type PluginRestartPolicy

type PluginRestartPolicy string

PluginRestartPolicy Values

const (
	RestartAlways  PluginRestartPolicy = "always"
	RestartNever   PluginRestartPolicy = "never"
	RestartOnError PluginRestartPolicy = "onError"
)

type PluginState

type PluginState struct {
	Status        RoutineStatus `json:"status" yaml:"status"`
	StatusMsg     string        `json:"statusMsg" yaml:"statusMsg"`
	LastMsg       string        `json:"lastMsg" yaml:"lastMsg"`
	Config        interface{}   `json:"config" yaml:"config"`
	Restarts      int           `json:"restarts" yaml:"restarts"`
	TotalRestarts int           `json:"totalRestarts" yaml:"totalRestarts"`
	RunningSince  time.Time     `json:"runningSince" yaml:"runningSince"`
	LastUpdated   time.Time     `json:"lastUpdated" yaml:"lastUpdated"`
}

type PrometheusGauge

type PrometheusGauge struct {
	Name   string            `yaml:"name"`
	Help   string            `yaml:"help"`
	Value  float64           `yaml:"value"`
	Labels map[string]string `yaml:"labels"`
}

type PrometheusMetrics

type PrometheusMetrics struct {
	Gauges []PrometheusGauge `yaml:"gauges"`
}

type RoutineStatus

type RoutineStatus string
const (
	NotRunning     RoutineStatus = "notRunning"
	Running        RoutineStatus = "running"
	Error          RoutineStatus = "error"
	RestartBackOff RoutineStatus = "restartBackOff"
	Restarting     RoutineStatus = "restarting"
	StatusUnknown  RoutineStatus = "unknown"
)

type SynTestGRPCPlugin

type SynTestGRPCPlugin struct {
	plugin.Plugin               // Implement the plugin.Plugin Interface even tho its a GRPC interface (necessary)
	Impl          SynTestPlugin // The real implementation is injected into this variable
}

func (SynTestGRPCPlugin) GRPCClient

func (SynTestGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

func (*SynTestGRPCPlugin) GRPCServer

func (p *SynTestGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

type SynTestPlugin

type SynTestPlugin interface {
	// Called once at the start when plugin is run
	Initialise(config proto.SynTestConfig) error

	// Called when the test needs to be performed.
	PerformTest(info proto.Trigger) (proto.TestResult, error)

	// Called once at the end, before the plugin is killed
	Finish() error
}
INTERFACES

The interface all test plugins must implement

type SynTestPluginGRPCClient

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

func (*SynTestPluginGRPCClient) Finish

func (t *SynTestPluginGRPCClient) Finish() error

func (*SynTestPluginGRPCClient) Initialise

func (t *SynTestPluginGRPCClient) Initialise(config proto.SynTestConfig) error

func (*SynTestPluginGRPCClient) PerformTest

func (t *SynTestPluginGRPCClient) PerformTest(trigger proto.Trigger) (proto.TestResult, error)

type SynTestPluginGRPCServer

type SynTestPluginGRPCServer struct {
	Impl SynTestPlugin
}

func (*SynTestPluginGRPCServer) Finish

func (*SynTestPluginGRPCServer) Initialise

func (s *SynTestPluginGRPCServer) Initialise(ctx context.Context, config *proto.SynTestConfig) (*proto.Empty, error)

func (*SynTestPluginGRPCServer) PerformTest

func (s *SynTestPluginGRPCServer) PerformTest(ctx context.Context, trigger *proto.Trigger) (*proto.TestResult, error)

type TestDetailsLogger

type TestDetailsLogger struct {
	Res proto.TestResult
	// contains filtered or unexported fields
}

Simple helper struct to output logs in the test result details

func (*TestDetailsLogger) Log

func (l *TestDetailsLogger) Log(msg string)

type TestRunStatus

type TestRunStatus int

Status of a test run

const (
	Failing TestRunStatus = 1
	Warning TestRunStatus = 2
	Passing TestRunStatus = 3
	Unknown TestRunStatus = 0
)

func GetTestRunStatus

func GetTestRunStatus(testRun proto.TestRun) TestRunStatus

Computes test run status from the test run results

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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