common

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

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 9

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

Building proto files

Run make proto to build proto files

Documentation

Index

Constants

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
)

Time constants

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 (
	K8sDiscoverLabel    string = "synheart.infra.webex.com/discover"
	K8sDiscoverLabelVal string = "true"
	SpecialKeyNodeName  string = "$nodeName"
	SpecialKeyAgentId   string = "$agentId"
	SpecialKeyPodName   string = "$podName"
	SpecialKeyAgentNs   string = "$agentNamespace"
)

Other constants

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

AddPrometheusMetricsToResults Adds a prometheus metric to a test result

func ComputeAgentId

func ComputeAgentId(podName string, namespace string) string

ComputeAgentId Computes agent id: it's just a string representing the pod name & namespace

func ComputePluginId

func ComputePluginId(testName string, namespace string, agentId string) string

ComputePluginId Computes plugin id, which represents a unique syntest plugin in the cluster

func ComputeSynTestConfigId

func ComputeSynTestConfigId(testName string, testNamespace string) string

ComputeSynTestConfigId Computes config id, which is a unique identifier for a syntest config using name and namespace

func FailedTestResult

func FailedTestResult() proto.TestResult

FailedTestResult Gets an empty failed test result

func GetPluginIdComponents

func GetPluginIdComponents(pluginId string) (testName, testNs, podName, podNs string, err error)

GetPluginIdComponents Splits the plugin Id into all its different compoenents

func IsAgentValidForSynTest

func IsAgentValidForSynTest(agentConfig AgentConfig, agentId, testName, testNs, testNodeSelector string,
	testPodLabelSelector, testLabels map[string]string, logger hclog.Logger) (bool, error)

IsAgentValidForSynTest checks if the agent matches the selectors in the SynTest

func ParseYMLConfig

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

ParseYMLConfig Parses and prints a yaml config

Types

type AgentConfig

type AgentConfig struct {
	MatchTestNamespaces []string                `yaml:"matchTestNamespaces" json:"matchTestNamespaces"`
	MatchTestLabels     map[string]string       `yaml:"matchTestLabels" json:"matchTestLabels"`
	LabelFileLocation   string                  `yaml:"labelFileLocation" json:"labelFileLocation"`
	SyncFrequency       time.Duration           `yaml:"syncFrequency" json:"syncFrequency"`
	GracePeriod         time.Duration           `yaml:"gracePeriod" json:"gracePeriod"`
	PrometheusConfig    PrometheusConfig        `yaml:"prometheus" json:"prometheusConfig"`
	StoreConfig         StorageConfig           `yaml:"storage" json:"storeConfig"`
	PrintPluginLogs     PrintPluginLogOption    `yaml:"printPluginLogs" json:"printPluginLogs"`
	EnabledPlugins      []PluginDiscoveryConfig `yaml:"enabledPlugins" json:"enabledPlugins"`
	DebugMode           bool                    `yaml:"debugMode" json:"debugMode"`

	// Populated at run time
	DiscoveredPlugins map[string][]string `json:"discoveredPlugins"`
	RunTimeInfo       AgentInfo           `json:"runTimeInfo"`
	MatchNamespaceSet map[string]bool     `json:"matchNamespaceSet"` // so we can check if a namespace is being watched in O(1)
}

type AgentInfo

type AgentInfo struct {
	NodeName       string            `json:"nodeName"`       // derived from Downward api
	PodName        string            `json:"podName"`        // derived from Downward api
	PodLabels      map[string]string `json:"podLabels"`      // derived from Downward api
	AgentNamespace string            `json:"agentNamespace"` // derived from Downward api
}

type AgentStatus

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

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 PluginDiscoveryConfig

type PluginDiscoveryConfig struct {
	Path string
	Cmd  string
}

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"`
	Config         interface{}   `json:"config" yaml:"config"`
	Restarts       int           `json:"restarts" yaml:"restarts"`
	RestartBackOff string        `json:"restartBackOff" yaml:"restartBackOff"`
	TotalRestarts  int           `json:"totalRestarts" yaml:"totalRestarts"`
	RunningSince   time.Time     `json:"runningSince" yaml:"runningSince"`
	LastUpdated    time.Time     `json:"lastUpdated" yaml:"lastUpdated"`
}

type PrintPluginLogOption

type PrintPluginLogOption string
const (
	LogOnFail PrintPluginLogOption = "onFail"
	LogNever  PrintPluginLogOption = "never"
	LogAlways PrintPluginLogOption = "always"
)

type PrometheusConfig

type PrometheusConfig struct {
	ServerAddress     string            `yaml:"address"`
	Push              bool              `yaml:"push"`
	PrometheusPushUrl string            `yaml:"pushUrl"`
	Labels            map[string]string `yaml:"labels"`
}

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"
	Restarting    RoutineStatus = "restarting"
	StatusUnknown RoutineStatus = "unknown"
)

type StorageConfig

type StorageConfig struct {
	Type       string        `yaml:"type"`
	BufferSize int           `yaml:"bufferSize"`
	Address    string        `yaml:"address"`
	ExportRate time.Duration `yaml:"exportRate"`
}

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
	proto.UnimplementedSynTestPluginServer
}

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 SyntestConfigStatus

type SyntestConfigStatus struct {
	Deployed  bool   `json:"deployed"`
	Message   string `json:"message"`
	Agent     string `json:"agent"`
	Timestamp string `json:"timestamp"`
}

type SyntestConfigSummary

type SyntestConfigSummary struct {
	Name        string `json:"name"`
	Namespace   string `json:"namespace"`
	ConfigId    string `json:"configId"`
	Version     string `json:"version"`
	DisplayName string `json:"displayName"`
	Description string `json:"description"`
	Plugin      string `json:"plugin"`
	Repeat      string `json:"repeat"`
}

type TestDetailsLogger

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

TestDetailsLogger is a simple helper struct to output logs in the test result details

func (*TestDetailsLogger) Log

func (l *TestDetailsLogger) Log(msg string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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