@@ -20,15 +20,12 @@ import (
2020 "fmt"
2121 "io"
2222 "net/http"
23- "strings"
2423 "testing"
2524 "time"
2625
2726 "github.com/agent-substrate/substrate/internal/e2e"
2827 "github.com/agent-substrate/substrate/internal/resources"
2928 "github.com/agent-substrate/substrate/pkg/proto/ateapipb"
30- corev1 "k8s.io/api/core/v1"
31- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3229)
3330
3431const networkingAtespace = "networking-e2e"
@@ -82,18 +79,12 @@ func TestActorEgressHTTPS(t *testing.T) {
8279 router := mustRouterClient (t , ctx )
8380 defer router .Close ()
8481
85- // Bound the access-log scan below to lines this test could have produced.
86- // The slack absorbs clock skew between here and the gateway's node.
87- since := metav1 .NewTime (time .Now ().Add (- 1 * time .Minute ))
88-
8982 actorRef := resources.ActorRef {Atespace : networkingAtespace , Name : actorName }
9083 status , body := fetchThroughEgressActor (t , ctx , router , actorRef , "https://example.com/" )
9184 if status != http .StatusOK {
9285 t .Fatalf ("Actor HTTPS egress fetch returned HTTP %d, want 200; body: %s" , status , body )
9386 }
9487 t .Logf ("Actor HTTPS egress fetch succeeded; body: %s" , body )
95-
96- assertEgressGatewayConnect (t , ctx , since , actorName , "443" )
9788}
9889
9990// fetchThroughEgressActor asks the egress demo Actor to fetch url and returns
@@ -127,95 +118,6 @@ func fetchThroughEgressActor(t *testing.T, ctx context.Context, router *e2e.Rout
127118 }
128119}
129120
130- // assertEgressGatewayConnect waits for the atenet-egress access log to show a
131- // CONNECT to port opened by actorName.
132- func assertEgressGatewayConnect (t * testing.T , ctx context.Context , since metav1.Time , actorName , port string ) {
133- t .Helper ()
134- want := fmt .Sprintf ("a CONNECT to port %s by actor %s" , port , actorName )
135- waitForAccessLog (t , ctx , since , want , func (lines []string ) (bool , error ) {
136- for _ , line := range lines {
137- authority , ok := accessLogField (line , "authority" )
138- if ! ok || ! strings .HasSuffix (authority , ":" + port ) {
139- continue
140- }
141- if ! strings .Contains (line , "/actor/" + actorName ) {
142- continue
143- }
144- t .Logf ("egress gateway tunneled the request: %s" , line )
145- return true , nil
146- }
147- return false , nil
148- })
149- }
150-
151- // waitForAccessLog polls the atenet-egress access log, across every gateway
152- // replica, until predicate accepts the lines written since.
153- func waitForAccessLog (t * testing.T , ctx context.Context , since metav1.Time , want string , predicate func (lines []string ) (bool , error )) {
154- t .Helper ()
155- const (
156- gatewayNamespace = "ate-system"
157- gatewaySelector = "app=atenet-egress"
158- gatewayContainer = "envoy"
159- // The access log's line prefix, from the HttpConnectionManager
160- // text_format_source in manifests/ate-install/atenet-egress.yaml.
161- accessLogPrefix = "[egress] "
162- )
163-
164- clients := e2e .GetClients ()
165- pods , err := clients .K8s .CoreV1 ().Pods (gatewayNamespace ).List (ctx , metav1.ListOptions {LabelSelector : gatewaySelector })
166- if err != nil {
167- t .Fatalf ("listing %s pods in %s: %v" , gatewaySelector , gatewayNamespace , err )
168- }
169- if len (pods .Items ) == 0 {
170- t .Fatalf ("no %s pods in %s; the egress gateway is not deployed" , gatewaySelector , gatewayNamespace )
171- }
172-
173- // Poll for the access log line (it may show up asynchronously from the actual traffic).
174- const timeout = 30 * time .Second
175- deadline := time .Now ().Add (timeout )
176- for {
177- var lines []string
178- for _ , pod := range pods .Items {
179- logs , err := clients .K8s .CoreV1 ().Pods (gatewayNamespace ).GetLogs (pod .Name , & corev1.PodLogOptions {
180- Container : gatewayContainer ,
181- SinceTime : & since ,
182- }).DoRaw (ctx )
183- if err != nil {
184- t .Fatalf ("reading logs of %s/%s: %v" , gatewayNamespace , pod .Name , err )
185- }
186- for line := range strings .SplitSeq (string (logs ), "\n " ) {
187- if strings .Contains (line , accessLogPrefix ) {
188- lines = append (lines , line )
189- }
190- }
191- }
192-
193- matched , err := predicate (lines )
194- if err != nil {
195- t .Fatalf ("looking for %s in the atenet-egress access log: %v" , want , err )
196- }
197- if matched {
198- return
199- }
200- if time .Now ().After (deadline ) {
201- t .Fatalf ("no atenet-egress access-log line for %s after %v; lines seen:\n %s" ,
202- want , timeout , strings .Join (lines , "\n " ))
203- }
204- time .Sleep (1 * time .Second )
205- }
206- }
207-
208- // accessLogField returns the value of the key=value field named key in an Envoy
209- // access log line whose fields are separated by spaces.
210- func accessLogField (line , key string ) (string , bool ) {
211- _ , rest , ok := strings .Cut (line , key + "=" )
212- if ! ok {
213- return "" , false
214- }
215- value , _ , _ := strings .Cut (rest , " " )
216- return value , true
217- }
218-
219121func createAndResumeActor (t * testing.T , ctx context.Context , prefix string , template e2e.Fixture ) (string , * ateapipb.Actor ) {
220122 t .Helper ()
221123 clients := e2e .GetClients ()
0 commit comments