Skip to content

Agent Mesh

router: resolve dnsaddr router addresses through the test DNS server

Antonio Ojea65af27b36c28
diff --git a/cmd/agentmesh-router/main.go b/cmd/agentmesh-router/main.go
index 5b423999..ff801fb7 100644
--- a/cmd/agentmesh-router/main.go
+++ b/cmd/agentmesh-router/main.go
@@ -17,6 +17,7 @@ package main
import (
"context"
"fmt"
+ "net"
"os"
"os/signal"
"syscall"
@@ -28,9 +29,27 @@ import (
"github.com/google/agentmesh/internal/router"
"github.com/google/agentmesh/internal/version"
golog "github.com/ipfs/go-log/v2"
+ madns "github.com/multiformats/go-multiaddr-dns"
"github.com/spf13/cobra"
)
+// The integration tests run a DNS server of their own for the dnsaddr
+// addresses routers announce; the router resolves peer routers through it
+// when told to, as agentmesh-node does.
+func init() {
+ if dnsServer := os.Getenv("AGENTMESH_TEST_DNS_SERVER"); dnsServer != "" {
+ customResolver := &net.Resolver{
+ PreferGo: true,
+ Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
+ d := net.Dialer{Timeout: 5 * time.Second}
+ return d.DialContext(ctx, "udp", dnsServer)
+ },
+ }
+ net.DefaultResolver = customResolver
+ madns.DefaultResolver, _ = madns.NewResolver(madns.WithDefaultResolver(customResolver))
+ }
+}
+
var (
controlPlaneURL string
insecureControlPlane bool
diff --git a/tests/integration/federation_test.go b/tests/integration/federation_test.go
index aad111cb..e023a385 100644
--- a/tests/integration/federation_test.go
+++ b/tests/integration/federation_test.go
@@ -265,17 +265,20 @@ roles:
// Search for the service from Node B
t.Log("Searching for tool from Node B...")
- searchCmd := exec.Command(clientBin,
- "-url", fmt.Sprintf("http://127.0.0.1:%d/mcp", apiPortB),
- "-token", "tokenB",
- "-tool", "discover_remote_services",
- "-args", `{"type": "mcp"}`,
- )
+ search := func() ([]byte, error) {
+ return exec.Command(clientBin,
+ "-url", fmt.Sprintf("http://127.0.0.1:%d/mcp", apiPortB),
+ "-token", "tokenB",
+ "-tool", "discover_remote_services",
+ "-args", `{"type": "mcp"}`,
+ ).Output()
+ }
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
var found bool
+ attempts := 0
for {
select {
case <-ctx.Done():
@@ -283,9 +286,12 @@ roles:
t.Logf("Node A Stderr: %s", nodeStderrA.String())
t.Logf("Node B Stdout: %s", nodeStdoutB.String())
t.Logf("Node B Stderr: %s", nodeStderrB.String())
+ t.Logf("Router A Stderr: %s", stderrRouterA.String())
+ t.Logf("Router B Stderr: %s", stderrRouterB.String())
t.Fatalf("timed out waiting to discover tool from Node B.")
default:
- out, err := searchCmd.Output()
+ attempts++
+ out, err := search()
if err == nil {
if strings.Contains(string(out), "federated-tool") {
found = true
@@ -299,7 +305,7 @@ roles:
}
}
- t.Log("Successfully discovered federated tool via relay!")
+ t.Logf("Successfully discovered federated tool via relay after %d attempt(s)!", attempts)
// Assert datapath works via Node B's local Egress Proxy
t.Log("Testing datapath from Node B to Node A...")