proc

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AverageWindow number of points to keep
	AverageWindow = 1000
	// RateDuration duration to keep the items
	RateDuration = time.Second
)

Variables

This section is empty.

Functions

func GetAppStateStatus

func GetAppStateStatus(id watcher.Identity, services []*ServiceState, desired int) watcher.Status

GetAppStateStatus a helper function to get the status of the app

func GetContainerStateStatus

func GetContainerStateStatus(state ContainerState) (watcher.Status, *watcher.ContainerStatusSource)

GetContainerStateStatus a helper function to get the status of the container

func GetPodStatus

func GetPodStatus(pod Pod) watcher.Status

GetPodStatus a helper function to get the status of a pod

func GetServiceStateStatus

func GetServiceStateStatus(id watcher.Identity, pods []watcher.Status, replicas int) watcher.Status

GetServiceStateStatus a helper function to get the status of the service

func WithLock

func WithLock(lockable Lockable, fn func())

WithLock runs a function with a lock

func WithReadLock

func WithReadLock(lockable ReadLockable, fn func())

WithReadLock runs a function with read lock

Types

type AppState

type AppState struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

AppState holds application (namespace) state

func (*AppState) GetService

func (app *AppState) GetService(id uuid.UUID) (*ServiceState, bool)

GetService gets a service with id

func (*AppState) GetStatus

func (app *AppState) GetStatus() watcher.Status

GetStatus getter for AppState.status

func (*AppState) NewService

func (app *AppState) NewService(
	id uuid.UUID,
) *ServiceState

NewService creates a new service with a given id

func (*AppState) SetDesiredServices

func (app *AppState) SetDesiredServices(services []uuid.UUID)

SetDesiredServices setter for AppState.desiredServices

func (*AppState) SetStatus

func (app *AppState) SetStatus(status watcher.Status)

SetStatus setter for AppState.status

type ContainerState

type ContainerState struct {
	Current              kapi.ContainerState
	LastTerminationState kapi.ContainerState
}

ContainerState a struct to hold the container state it keeps the last termination state to detect OOMs in case of CrashLoops

func (*ContainerState) IsOOMKilled

func (state *ContainerState) IsOOMKilled() bool

IsOOMKilled returns if the service is oom killed

type Database

type Database interface {
	WriteEvent(event *watcher.Event) error
	WriteEvents(events []*watcher.Event) error
}

Database eventer

type Identifiable

type Identifiable interface {
	GetLabels() map[string]string
	GetNamespace() string
	GetName() string
	GroupVersionKind() schema.GroupVersionKind
}

Identifiable an identifiable kubernetes entity

type Identificator

type Identificator interface {
	GetID(resource Identifiable) (string, error)
	GetAccountID(resource Identifiable) (uuid.UUID, error)
	GetApplicationID(resource Identifiable) (uuid.UUID, error)
	GetServiceID(resource Identifiable) (uuid.UUID, error)
	GetContainerID(pod Identifiable, containerName string) (uuid.UUID, error)
	IsIgnored(resource Identifiable) bool
}

Identificator an interface to represent entities able to identify identifiables

type Lockable

type Lockable interface {
	Lock()
	Unlock()
}

Lockable Same interface as sync.Locker but sync package doesn't have interface for read locker

type Observer

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

Observer kubernetes objects observer

func NewObserver

func NewObserver(
	clientset *kubernetes.Clientset,
	clientV1 *v1client.AppsV1Client,
	batchV1Beta1 *beta1batchclient.BatchV1beta1Client,
	identificator Identificator,
	health *health.Health,
) *Observer

NewObserver creates a new observer

func (*Observer) GetPipePods

func (observer *Observer) GetPipePods() chan Pod

GetPipePods getter for observer.pods

func (*Observer) GetPipeReplicas

func (observer *Observer) GetPipeReplicas() chan ReplicaSpec

GetPipeReplicas getter for observer.replicas

func (*Observer) SetSyncCallback

func (observer *Observer) SetSyncCallback(fn func())

SetSyncCallback setter for sync callback

func (*Observer) Start

func (observer *Observer) Start()

Start start the observer

type Pod

type Pod struct {
	Name          string                       `json:"name"`
	ID            string                       `json:"id"`
	AccountID     uuid.UUID                    `json:"account_id"`
	ApplicationID uuid.UUID                    `json:"application_id"`
	ServiceID     uuid.UUID                    `json:"service_id"`
	Status        watcher.Status               `json:"status"`
	Containers    map[uuid.UUID]ContainerState `json:"containers"`
}

Pod pod type

func (*Pod) GetIdentity

func (pod *Pod) GetIdentity() watcher.Identity

GetIdentity returns an identity for the pod

type PodName

type PodName = string

PodName pod name

type Proc

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

Proc events processor

func NewProc

func NewProc(
	pods chan Pod, replicas chan ReplicaSpec,
	changer StatusChanger, database Database,
	threads int,
	health *health.Health,
) *Proc

NewProc creates a new processor

func (*Proc) SetSynced

func (proc *Proc) SetSynced()

SetSynced sync all entities

func (*Proc) Start

func (proc *Proc) Start()

Start starts the processor

type ReadLockable

type ReadLockable interface {
	RLock()
	RUnlock()
}

ReadLockable defines only read lock functions

type ReplicaSpec

type ReplicaSpec struct {
	Name          string
	ID            string
	AccountID     uuid.UUID
	ApplicationID uuid.UUID
	ServiceID     uuid.UUID
	Replicas      int
}

ReplicaSpec returns an identity for a replicated service

func (*ReplicaSpec) GetIdentity

func (spec *ReplicaSpec) GetIdentity() watcher.Identity

GetIdentity returns an identity for the service

type ServiceState

type ServiceState struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

ServiceState defines the service state

func (*ServiceState) GetPodStatus

func (service *ServiceState) GetPodStatus(name string) (watcher.Status, bool)

GetPodStatus returns the status of a pod by its name that belongs to the service

func (*ServiceState) GetReplicas

func (service *ServiceState) GetReplicas() int

GetReplicas getter for service.replicas

func (*ServiceState) GetStatus

func (service *ServiceState) GetStatus() watcher.Status

GetStatus getter for service.status

func (*ServiceState) IsSameContainerState

func (service *ServiceState) IsSameContainerState(
	container uuid.UUID,
	state ContainerState,
) bool

IsSameContainerState checks if the state is the same for a container inside the service

func (*ServiceState) RemovePodStatus

func (service *ServiceState) RemovePodStatus(name string)

RemovePodStatus removes pod status by name

func (*ServiceState) SetContainerState

func (service *ServiceState) SetContainerState(
	container uuid.UUID, state ContainerState,
)

SetContainerState setter for container state

func (*ServiceState) SetPodStatus

func (service *ServiceState) SetPodStatus(name string, status watcher.Status)

SetPodStatus sets a status for a pod by its name

func (*ServiceState) SetReplicas

func (service *ServiceState) SetReplicas(replicas int)

SetReplicas setter for service,replicas represents the number of replicas of the service

func (*ServiceState) SetStatus

func (service *ServiceState) SetStatus(status watcher.Status)

SetStatus setter for service.status

type States

type States struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

States global state for the processor

func NewStates

func NewStates() *States

NewStates returns a new states

func (*States) GetApp

func (states *States) GetApp(id uuid.UUID) (*AppState, bool)

GetApp gets app by id

func (*States) NewApp

func (states *States) NewApp(
	id uuid.UUID, accountID uuid.UUID,
) *AppState

NewApp creates a new app

type StatusChanger

type StatusChanger interface {
	GetApplicationDesiredServices(uuid.UUID) ([]uuid.UUID, error)
	ChangeStatus(string, uuid.UUID, watcher.Status, *watcher.ContainerStatusSource)
}

StatusChanger interface for status changer

type Syncer

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

Syncer keeps track of synced entities

func NewSyncer

func NewSyncer() *Syncer

NewSyncer creates a new syncer

func (*Syncer) InformResource

func (syncer *Syncer) InformResource(resource string, version string)

InformResource set version and sync resource

func (*Syncer) OnHandle

func (syncer *Syncer) OnHandle(resource string, version string)

OnHandle look a given resource to start handling

func (*Syncer) OnProcess

func (syncer *Syncer) OnProcess(resource string, version string)

OnProcess start processing resource and unlock

func (*Syncer) SetOnSync

func (syncer *Syncer) SetOnSync(fn func())

SetOnSync set on sync hook

Jump to

Keyboard shortcuts

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