service

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircuitBreakerPolicy

type CircuitBreakerPolicy struct {
	MaxConnections             uint32
	MaxPendingRequests         uint32
	MaxRequests                uint32
	MaxRetries                 uint32
	ConsecutiveErrorsThreshold uint32
	IntervalMS                 uint64
	BaseEjectionTimeMS         uint64
	State                      CircuitBreakerState
	LastStateChange            int64
	FailureCount               uint32
	SuccessCount               uint32
	HalfOpenAllowedCalls       uint32
}

CircuitBreakerPolicy represents a circuit breaker policy

type CircuitBreakerState

type CircuitBreakerState string

CircuitBreakerState represents the state of a circuit breaker

const (
	// CircuitBreakerClosed indicates the circuit breaker is closed (normal operation)
	CircuitBreakerClosed CircuitBreakerState = "closed"
	// CircuitBreakerOpen indicates the circuit breaker is open (requests are rejected)
	CircuitBreakerOpen CircuitBreakerState = "open"
	// CircuitBreakerHalfOpen indicates the circuit breaker is half-open (testing if service is healthy)
	CircuitBreakerHalfOpen CircuitBreakerState = "half_open"
)

type Discovery

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

Discovery handles service discovery and health checking

func NewDiscovery

func NewDiscovery(logger *logrus.Logger) (*Discovery, error)

NewDiscovery creates a new service discovery manager

func (*Discovery) AddRoutingRule

func (d *Discovery) AddRoutingRule(rule RoutingRule) error

AddRoutingRule adds a routing rule

func (*Discovery) CheckCircuitBreaker

func (d *Discovery) CheckCircuitBreaker(serviceName string, endpointIP string) (bool, error)

CheckCircuitBreaker checks if a circuit breaker is open

func (*Discovery) Close

func (d *Discovery) Close() error

Close closes the service discovery

func (*Discovery) ConfigureHealthCheck

func (d *Discovery) ConfigureHealthCheck(serviceName string, config HealthCheckConfig) error

ConfigureHealthCheck configures health checks for a service

func (*Discovery) ConfigureLoadBalancing

func (d *Discovery) ConfigureLoadBalancing(serviceName string, strategy LoadBalancingStrategy) error

ConfigureLoadBalancing configures load balancing for a service

func (*Discovery) ConfigureServiceMesh

func (d *Discovery) ConfigureServiceMesh(serviceName string, config ServiceMeshConfig) error

ConfigureServiceMesh configures service mesh for a service

func (*Discovery) ConfigureTrafficSplit

func (d *Discovery) ConfigureTrafficSplit(config TrafficSplitConfig) error

ConfigureTrafficSplit configures traffic splitting for a service

func (*Discovery) DeregisterService

func (d *Discovery) DeregisterService(
	serviceName string,
	nodeID string,
	ipAddress string,
	port uint16,
) error

DeregisterService deregisters a service endpoint

func (*Discovery) GetHealthCheckStatistics

func (d *Discovery) GetHealthCheckStatistics() map[string]float64

GetHealthCheckStatistics returns statistics for health checks

func (*Discovery) GetProxyMetrics

func (d *Discovery) GetProxyMetrics() map[string]float64

GetProxyMetrics returns metrics for the proxy

func (*Discovery) GetServiceByDomain

func (d *Discovery) GetServiceByDomain(domain string) (string, []ServiceEndpoint)

GetServiceByDomain returns a service by domain

func (*Discovery) GetServiceEndpointWithOptions

func (d *Discovery) GetServiceEndpointWithOptions(
	serviceName string,
	clientIP string,
	sessionID string,
	preferredVersion string,
) *ServiceEndpoint

GetServiceEndpointWithOptions returns a service endpoint with options

func (*Discovery) GetServiceEndpoints

func (d *Discovery) GetServiceEndpoints(serviceName string) []ServiceEndpoint

GetServiceEndpoints returns the endpoints for a service

func (*Discovery) GetServiceURL

func (d *Discovery) GetServiceURL(ctx context.Context, serviceName string) (string, error)

GetServiceURL returns the URL for a service

func (*Discovery) GetServiceURLSimple

func (d *Discovery) GetServiceURLSimple(serviceName string) string

GetServiceURLSimple is the original GetServiceURL method without context and error

func (*Discovery) GetTrafficSplit

func (d *Discovery) GetTrafficSplit(serviceName string) *TrafficSplitConfig

GetTrafficSplit returns the traffic split configuration for a service

func (*Discovery) HandleContainerCreated

func (d *Discovery) HandleContainerCreated(
	containerID string,
	serviceName string,
	domain string,
	nodeID string,
	ipAddress string,
	port uint16,
) error

HandleContainerCreated handles a new container being created

func (*Discovery) HandleContainerRemoved

func (d *Discovery) HandleContainerRemoved(
	containerID string,
	serviceName string,
	nodeID string,
	ipAddress string,
	port uint16,
) error

HandleContainerRemoved handles a container being removed

func (*Discovery) HandleNodeJoined

func (d *Discovery) HandleNodeJoined(nodeID string, nodeIP string) error

HandleNodeJoined handles a node joining the cluster

func (*Discovery) HandleNodeLeft

func (d *Discovery) HandleNodeLeft(nodeID string) error

HandleNodeLeft handles a node leaving the cluster

func (*Discovery) Initialize

func (d *Discovery) Initialize() error

Initialize initializes the service discovery system

func (*Discovery) ListRoutingRules

func (d *Discovery) ListRoutingRules() []RoutingRule

ListRoutingRules returns all routing rules

func (*Discovery) ListServices

func (d *Discovery) ListServices() map[string][]ServiceEndpoint

ListServices returns a list of all services

func (*Discovery) MarkEndpointUnhealthy

func (d *Discovery) MarkEndpointUnhealthy(serviceName string, ipAddress string, port uint16) error

MarkEndpointUnhealthy marks an endpoint as unhealthy

func (*Discovery) RecordCircuitBreakerResult

func (d *Discovery) RecordCircuitBreakerResult(serviceName string, endpointIP string, success bool) error

RecordCircuitBreakerResult records the result of a request for circuit breaking

func (*Discovery) RecordConnectionCompletion

func (d *Discovery) RecordConnectionCompletion(
	serviceName string,
	ipAddress string,
	port uint16,
	durationMS float64,
	success bool,
) error

RecordConnectionCompletion records the completion of a connection

func (*Discovery) RegisterService

func (d *Discovery) RegisterService(
	serviceConfig *api.ServiceConfig,
	nodeID string,
	ipAddress string,
	port uint16,
) error

RegisterService registers a service endpoint

func (*Discovery) RegisterServiceWithVersion

func (d *Discovery) RegisterServiceWithVersion(
	serviceConfig *api.ServiceConfig,
	nodeID string,
	ipAddress string,
	port uint16,
	version string,
	weight uint32,
) error

RegisterServiceWithVersion registers a service with a specific version

func (*Discovery) RemoveRoutingRule

func (d *Discovery) RemoveRoutingRule(serviceName string, pathPrefix string) error

RemoveRoutingRule removes a routing rule

func (*Discovery) RemoveTrafficSplit

func (d *Discovery) RemoveTrafficSplit(serviceName string) error

RemoveTrafficSplit removes traffic splitting for a service

func (*Discovery) WithNetworkManager

func (d *Discovery) WithNetworkManager(networkManager interface{}) *Discovery

WithNetworkManager sets the network manager

func (*Discovery) WithNodeManager

func (d *Discovery) WithNodeManager(nodeManager interface{}) *Discovery

WithNodeManager sets the node manager

type EndpointStats

type EndpointStats struct {
	ActiveConnections uint32
	TotalRequests     uint64
	FailedRequests    uint64
	AvgResponseTimeMS float64
	LastSelected      int64
}

EndpointStats represents statistics for an endpoint

type HealthCheckConfig

type HealthCheckConfig struct {
	Protocol           HealthCheckProtocol
	Path               string // For HTTP health checks
	IntervalSeconds    uint64
	TimeoutSeconds     uint64
	HealthyThreshold   uint32
	UnhealthyThreshold uint32
}

HealthCheckConfig represents the configuration for health checks

type HealthCheckProtocol

type HealthCheckProtocol string

HealthCheckProtocol represents the protocol for health checks

const (
	// HealthCheckHTTP indicates HTTP health checks
	HealthCheckHTTP HealthCheckProtocol = "http"
	// HealthCheckHTTPS indicates HTTPS health checks
	HealthCheckHTTPS HealthCheckProtocol = "https"
	// HealthCheckTCP indicates TCP health checks
	HealthCheckTCP HealthCheckProtocol = "tcp"
	// HealthCheckCommand indicates command health checks
	HealthCheckCommand HealthCheckProtocol = "command"
)

type LoadBalancingStrategy

type LoadBalancingStrategy string

LoadBalancingStrategy represents the strategy for load balancing

const (
	// LoadBalancingRoundRobin indicates round-robin load balancing
	LoadBalancingRoundRobin LoadBalancingStrategy = "round_robin"
	// LoadBalancingWeightedRoundRobin indicates weighted round-robin load balancing
	LoadBalancingWeightedRoundRobin LoadBalancingStrategy = "weighted_round_robin"
	// LoadBalancingLeastConnections indicates least connections load balancing
	LoadBalancingLeastConnections LoadBalancingStrategy = "least_connections"
	// LoadBalancingRandom indicates random load balancing
	LoadBalancingRandom LoadBalancingStrategy = "random"
	// LoadBalancingIPHash indicates IP hash load balancing
	LoadBalancingIPHash LoadBalancingStrategy = "ip_hash"
)

type RetryPolicy

type RetryPolicy struct {
	MaxRetries uint32
	RetryOn    []string
	TimeoutMS  uint64
}

RetryPolicy represents a retry policy

type RoutingRule

type RoutingRule struct {
	PathPrefix  string
	Headers     map[string]string
	ServiceName string
	Weight      uint32
}

RoutingRule represents a routing rule for a service

type ServiceEndpoint

type ServiceEndpoint struct {
	ServiceName     string
	Domain          string
	IPAddress       string
	Port            uint16
	NodeID          string
	HealthStatus    ServiceHealth
	LastHealthCheck int64
	Version         string
	Weight          uint32
	Metadata        map[string]string
}

ServiceEndpoint represents an endpoint for a service

type ServiceHealth

type ServiceHealth string

ServiceHealth represents the health status of a service

const (
	// ServiceHealthy indicates the service is healthy
	ServiceHealthy ServiceHealth = "healthy"
	// ServiceUnhealthy indicates the service is unhealthy
	ServiceUnhealthy ServiceHealth = "unhealthy"
	// ServiceUnknown indicates the service health is unknown
	ServiceUnknown ServiceHealth = "unknown"
)

type ServiceInfo

type ServiceInfo struct {
	Name            string
	Namespace       string
	Version         string
	Endpoints       []ServiceEndpoint
	Labels          map[string]string
	Annotations     map[string]string
	CreatedAt       time.Time
	UpdatedAt       time.Time
	HealthStatus    ServiceHealth
	LastHealthCheck time.Time
	Metadata        map[string]string
}

ServiceInfo represents information about a service

type ServiceMeshConfig

type ServiceMeshConfig struct {
	Enabled        bool
	MTLSEnabled    bool
	TracingEnabled bool
	RetryPolicy    *RetryPolicy
	TimeoutMS      uint64
	CircuitBreaker *CircuitBreakerPolicy
}

ServiceMeshConfig represents a service mesh configuration

type TrafficSplit

type TrafficSplit struct {
	Version string
	Weight  uint32
}

TrafficSplit represents a traffic split

type TrafficSplitConfig

type TrafficSplitConfig struct {
	ServiceName string
	Splits      []TrafficSplit
}

TrafficSplitConfig represents a traffic split configuration

Jump to

Keyboard shortcuts

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