Skip to content

Commit b4f3ba9

Browse files
AryanP123pwright
andauthored
add spec.observer (auto|none) and wire to router (#2348)
* add spec.observer (auto|none) and wire to router Fixes #2342 * Added unit tests * Added http1 and http2 values to spec.observer; updated unit tests * Update config/crd/bases/skupper_listener_crd.yaml Co-authored-by: Paul Wright <5154224+pwright@users.noreply.github.com> --------- Co-authored-by: Paul Wright <5154224+pwright@users.noreply.github.com>
1 parent c3ae5cf commit b4f3ba9

File tree

6 files changed

+117
-1
lines changed

6 files changed

+117
-1
lines changed

config/crd/bases/skupper_listener_crd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ spec:
2222
spec:
2323
type: object
2424
properties:
25+
observer:
26+
description: |-
27+
The listener observer controls how the listener inspects network traffic for application-level protocol information.
28+
When unset or set to `auto`, the listener inspects traffic to detect known application protocols and produces telemetry events for that application traffic.
29+
Set to a specific protocol (`http1` or `http2`) to restrict inspection to that protocol only.
30+
Set to `none` to disable protocol inspection and reduce overhead from traffic inspection and application-level telemetry.
31+
type: string
32+
enum:
33+
- auto
34+
- none
35+
- http1
36+
- http2
2537
routingKey:
2638
description: |-
2739
The identifier to route traffic from listeners to connectors. To

internal/qdr/amqp_mgmt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func asTcpEndpoint(record Record) TcpEndpoint {
130130
Address: record.AsString("address"),
131131
SiteId: record.AsString("siteId"),
132132
SslProfile: record.AsString("sslProfile"),
133+
Observer: record.AsString("observer"),
133134
ProcessID: record.AsString("processId"),
134135
}
135136
if value, ok := record["verifyHostname"]; ok {

internal/qdr/qdr.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ type TcpEndpoint struct {
559559
Address string `json:"address,omitempty"`
560560
SiteId string `json:"siteId,omitempty"`
561561
SslProfile string `json:"sslProfile,omitempty"`
562+
Observer string `json:"observer,omitempty"`
562563
VerifyHostname *bool `json:"verifyHostname,omitempty"`
563564
ProcessID string `json:"processId,omitempty"`
564565
}
@@ -583,6 +584,9 @@ func (e TcpEndpoint) toRecord() Record {
583584
if e.SslProfile != "" {
584585
result["sslProfile"] = e.SslProfile
585586
}
587+
if e.Observer != "" {
588+
result["observer"] = e.Observer
589+
}
586590
if e.VerifyHostname != nil {
587591
result["verifyHostname"] = e.VerifyHostname
588592
}
@@ -948,8 +952,17 @@ func (a TcpEndpoint) equivalentVerifyHostname(b TcpEndpoint) bool {
948952
}
949953

950954
func (a TcpEndpoint) Equivalent(b TcpEndpoint) bool {
955+
obsA := a.Observer
956+
if obsA == "" {
957+
obsA = "auto"
958+
}
959+
obsB := b.Observer
960+
if obsB == "" {
961+
obsB = "auto"
962+
}
951963
if !equivalentHost(a.Host, b.Host) || a.Port != b.Port || a.Address != b.Address ||
952-
a.SiteId != b.SiteId || a.ProcessID != b.ProcessID || !a.equivalentVerifyHostname(b) {
964+
a.SiteId != b.SiteId || a.ProcessID != b.ProcessID || !a.equivalentVerifyHostname(b) ||
965+
obsA != obsB {
953966
return false
954967
}
955968
return true

internal/qdr/qdr_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,91 @@ func TestRecordTypes_GH2081(t *testing.T) {
668668
})
669669
}
670670
}
671+
672+
func TestTcpEndpointObserverToRecord(t *testing.T) {
673+
// empty observer -> omitted
674+
e := TcpEndpoint{
675+
Name: "t1",
676+
Address: "a",
677+
Host: "h",
678+
Port: "1234",
679+
SiteId: "s",
680+
Observer: "",
681+
}
682+
r := e.toRecord()
683+
_, ok := r["observer"]
684+
assert.Assert(t, !ok, "observer should be omitted when empty")
685+
686+
// non-empty observer -> included
687+
for _, val := range []string{"auto", "none", "http1", "http2"} {
688+
e.Observer = val
689+
r = e.toRecord()
690+
got, ok := r["observer"]
691+
assert.Assert(t, ok, "observer should be present when set")
692+
assert.Equal(t, got, val)
693+
}
694+
}
695+
696+
func TestTcpEndpointEquivalentObserverAutoVsEmpty(t *testing.T) {
697+
a := TcpEndpoint{
698+
Name: "t1",
699+
Address: "a",
700+
Host: "",
701+
Port: "1234",
702+
SiteId: "s",
703+
Observer: "auto",
704+
}
705+
b := TcpEndpoint{
706+
Name: "t1",
707+
Address: "a",
708+
Host: "",
709+
Port: "1234",
710+
SiteId: "s",
711+
Observer: "",
712+
}
713+
if !a.Equivalent(b) {
714+
t.Errorf("expected endpoints to be equivalent when comparing observer 'auto' vs empty")
715+
}
716+
}
717+
718+
func TestTcpEndpointEquivalentHttpModes(t *testing.T) {
719+
base := TcpEndpoint{
720+
Name: "t1",
721+
Address: "a",
722+
Host: "",
723+
Port: "1234",
724+
SiteId: "s",
725+
}
726+
// Equal http1/http1
727+
a := base
728+
b := base
729+
a.Observer = "http1"
730+
b.Observer = "http1"
731+
if !a.Equivalent(b) {
732+
t.Errorf("expected http1 vs http1 to be equivalent")
733+
}
734+
// Equal http2/http2
735+
a.Observer = "http2"
736+
b.Observer = "http2"
737+
if !a.Equivalent(b) {
738+
t.Errorf("expected http2 vs http2 to be equivalent")
739+
}
740+
// Different http1 vs auto
741+
a.Observer = "http1"
742+
b.Observer = "auto"
743+
if a.Equivalent(b) {
744+
t.Errorf("expected http1 vs auto to be not equivalent")
745+
}
746+
// Different http2 vs empty (router default)
747+
a.Observer = "http2"
748+
b.Observer = ""
749+
if a.Equivalent(b) {
750+
t.Errorf("expected http2 vs empty to be not equivalent")
751+
}
752+
// Different http1 vs none
753+
a.Observer = "http1"
754+
b.Observer = "none"
755+
if a.Equivalent(b) {
756+
t.Errorf("expected http1 vs none to be not equivalent")
757+
}
758+
}

internal/site/listener.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func UpdateBridgeConfigForListenerWithHostAndPort(siteId string, listener *skupp
2121
Port: strconv.Itoa(port),
2222
Address: listener.Spec.RoutingKey,
2323
SslProfile: listener.Spec.TlsCredentials,
24+
Observer: listener.Spec.Observer,
2425
})
2526
}
2627
}

pkg/apis/skupper/v2alpha1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ type ListenerSpec struct {
407407
Port int `json:"port"`
408408
TlsCredentials string `json:"tlsCredentials,omitempty"`
409409
Type string `json:"type,omitempty"`
410+
Observer string `json:"observer,omitempty"`
410411
ExposePodsByName bool `json:"exposePodsByName,omitempty"`
411412
Settings map[string]string `json:"settings,omitempty"`
412413
}

0 commit comments

Comments
 (0)