Skip to content

Commit

Permalink
feat: add Options field
Browse files Browse the repository at this point in the history
for per-route-features forwarding
(RFC 0027)

Co-authored-by: Tamara Boehm <[email protected]>
  • Loading branch information
a18e and b1tamara committed Oct 22, 2024
1 parent 1ed8242 commit 8737053
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
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

0 comments on commit 8737053

Please sign in to comment.