discovery

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 10 Imported by: 0

README

discovery

Service discovery for prometheus with etcd backend.

Documentation

Overview

Package discovery contains domain logic for service discovery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServersBySelector

func ServersBySelector(selector labels.Selector) func(Server) bool

ServersBySelector filters Servers by Selector.

func ServiceByEndpoint

func ServiceByEndpoint(e fmt.Stringer) func(Service) bool

ServiceByEndpoint filters Services by Endpoint.

func ServiceByName

func ServiceByName(name string) func(Service) bool

ServiceByName filters Services by Name.

func ServiceBySelector

func ServiceBySelector(selector labels.Selector) func(Service) bool

ServiceBySelector filters Services by Selector.

Types

type ExportConfig

type ExportConfig int

ExportConfig defines how services in a namespaces are exported for file-based discovery.

const (
	Disabled ExportConfig = iota // disabled
	Standard                     // standard
	Blackbox                     // blackbox
)

All possible export configurations:

Standard: standard configuration Blackbox: for blackbox configurations Disabled: no export

func (ExportConfig) String

func (i ExportConfig) String() string

type Labels

type Labels map[string]string

Labels represents key value pairs.

func (Labels) Get

func (l Labels) Get(key string) string

Get gets the value for key.

func (Labels) Has

func (l Labels) Has(key string) bool

Has returs true if Labels contains key.

func (Labels) String

func (l Labels) String() string

type Namespace

type Namespace struct {
	Name     string       `json:"name"`
	Export   ExportConfig `json:"export"`
	Modified time.Time    `json:"modified,omitempty"`
}

Namespace represents a namespace.

func DefaultNamespace

func DefaultNamespace() *Namespace

DefaultNamespace is used when no namespace is given.

func (Namespace) Header

func (n Namespace) Header() []string

Header creates the header for csv or table output.

func (Namespace) Row

func (n Namespace) Row() []string

Row creates a row for csv or table output.

func (Namespace) Validate

func (n Namespace) Validate() error

Validate checks if a services values are valid.

type Namespaces

type Namespaces []Namespace

Namespaces is a list of namespaces.

func (Namespaces) Index

func (n Namespaces) Index(name string) int

Index returns the index of a namespace with name. If not found -1 is returned.

func (Namespaces) Names

func (n Namespaces) Names() []string

Names returns the server names as slice of strings.

func (Namespaces) SortByDate

func (n Namespaces) SortByDate()

SortByDate sorts servers by registerdate.

func (Namespaces) SortByName

func (n Namespaces) SortByName()

SortByName sorts servers by name.

type Server

type Server struct {
	Name     string      `json:"name"`
	Labels   Labels      `json:"labels"`
	State    ServerState `json:"state"`
	Modified time.Time   `json:"modified,omitempty"`
}

Server represents a registered server.

With kubernetes selectors it is possible to select a server by labels. If IsActive is false, no services are distributed to this server.

func NewServer

func NewServer(name string, l Labels) *Server

NewServer creates a new server instance.

func (Server) Header

func (s Server) Header() []string

Header creates the header for csv or table output.

func (Server) KeyVals

func (s Server) KeyVals() []interface{}

KeyVals represents the service as slice of interface.

func (Server) Row

func (s Server) Row() []string

Row creates a row for csv or table output.

func (Server) Validate

func (s Server) Validate() error

Validate checks if a services values are valid.

type ServerState

type ServerState int

ServerState describes the server state.

const (
	Leaving ServerState = iota // leaving
	Joining                    // joining
	Active                     // active
)

All possible export states:

Leaving: server was unregistered and is leaving Joining: server was registered and is ready for services Active: server already has services configured

func (ServerState) String

func (i ServerState) String() string

type Servers

type Servers []Server

Servers is a list of servers.

func (Servers) Enabled

func (s Servers) Enabled() Servers

Enabled returns all active and joining servers.

func (Servers) Filter

func (s Servers) Filter(f func(Server) bool) Servers

Filter filters Servers.

func (Servers) Names

func (s Servers) Names() []string

Names returns the server names as slice of strings.

func (Servers) SortByDate

func (s Servers) SortByDate()

SortByDate sorts servers by registerdate.

func (Servers) SortByName

func (s Servers) SortByName()

SortByName sorts servers by name.

type Service

type Service struct {
	ID          string    `json:"id,omitempty"`
	Name        string    `json:"name,omitempty"`
	Namespace   string    `json:"namespace,omitempty"`
	Endpoint    *url.URL  `json:"endpoint,omitempty"`
	Selector    string    `json:"selector,omitempty"`
	Servers     []string  `json:"servers,omitempty"`
	Labels      Labels    `json:"labels,omitempty"`
	Description string    `json:"description,omitempty"`
	Modified    time.Time `json:"modified,omitempty"`
}

Service contains all information for service discovery.

func MustNewService

func MustNewService(name, endpoint string) *Service

MustNewService panics if endpoint or name is not valid.

func NewService

func NewService(name, endpoint string) (*Service, error)

NewService creates a new service with ID and timestamp.

func (Service) HasServer

func (s Service) HasServer(serverName string) bool

HasServer returns true if service has serverName in its Servers slice.

func (Service) Header

func (s Service) Header() []string

Header creates the header for csv or table output.

func (Service) KeyVals

func (s Service) KeyVals() []interface{}

KeyVals represents the service as slice of interface.

func (Service) MarshalJSON

func (s Service) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaler.

func (Service) Row

func (s Service) Row() []string

Row creates a row for csv or table output.

func (*Service) UnmarshalJSON

func (s *Service) UnmarshalJSON(j []byte) error

UnmarshalJSON is a custom json unmarshaller.

func (Service) Validate

func (s Service) Validate() error

Validate checks if a services values are valid.

type Services

type Services []Service

Services is a slice of Serices

func (Services) Filter

func (s Services) Filter(f func(Service) bool) Services

Filter filters Services.

Directories

Path Synopsis
cmd
internal
auth
Package auth handles openid connect and jwt (for access tokens) authentication and authorization.
Package auth handles openid connect and jwt (for access tokens) authentication and authorization.
cmd/client
Package client represents the discovery client command.
Package client represents the discovery client command.
cmd/server
Package server represents the discovery server command.
Package server represents the discovery server command.
exporter
Package exporter exports services to filesystem for prometheus file discovery.
Package exporter exports services to filesystem for prometheus file discovery.
hash
Package hash implements a consistent hasher described as described in http://arxiv.org/pdf/1406.2294v1.pdf
Package hash implements a consistent hasher described as described in http://arxiv.org/pdf/1406.2294v1.pdf
registry
Package registry is responsible for registering and unregistering services and servers.
Package registry is responsible for registering and unregistering services and servers.
repo
Package repo is responsilbe to store services and servers in a (etcd) repository.
Package repo is responsilbe to store services and servers in a (etcd) repository.
server
Package server is responsible for starting the grpc and http server.
Package server is responsible for starting the grpc and http server.
server/convert
Package convert converts proto types to domain types and vice versa.
Package convert converts proto types to domain types and vice versa.
pkg
discoverypb
Package discoveryv1 is a reverse proxy.
Package discoveryv1 is a reverse proxy.

Jump to

Keyboard shortcuts

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