UNPKG

consul-resolver

Version:

A load balancer for Consul services with Redis-based metrics

55 lines (54 loc) 1.78 kB
import { ConsulResolverConfig, ServiceMetrics, SelectionAlgorithm, OptimalServiceResult } from "./types"; declare class ConsulResolver { private config; private currentIndex; private consul; private redis; private cachePrefix; private weights; private metrics; private cacheTTL; private cacheEnabled; private debug; constructor(config: ConsulResolverConfig); private getConnectionKey; private getDNSCacheKey; private getHealthCacheKey; private resolveDNS; private combineHealthAndDNSWeights; /** * Select the optimal service based on the specified algorithm */ selectOptimalService(service: string, algorithm?: SelectionAlgorithm): Promise<OptimalServiceResult>; /** * Get health checks from Consul with caching */ private getHealthChecks; /** * Sort SRV records by priority (lower number is higher priority) */ private sortByPriority; /** * Select a service from SRV records using the specified algorithm */ private selectFromSrvRecords; /** * Select SRV record using weighted random selection */ private selectWeightedSrvRecord; private roundRobinSelection; private leastConnectionSelection; private getServicesMetrics; private rankServices; private calculateHealthScore; private calculateResourceScore; private calculateDistributionScore; private normalizeScore; private weightedRandomSelection; incrementConnections(serviceId: string): Promise<void>; decrementConnections(serviceId: string): Promise<void>; private updateSelectionMetrics; getSelectionMetrics(serviceId: string): Promise<ServiceMetrics | null>; refresh(): Promise<void>; } export default ConsulResolver;