consul-resolver
Version:
A load balancer for Consul services with Redis-based metrics
82 lines (81 loc) • 1.89 kB
TypeScript
/// <reference types="node" />
import type { Redis as IORedis } from "ioredis";
import { Agent } from "https";
export interface SrvRecord {
name: string;
ip: string;
port: number;
priority: number;
weight: number;
}
export interface ConsulDNSRecord {
name: string;
port: number;
priority: number;
weight: number;
ip?: string;
}
export interface ConsulResolverConfig {
redis?: IORedis;
cacheEnabled: boolean;
cachePrefix: string;
host: string;
port: number;
secure: boolean;
debug?: boolean;
token?: string;
agent?: Agent | import("http").Agent;
weights?: typeof DEFAULT_WEIGHTS;
metrics?: typeof DEFAULT_METRICS;
cacheTTL?: number;
dnsEndpoints?: string[];
dnsTimeout?: number;
dnsRetries?: number;
}
export declare const DEFAULT_WEIGHTS: {
health: number;
responseTime: number;
errorRate: number;
resources: number;
connections: number;
distribution: number;
};
export declare const DEFAULT_METRICS: ServiceMetrics;
export interface ServiceMetrics {
responseTime: number;
errorRate: number;
cpuUsage: number;
memoryUsage: number;
activeConnections: number;
lastSelectedTime?: number;
}
export interface ServiceHealth {
Node: {
Node: string;
Address: string;
};
Service: {
ID: string;
Service: string;
Tags: string[];
Address: string;
Port: number;
};
Checks: Array<{
Status: string;
Output: string;
}>;
}
export interface ServiceInfo {
ip: string;
port: number;
}
export interface OptimalServiceResult {
selected: ServiceInfo | null;
services: ServiceInfo[];
}
export declare enum SelectionAlgorithm {
RoundRobin = "round-robin",
LeastConnection = "least-connection",
WeightedRoundRobin = "weighted-round-robin"
}