utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: Apache-2.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const AgentLabelKey = "app"

Variables

View Source
var AgentLabelValues = []string{"netchecker-agent", "netchecker-agent-hostnet"}

Functions

func NewK8sStorer added in v1.2.0

func NewK8sStorer() (*k8sAgentStorage, error)

func ProcessRequest

func ProcessRequest(r *http.Request, dst interface{}, rw http.ResponseWriter) error

func ProcessResponse

func ProcessResponse(rw http.ResponseWriter, data interface{}) error

func UpdateAgentBaseMetrics

func UpdateAgentBaseMetrics(am NcAgentMetrics, name string, report, error bool)

UpdateAgentBaseMetrics function updates basic metrics with reports and error counters

func UpdateAgentProbeMetrics

func UpdateAgentProbeMetrics(ai ext_v1.AgentSpec, am AgentMetrics)

UpdateAgentProbeMetrics function updates HTTP probe metrics.

Types

type AgentInfo

type AgentInfo struct {
	ReportInterval int                 `json:"report_interval"`
	NodeName       string              `json:"nodename"`
	PodName        string              `json:"podname"`
	HostDate       time.Time           `json:"hostdate"`
	LastUpdated    time.Time           `json:"last_updated"`
	LookupHost     map[string][]string `json:"nslookup"`
	NetworkProbes  []ProbeResult       `json:"network_probes"`
	IPs            map[string][]string `json:"ips"`
}

AgentInfo is payload structure for keepalive message received from agent.

type AgentMetrics

type AgentMetrics struct {
	ErrorCount            prometheus.Counter
	ReportCount           prometheus.Counter
	PodName               string
	ErrorsFromLastReport  int
	ProbeConnectionResult *prometheus.GaugeVec
	ProbeHTTPCode         *prometheus.GaugeVec
	ProbeTotal            *prometheus.GaugeVec
	ProbeContentTransfer  *prometheus.GaugeVec
	ProbeTCPConnection    *prometheus.GaugeVec
	ProbeDNSLookup        *prometheus.GaugeVec
	ProbeConnect          *prometheus.GaugeVec
	ProbeServerProcessing *prometheus.GaugeVec
}

AgentMetrics contains Prometheus entities and agent data required for reporting metrics for particular agent.

func NewAgentMetrics

func NewAgentMetrics(ai *ext_v1.AgentSpec) AgentMetrics

NewAgentMetrics setup prometheus metrics

type AgentStorer added in v1.2.0

type AgentStorer interface {
	UpdateAgents(http.ResponseWriter, *http.Request, httprouter.Params) (ext_v1.AgentSpec, error)
	GetSingleAgent(http.ResponseWriter, *http.Request, httprouter.Params)
	GetAgents(http.ResponseWriter, *http.Request, httprouter.Params)
	CleanCacheOnDemand(http.ResponseWriter)
	CheckAgents() ([]string, []string, error)
	//
	AgentCache() NcAgentCache                   // Returns Agent Cache map (RO)
	AgentCacheUpdate(string, *ext_v1.AgentSpec) // (agentName, agent.Spec) may be interface{} should be used, because format is storage-specific
	// required for tests
	SetKubeClient(cl Proxy)
}

type AppConfig added in v1.2.0

type AppConfig struct {
	sync.Mutex           // ensures atomic writes; protects the following fields
	UseKubeClient bool   // use k8s TPR (true) or etcd (false) as a data storage
	EtcdEndpoints string // endpoints (IPaddress1:PORT1[,IPaddress2:PORT2]) of etcd server
	// when etcd is being used as a data storage
	EtcdTree      string        // Root of NetChecker server etcd tree
	EtcdCertFile  string        // SSL certificate file when using HTTPS to connect to etcd
	EtcdKeyFile   string        // SSL key file when using HTTPS to connect to etcd
	EtcdCAFile    string        // SSL CA file when using HTTPS to connect to etcd
	HttpListen    string        // REST API endpoint (IPaddress:PORT) for netchecker server to listen to
	PingTimeout   time.Duration // etcd ping timeout (sec)
	ReportTTL     time.Duration // TTL for Agent report data when etcd is in use (sec)
	CheckInterval time.Duration // Interval of checking that agents data is up-to-date
}

func GetOrCreateConfig added in v1.2.0

func GetOrCreateConfig() *AppConfig

func (*AppConfig) ToJson added in v1.2.0

func (c *AppConfig) ToJson() ([]byte, error)

func (*AppConfig) ToYaml added in v1.2.0

func (c *AppConfig) ToYaml() ([]byte, error)

type CheckConnectivityInfo

type CheckConnectivityInfo struct {
	Message  string   `json="message"`
	Absent   []string `json="outdated,omitempty"`
	Outdated []string `json="absent,omitempty"`
}

CheckConnectivityInfo is payload structure for server answer to connectivity check request.

type EtcdAgentStorage added in v1.2.0

type EtcdAgentStorage struct {
	sync.Mutex // ensures atomic writes; protects the following fields

	NcAgentCache NcAgentCache
	// contains filtered or unexported fields
}

func NewEtcdStorer added in v1.2.0

func NewEtcdStorer() (*EtcdAgentStorage, error)

func (*EtcdAgentStorage) AgentCache added in v1.2.0

func (s *EtcdAgentStorage) AgentCache() NcAgentCache

func (*EtcdAgentStorage) AgentCacheUpdate added in v1.2.0

func (h *EtcdAgentStorage) AgentCacheUpdate(key string, ag *ext_v1.AgentSpec)

func (*EtcdAgentStorage) CheckAgents added in v1.2.0

func (s *EtcdAgentStorage) CheckAgents() ([]string, []string, error)

func (*EtcdAgentStorage) CleanCacheOnDemand added in v1.2.0

func (h *EtcdAgentStorage) CleanCacheOnDemand(rw http.ResponseWriter)

func (*EtcdAgentStorage) GetAgents added in v1.2.0

func (*EtcdAgentStorage) GetSingleAgent added in v1.2.0

func (s *EtcdAgentStorage) GetSingleAgent(rw http.ResponseWriter, r *http.Request, rp httprouter.Params)

func (*EtcdAgentStorage) PingETCD added in v1.2.0

func (s *EtcdAgentStorage) PingETCD() error

func (*EtcdAgentStorage) SetKubeClient added in v1.2.0

func (h *EtcdAgentStorage) SetKubeClient(cl Proxy)

func (*EtcdAgentStorage) UpdateAgents added in v1.2.0

type EtcdConfig added in v1.2.0

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

type Handler

type Handler struct {
	Agents      AgentStorer
	Metrics     NcAgentMetrics
	HTTPHandler http.Handler
}

func NewHandler

func NewHandler(useKubeClient bool) (*Handler, error)

func (*Handler) AddMiddleware

func (h *Handler) AddMiddleware()

func (*Handler) CleanCache

func (h *Handler) CleanCache(handle httprouter.Handle) httprouter.Handle

func (*Handler) CollectAgentsMetrics

func (h *Handler) CollectAgentsMetrics(checkInterval time.Duration, useKubeClient bool)

func (*Handler) ConnectivityCheck

func (h *Handler) ConnectivityCheck(rw http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*Handler) SetupRouter

func (h *Handler) SetupRouter()

func (*Handler) UpdateAgents

func (h *Handler) UpdateAgents(rw http.ResponseWriter, r *http.Request, rp httprouter.Params)

type K8sConnection added in v1.2.0

type K8sConnection struct {
	KubeClient Proxy
}

type KubeProxy

type KubeProxy struct {
	Client kubernetes.Interface
}

func (*KubeProxy) Pods

func (kp *KubeProxy) Pods() (*v1.PodList, error)

func (*KubeProxy) SetupClientSet

func (kp *KubeProxy) SetupClientSet(config *rest.Config) (*kubernetes.Clientset, error)

SetupClientSet is a function for initialize kubernetes clientset

type NcAgentCache added in v1.2.0

type NcAgentCache map[string]ext_v1.AgentSpec

type NcAgentMetrics added in v1.2.0

type NcAgentMetrics map[string]AgentMetrics

type ProbeResult

type ProbeResult struct {
	URL              string
	ConnectionResult int
	HTTPCode         int
	Total            int
	ContentTransfer  int
	TCPConnection    int
	DNSLookup        int
	Connect          int
	ServerProcessing int
}

ProbeResult structure for network probing results

type Proxy

type Proxy interface {
	Pods() (*v1.PodList, error)
}

Jump to

Keyboard shortcuts

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