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

Add AZ to registry message #29

Merged
merged 1 commit into from
Nov 9, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 37 additions & 16 deletions cmd/route-emitter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ var _ = Describe("Route Emitter", func() {
lrpKey := models.NewActualLRPKey("some-guid", 0, domain)
instanceKey := models.NewActualLRPInstanceKey("instance-guid", "cell-id")
netInfo := models.NewActualLRPNetInfo("some-ip", "container-ip", models.ActualLRPNetInfo_PreferredAddressHost, models.NewPortMapping(62003, 5222))
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
})

It("requests a token from the server", func() {
Expand Down Expand Up @@ -707,7 +707,7 @@ var _ = Describe("Route Emitter", func() {
lrpKey = models.NewActualLRPKey(processGUID, 0, domain)
instanceKey = models.NewActualLRPInstanceKey("instance-guid", "cell-id")
netInfo = models.NewActualLRPNetInfo("some-ip", "container-ip", models.ActualLRPNetInfo_PreferredAddressHost, models.NewPortMapping(5222, 5222))
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
Eventually(runner).Should(gbytes.Say("caching-event"))

By("unblocking the sync loop")
Expand Down Expand Up @@ -763,7 +763,7 @@ var _ = Describe("Route Emitter", func() {
})

JustBeforeEach(func() {
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
})

It("emits its routes immediately", func() {
Expand Down Expand Up @@ -952,7 +952,7 @@ var _ = Describe("Route Emitter", func() {
lrpKey = models.NewActualLRPKey(expectedTCPProcessGUID, 0, domain)
instanceKey = models.NewActualLRPInstanceKey("instance-guid", "cell-id")
netInfo = models.NewActualLRPNetInfo("some-ip", "container-ip", models.ActualLRPNetInfo_PreferredAddressHost, models.NewPortMapping(5222, 5222))
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
Eventually(runner).Should(gbytes.Say("caching-event"))

By("unblocking the sync loop")
Expand Down Expand Up @@ -988,7 +988,7 @@ var _ = Describe("Route Emitter", func() {
key := models.NewActualLRPKey("some-guid-1", 0, domain)
instanceKey := models.NewActualLRPInstanceKey("instance-guid-1", "cell-id")
netInfo := models.NewActualLRPNetInfo("some-ip-1", "container-ip-1", models.ActualLRPNetInfo_PreferredAddressHost, models.NewPortMapping(62003, 1883))
Expect(bbsClient.StartActualLRP(logger, "", &key, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &key, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
})

It("starts an SSE connection to the bbs and continues to try to emit to routing api", func() {
Expand Down Expand Up @@ -1242,7 +1242,7 @@ var _ = Describe("Route Emitter", func() {
It("emits routes", func() {
err := bbsClient.DesireLRP(logger, "", desiredLRP)
Expect(err).NotTo(HaveOccurred())
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
var msg1, msg2 routingtable.RegistryMessage
Eventually(registeredRoutes).Should(Receive(&msg1))
Expand All @@ -1262,6 +1262,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1276,6 +1277,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1330,7 +1332,7 @@ var _ = Describe("Route Emitter", func() {

Context("and an instance starts", func() {
JustBeforeEach(func() {
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -1371,7 +1373,7 @@ var _ = Describe("Route Emitter", func() {
sqlRunner.Reset()

// Only start actual LRP, do not repopulate Desired
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -1399,6 +1401,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1413,6 +1416,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1442,6 +1446,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1457,6 +1462,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1488,6 +1494,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1502,6 +1509,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1531,6 +1539,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1546,6 +1555,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1575,6 +1585,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1590,6 +1601,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1630,7 +1642,7 @@ var _ = Describe("Route Emitter", func() {
err := bbsClient.DesireLRP(logger, "", desiredLRP)
Expect(err).NotTo(HaveOccurred())

err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -1662,6 +1674,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{hostnames[0]},
Expand All @@ -1676,6 +1689,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1791,7 +1805,7 @@ var _ = Describe("Route Emitter", func() {
err := bbsClient.DesireLRP(logger, "", desiredLRP)
Expect(err).NotTo(HaveOccurred())

err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})
It("does not emit any internal routes", func() {
Expand Down Expand Up @@ -1839,7 +1853,7 @@ var _ = Describe("Route Emitter", func() {

Context("and an instance starts", func() {
JustBeforeEach(func() {
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -1877,7 +1891,7 @@ var _ = Describe("Route Emitter", func() {
Eventually(runner).Should(gbytes.Say("succeeded-getting-desired-lrps"))

// Only start actual LRP, do not repopulate Desired
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err := bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -1894,6 +1908,7 @@ var _ = Describe("Route Emitter", func() {
Tags: map[string]string{
"component": "route-emitter",
},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{internalHostnames[0], fmt.Sprintf("%d.%s", 0, internalHostnames[0])},
Expand All @@ -1903,6 +1918,7 @@ var _ = Describe("Route Emitter", func() {
Tags: map[string]string{
"component": "route-emitter",
},
AvailabilityZone: "some-zone",
}),
))
})
Expand All @@ -1920,13 +1936,15 @@ var _ = Describe("Route Emitter", func() {
PrivateInstanceIndex: "0",
App: desiredLRP.LogGuid,
Tags: map[string]string{"component": "route-emitter"},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{internalHostnames[0], fmt.Sprintf("%d.%s", 0, internalHostnames[0])},
Host: netInfo.InstanceAddress,
PrivateInstanceIndex: "0",
App: desiredLRP.LogGuid,
Tags: map[string]string{"component": "route-emitter"},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -1964,7 +1982,7 @@ var _ = Describe("Route Emitter", func() {
err := bbsClient.DesireLRP(logger, "", desiredLRP)
Expect(err).NotTo(HaveOccurred())

err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -1989,13 +2007,15 @@ var _ = Describe("Route Emitter", func() {
PrivateInstanceIndex: "0",
App: desiredLRP.LogGuid,
Tags: map[string]string{"component": "route-emitter"},
AvailabilityZone: "some-zone",
}),
MatchRegistryMessage(routingtable.RegistryMessage{
URIs: []string{internalHostnames[0], fmt.Sprintf("0.%s", internalHostnames[0])},
Host: netInfo.InstanceAddress,
PrivateInstanceIndex: "0",
App: desiredLRP.LogGuid,
Tags: map[string]string{"component": "route-emitter"},
AvailabilityZone: "some-zone",
}),
))
})
Expand Down Expand Up @@ -2067,7 +2087,7 @@ var _ = Describe("Route Emitter", func() {
err := bbsClient.DesireLRP(logger, "", desiredLRP)
Expect(err).NotTo(HaveOccurred())

err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)
err = bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -2293,7 +2313,7 @@ var _ = Describe("Route Emitter", func() {
lrpKey := models.NewActualLRPKey("some-other-guid", 0, domain)
instanceKey := models.NewActualLRPInstanceKey("instance-guid", "cell-id")
netInfo := models.NewActualLRPNetInfo("1.2.3.4", "container-ip", models.ActualLRPNetInfo_PreferredAddressHost, models.NewPortMapping(65100, 8080))
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())

// keep reading unregistration messages until route-1 is re-registered
done := make(chan struct{})
Expand Down Expand Up @@ -2323,6 +2343,7 @@ var _ = Describe("Route Emitter", func() {
"component": "route-emitter",
"some-tag": "some-value",
},
AvailabilityZone: "some-zone",
})))
done <- struct{}{}

Expand Down Expand Up @@ -2367,7 +2388,7 @@ var _ = Describe("Route Emitter", func() {
runner.StartCheck = "succeeded-getting-actual-lrps"
emitter = ginkgomon.Invoke(runner)

Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true)).To(Succeed())
Expect(bbsClient.StartActualLRP(logger, "", &lrpKey, &instanceKey, &netInfo, []*models.ActualLRPInternalRoute{}, map[string]string{}, true, "some-zone")).To(Succeed())
Eventually(runner).Should(gbytes.Say("caching-event"))

By("unblocking the sync loop")
Expand Down
4 changes: 4 additions & 0 deletions routingtable/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Endpoint struct {
Since int64
ModificationTag *models.ModificationTag
PreferredAddress models.ActualLRPNetInfo_PreferredAddress
AvailabilityZone string
}

func (e Endpoint) key() EndpointKey {
Expand All @@ -70,6 +71,7 @@ func NewEndpoint(
port, containerPort uint32,
preferredAddress models.ActualLRPNetInfo_PreferredAddress,
modificationTag *models.ModificationTag,
availabiltiyZone string,
) Endpoint {
return Endpoint{
InstanceGUID: instanceGUID,
Expand All @@ -80,6 +82,7 @@ func NewEndpoint(
ContainerPort: containerPort,
PreferredAddress: preferredAddress,
ModificationTag: modificationTag,
AvailabilityZone: availabiltiyZone,
}
}

Expand Down Expand Up @@ -226,6 +229,7 @@ func NewEndpointsFromActual(actualLRP *models.ActualLRP) []Endpoint {
ContainerTlsProxyPort: portMapping.ContainerTlsProxyPort,
Since: actualLRP.Since,
PreferredAddress: actualLRP.PreferredAddress,
AvailabilityZone: actualLRP.AvailabilityZone,
}
endpoints = append(endpoints, endpoint)
}
Expand Down