hubble

package
v0.0.0-...-d591cd7 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2017 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const VERSION string = "0.2"

Version

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendAdapter

type BackendAdapter interface {
	GetAll() ([]*Service, error)
}

BackendAdapter implements GetAll() method

type Dispatcher

type Dispatcher struct {
	TTL          time.Duration
	Services     map[string]*ServiceAtomic
	Exporters    map[string]Exporter
	ToRegister   chan *ServiceAtomic
	ToUnregister chan map[string]*ServiceAtomic
	*sync.RWMutex
}

Dispatcher sends messages to ToRegister and ToUnregister channels according to service list and its params. Dispatcher prevents multiple registration for one service and unregistering for actual service. Services and Exporter are stored in map where key is

func NewDispatcher

func NewDispatcher(ttl int) *Dispatcher

NewDispatcher receives TTL and callback function that should return []*ServiceAtomic. Example:

cb := func() (list []*hubble.ServiceAtomic, err error) {
    services, err := h.Services(filterCB)
    if err != nil {
        return list, err
    }
    for _, svc := range services {
        for _, el := range svc.MakeAtomic(nil) {
            list = append(list, el)
        }
    }
    return list, err
}

d := hubble.NewDispatcher(60)
d.Run(callback)

defer in example function is important. If callback was not return an error Dispatcher receives empty services list. Re-register will be failed because prometheus golang client cannot fully unregister Collector.

func (*Dispatcher) Process

func (d *Dispatcher) Process(f func() ([]*ServiceAtomic, error))

func (*Dispatcher) Register

func (d *Dispatcher) Register(item *ServiceAtomic, exporter Exporter)

Register service and exporter pair in Dispatcher

func (*Dispatcher) Run

func (d *Dispatcher) Run(f func() ([]*ServiceAtomic, error))

Run Dispatcher

func (*Dispatcher) Unregister

func (d *Dispatcher) Unregister(item *ServiceAtomic)

Unregister service in Dispatcher

func (*Dispatcher) UnregisterWithHash

func (d *Dispatcher) UnregisterWithHash(h string)

Unregister service in Dispatcher with only hash identificator provided

type Exporter

type Exporter interface {
	exportertools.Exporter
}
Exporter interface is used to call Close() when Interrupt

or other quit signals are received

type Hubble

type Hubble struct {
	SvcBackend    BackendAdapter
	ParamsBackend KVBackendAdapter
	// contains filtered or unexported fields
}

Hubble stores service and kv backends adapters

func New

func New(sb BackendAdapter, pb KVBackendAdapter, exporterName string) *Hubble

func (*Hubble) Services

func (h *Hubble) Services(filter func(list []*Service) []*Service) ([]*Service, error)

Services() recever a filter callback to filter services will not be used in exporter. Then returns []*Service.

example:

filterCB := func(list []*hubble.Service) []*hubble.Service {
    var servicesForMonitoring []*hubble.Service
    for _, svc := range list {
        if util.IncludesStr(svc.Tags, "goro") {
            servicesForMonitoring = append(servicesForMonitoring, svc)
        }
    }
    return servicesForMonitoring
}

type KVBackendAdapter

type KVBackendAdapter interface {
	GetParams(key string) (*ServiceParams, error)
}

KVBackendAdapter implements GetParams() method should fill ServiceParams part of Service with data

type Service

type Service struct {
	ModifyIndex uint64
	Name        string
	Addresses   map[string]string
	Port        string
	Tags        []string
	*ServiceParams
}

Service main parameters

func DefaultService

func DefaultService() *Service

DefaultService return empty Service instance

func (*Service) MakeAtomic

func (s *Service) MakeAtomic(extraLabels map[string]string) []*ServiceAtomic

MakeAtomic splits Service into list of ServiceAtomic

type ServiceAtomic

type ServiceAtomic struct {
	Name            string
	Address         string
	Port            string
	Tags            []string
	ExtraLabels     map[string]string
	ExporterOptions map[string]string
}
ServiceAtomic is the main useful unit for an expoter.

Actually it is Service splitted by host.

type ServiceParams

type ServiceParams struct {
	ModifyIndex     uint64
	Notifiable      bool              `json:"notifiable"` // useful for Alertmanager
	ExtraLabels     map[string]string `json:"extra_labels"`
	ExporterOptions map[string]string `json:"exporter_options"`
}

ServiceParams struct to keep other service check or metric parameters.

Jump to

Keyboard shortcuts

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