Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement per-route options forwarding in route-emitter #47

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions routehandlers/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ var _ = Describe("Handler", func() {
Hostnames: []string{hostname1},
Port: 8080,
RouteServiceUrl: "https://rs.example.com",
Options: json.RawMessage(`{"lb_algo":"least-connection"}`),
},
}.RoutingInfo()

Expand Down
2 changes: 2 additions & 0 deletions routingtable/endpoint.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routingtable

import (
"encoding/json"
"fmt"

"code.cloudfoundry.org/bbs/models"
Expand Down Expand Up @@ -141,6 +142,7 @@ type Route struct {
LogGUID string
Protocol string
MetricTags map[string]*models.MetricTagValue
Options json.RawMessage
}

type routeHash struct {
Expand Down
3 changes: 3 additions & 0 deletions routingtable/registry_message.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routingtable

import (
"encoding/json"
"fmt"
"strconv"

Expand All @@ -22,6 +23,7 @@ type RegistryMessage struct {
EndpointUpdatedAtNs int64 `json:"endpoint_updated_at_ns,omitempty" hash:"ignore"`
Tags map[string]string `json:"tags,omitempty" hash:"ignore"`
AvailabilityZone string `json:"availability_zone,omitempty" hash:"ignore"`
Options json.RawMessage `json:"options,omitempty" hash:"ignore"`
}

func RegistryMessageFor(endpoint Endpoint, route Route, emitEndpointUpdatedAt bool) RegistryMessage {
Expand Down Expand Up @@ -50,6 +52,7 @@ func RegistryMessageFor(endpoint Endpoint, route Route, emitEndpointUpdatedAt bo
PrivateInstanceIndex: index,
ServerCertDomainSAN: endpoint.InstanceGUID,
RouteServiceUrl: route.RouteServiceUrl,
Options: route.Options,
}
}

Expand Down
40 changes: 40 additions & 0 deletions routingtable/registry_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,34 @@ var _ = Describe("RegistryMessage", func() {
Expect(message).To(Equal(expectedMessage))
})
})

Context("when a route option is provided", func() {
BeforeEach(func() {
expectedMessage.Options = json.RawMessage(`{"lb_algo":"least-connection"}`)
expectedJSON = `{
"host": "1.1.1.1",
"port": 61001,
"uris": ["host-1.example.com"],
"app" : "app-guid",
"private_instance_id": "instance-guid",
"server_cert_domain_san": "instance-guid",
"private_instance_index": "0",
"route_service_url": "https://hello.com",
"endpoint_updated_at_ns": 1000,
"tags": {"component":"route-emitter", "doo": "0", "foo": "bar", "goo": "instance-guid"},
"availability_zone": "some-zone",
"options": {"lb_algo":"least-connection"}
}`
})

It("correctly marshals the route option", func() {
message := routingtable.RegistryMessage{}

err := json.Unmarshal([]byte(expectedJSON), &message)
Expect(err).NotTo(HaveOccurred())
Expect(message).To(Equal(expectedMessage))
})
})
})

Describe("RegistryMessageFor", func() {
Expand Down Expand Up @@ -182,6 +210,18 @@ var _ = Describe("RegistryMessage", func() {
Expect(message).To(Equal(expectedMessage))
})
})

Context("when route options are provided", func() {
BeforeEach(func() {
route.Options = json.RawMessage(`{"lb_algo":"least-connection"}`)
expectedMessage.Options = json.RawMessage(`{"lb_algo":"least-connection"}`)
})

It("creates a valid message when route options are provided", func() {
message := routingtable.RegistryMessageFor(endpoint, route, true)
Expect(message).To(Equal(expectedMessage))
})
})
})

Describe("InternalAddressRegistryMessageFor", func() {
Expand Down
1 change: 1 addition & 0 deletions routingtable/routingtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func httpRoutesFrom(lrp *models.DesiredLRP) map[RoutingKey][]routeMapping {
IsolationSegment: route.IsolationSegment,
MetricTags: lrp.MetricTags,
Protocol: route.Protocol,
Options: route.Options,
}
routes = append(routes, route)
}
Expand Down