Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(config): reject invalid receiver ports before installation (#982)

Divyam Talwar2379255cd187
diff --git a/cli/beacon/internal/endpoint/config/config.go b/cli/beacon/internal/endpoint/config/config.go
index 9da35171..ef220afb 100644
--- a/cli/beacon/internal/endpoint/config/config.go
+++ b/cli/beacon/internal/endpoint/config/config.go
@@ -252,13 +252,21 @@ func DeriveHealthCheckPort(grpcPort, httpPort int) int {
return DefaultHealthCheckPort
}
-// ValidateCollectorPorts rejects a health-check port the collector could not bind: outside the TCP
-// range, or shared with an OTLP receiver, which would make the collector fail at start with a bind
-// error rather than at install with an explanation.
+// ValidateCollectorPorts rejects out-of-range or shared collector endpoints before install writes
+// a configuration the collector cannot bind. A zero health port keeps the legacy default.
func ValidateCollectorPorts(collector Collector) error {
+ if !validPort(collector.GRPCPort) {
+ return fmt.Errorf("collector OTLP gRPC port %d is out of range; choose a port between 1 and 65535 with --otlp-grpc-port", collector.GRPCPort)
+ }
+ if !validPort(collector.HTTPPort) {
+ return fmt.Errorf("collector OTLP HTTP port %d is out of range; choose a port between 1 and 65535 with --otlp-http-port", collector.HTTPPort)
+ }
+ if collector.GRPCPort == collector.HTTPPort {
+ return fmt.Errorf("collector OTLP gRPC and HTTP ports are both %d; choose different --otlp-grpc-port and --otlp-http-port values", collector.GRPCPort)
+ }
health := HealthCheckPort(collector)
- if !validPort(health) {
- return fmt.Errorf("collector health-check port %d is out of range; choose a port between 1 and 65535 with --health-port", health)
+ if collector.HealthPort < 0 || !validPort(health) {
+ return fmt.Errorf("collector health-check port %d is out of range; choose a port between 1 and 65535 with --health-port", collector.HealthPort)
}
if health == collector.GRPCPort || health == collector.HTTPPort {
return fmt.Errorf("collector health-check port %d is also an OTLP receiver port; choose a different --health-port", health)
diff --git a/cli/beacon/internal/endpoint/config/healthport_test.go b/cli/beacon/internal/endpoint/config/healthport_test.go
index dd64096e..0158bce0 100644
--- a/cli/beacon/internal/endpoint/config/healthport_test.go
+++ b/cli/beacon/internal/endpoint/config/healthport_test.go
@@ -107,14 +107,21 @@ func TestValidateCollectorPortsRejectsAHealthPortTheCollectorCannotBind(t *testi
if err := ValidateCollectorPorts(Collector{GRPCPort: 4317, HTTPPort: 4318}); err != nil {
t.Fatalf("legacy config (no health port) rejected: %v", err)
}
- for name, c := range map[string]Collector{
- "same as gRPC": {GRPCPort: 4327, HTTPPort: 4328, HealthPort: 4327},
- "same as HTTP": {GRPCPort: 4327, HTTPPort: 4328, HealthPort: 4328},
- "out of range": {GRPCPort: 4327, HTTPPort: 4328, HealthPort: 70000},
+ for name, tc := range map[string]struct {
+ c Collector
+ flag string
+ }{
+ "health same as gRPC": {Collector{GRPCPort: 4327, HTTPPort: 4328, HealthPort: 4327}, "--health-port"},
+ "health same as HTTP": {Collector{GRPCPort: 4327, HTTPPort: 4328, HealthPort: 4328}, "--health-port"},
+ "health out of range": {Collector{GRPCPort: 4327, HTTPPort: 4328, HealthPort: 70000}, "--health-port"},
+ "negative health": {Collector{GRPCPort: 4327, HTTPPort: 4328, HealthPort: -1}, "--health-port"},
+ "negative gRPC": {Collector{GRPCPort: -1, HTTPPort: 4318}, "--otlp-grpc-port"},
+ "oversized HTTP": {Collector{GRPCPort: 4317, HTTPPort: 65536}, "--otlp-http-port"},
+ "same receiver ports": {Collector{GRPCPort: 4317, HTTPPort: 4317}, "--otlp-http-port"},
} {
- err := ValidateCollectorPorts(c)
- if err == nil || !strings.Contains(err.Error(), "--health-port") {
- t.Errorf("%s: ValidateCollectorPorts error = %v, want one naming --health-port", name, err)
+ err := ValidateCollectorPorts(tc.c)
+ if err == nil || !strings.Contains(err.Error(), tc.flag) {
+ t.Errorf("%s: ValidateCollectorPorts error = %v, want one naming %s", name, err, tc.flag)
}
}
}