Skip to content

Commit 659832f

Browse files
authored
demos/counter: remove sandbox IP greeting from counter response (agent-substrate#3510)
<!-- The PR title becomes the release note. Write it for users. --> Follow-up to agent-substrate#3498 (comment). Remove `hello from: %s` and `getCurrentIP()` from `demos/counter/counter.go`. Why? `counter.go` included `hello from: <ip>` in its response from early dyas of Substrate to show that an actor resumed on a different worker Pod IP. However, now every actor sandbox uses the fixed veth address `169.254.17.2` (`ActorVethIP` in `internal/ateworker/actornet/net.go`), so `getCurrentIP()` always returns `169.254.17.2` regardless of which worker Pod hosts the actor. Also updated documentations to remove mentioning of "the different worker Pod IP replied by counter indicates it was resumed on another pod". <!-- e.g. "AI-assisted, I reviewed and tested it." No AI co-author trailers. --> AI use: AI-assisted to update the counter demo, docs, and tests; I reviewed the diff. <!-- Breaking change? Describe what users must do on upgrade and ask for the `breaking-change` label. --> - [x] Tests pass - [x] Docs updated --------- Signed-off-by: Zoe Zhao <[email protected]>
1 parent 0e67fd6 commit 659832f

7 files changed

Lines changed: 19 additions & 69 deletions

File tree

‎demos/counter/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,12 @@ kubectl ate suspend actor my-counter-1 -a ate-demo-counter
188188
The snapshot stays on the worker's node and is uploaded to snapshot storage in
189189
the background. Add `--mode=sync` to wait for the upload instead.
190190

191-
Repeat the `curl` from step 1 and the actor resumes from its snapshot —
192-
possibly on a different worker — with **both** counters continuing from where
191+
Repeat the `curl` from step 1 and the actor resumes from its snapshot,
192+
possibly on a different worker, with **both** counters continuing from where
193193
they left off: the memory count comes back from the `MEMORY` snapshot's process
194-
memory, the file counter from the durable volume.
194+
memory, the file counter from the durable volume. Run `kubectl ate get actor`
195+
from step 2 again and check the `WORKER POD` column to see which worker pod it
196+
resumed on.
195197

196198
4. To permanently delete the suspended actor:
197199
<details>

‎demos/counter/counter.go‎

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Command counter is a simple server that will be used as a worker pod. It listens on ports 80
16-
// and returns a greeting with the IP of the pod where it is running.
15+
// Command counter is a simple HTTP server that increments counters in memory,
16+
// on a durable volume, and on the root filesystem. It listens on port 80 by
17+
// default, with optional listeners on --extra-port (HTTP) and --tcp-port (TCP
18+
// echo).
1719
package main
1820

1921
import (
@@ -92,7 +94,6 @@ func main() {
9294
fileCounter := incrementFileCounter(filepath.Join(*fileCounterDirectory, "a.txt"))
9395
rootfsCounter := incrementFileCounter(*rootfsCounterFile)
9496
memoryCounter := requestCount.Add(1)
95-
currentIP := getCurrentIP()
9697

9798
fileContentStr := ""
9899
if *validateExistingFilePath != "" {
@@ -114,7 +115,7 @@ func main() {
114115
secondFileCounterStr = fmt.Sprintf(" | preserved second file counter: %d", secondFileCounter)
115116
}
116117

117-
response := fmt.Sprintf("hello from: %s | preserved memory count: %d | preserved file counter: %d | preserved rootfs counter: %d%s%s\n", currentIP, memoryCounter, fileCounter, rootfsCounter, secondFileCounterStr, fileContentStr)
118+
response := fmt.Sprintf("preserved memory count: %d | preserved file counter: %d | preserved rootfs counter: %d%s%s\n", memoryCounter, fileCounter, rootfsCounter, secondFileCounterStr, fileContentStr)
118119
slog.InfoContext(ctx, "Handled request", slog.String("response", response))
119120

120121
w.WriteHeader(http.StatusOK)
@@ -165,7 +166,7 @@ func main() {
165166
if *extraPort > 0 {
166167
extraMux := http.NewServeMux()
167168
extraMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
168-
response := fmt.Sprintf("hello from extra port %d on pod %s\n", *extraPort, getCurrentIP())
169+
response := fmt.Sprintf("hello from extra port %d\n", *extraPort)
169170
slog.InfoContext(r.Context(), "Handled extra-port request", slog.String("response", response))
170171
w.WriteHeader(http.StatusOK)
171172
w.Write([]byte(response))
@@ -248,19 +249,3 @@ func hashRandomFile() string {
248249
hash := sha256.Sum256(rfBytes)
249250
return base64.RawStdEncoding.EncodeToString(hash[:])
250251
}
251-
252-
func getCurrentIP() string {
253-
addrs, err := net.InterfaceAddrs()
254-
if err != nil {
255-
slog.Error("Error getting interface addresses", slog.Any("err", err))
256-
return "x.x.x.x"
257-
}
258-
for _, addr := range addrs {
259-
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
260-
if ipnet.IP.To4() != nil {
261-
return ipnet.IP.String()
262-
}
263-
}
264-
}
265-
return "y.y.y.y"
266-
}

‎demos/multi-template/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When you send an HTTP request through the proxy, `atenet-router` automatically a
7272
```bash
7373
# counter binary
7474
curl -s http://localhost:8000
75-
# -> hello from: <ip> | preserved memory count: 1
75+
# -> preserved memory count: 1
7676

7777
# fspersist binary
7878
curl -s http://localhost:8001

‎demos/parking/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ request and retries the resume until a worker frees up — instead of failing fa
1616
with a `503`.
1717

1818
The setup is deliberately **oversubscribed**: a 2-worker pool with several
19-
actors. The workload is the same `counter` binary used by the counter demo; its
20-
reply includes the worker pod IP, so you can see which worker served a request.
19+
actors running the `counter` binary from the counter demo. Run
20+
`kubectl ate get actors -a ate-demo-parking` to see which worker pod each actor
21+
is assigned to.
2122

2223
See [docs/concepts/request-parking.md](../../docs/concepts/request-parking.md) for the design.
2324

‎demos/parking/parking.yaml.tmpl‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
# room it returns ResourceExhausted ("no worker has room for the actor"); with
1919
# parking enabled (the default) the router holds such requests and retries the
2020
# resume until a worker frees up (e.g. another actor suspends), instead of
21-
# failing fast with 503. The workload is the same counter binary used by the
22-
# counter demo -- its reply includes the worker pod IP, so you can see which
23-
# worker served a (possibly parked) request.
21+
# failing fast with 503. The workload is the counter binary from the counter
22+
# demo.
2423
#
2524
# The ActorTemplate is not a CRD: it lives in parking-template.yaml.tmpl and
2625
# is created through the ate API with `kubectl ate create actor-template`.

‎hack/verify-atenet-drain.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ run_kubectl_ate suspend actor "${ACTOR_BUSY}" -a "${ATESPACE}" >/dev/null
178178

179179
wait "${CURL_PID}" || true
180180
grep -q "HTTP=200" "${CURL_OUT}" || fail "parked request did not return 200 through the Terminating pod: $(cat "${CURL_OUT}")"
181-
grep -q "hello from" "${CURL_OUT}" || fail "parked request body missing the counter greeting: $(cat "${CURL_OUT}")"
181+
grep -q "preserved memory count:" "${CURL_OUT}" || fail "parked request body missing the counter response: $(cat "${CURL_OUT}")"
182182
echo "parked request served by the Terminating pod:"
183183
sed 's/^/ /' "${CURL_OUT}"
184184

‎internal/e2e/suites/networking/arbitraryport_test.go‎

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"net"
2424
"net/http"
2525
"net/url"
26-
"regexp"
2726
"strconv"
2827
"strings"
2928
"testing"
@@ -75,27 +74,6 @@ func TestActorArbitraryPortAccess(t *testing.T) {
7574
if !strings.Contains(body, "extra port 9090") {
7675
t.Fatalf("tunneled response body = %q, want it to mention extra port 9090", body)
7776
}
78-
79-
// Cross-check against the default port's own response, both self-reported
80-
// by the same counter binary via getCurrentIP() -- either sandbox has its
81-
// own network stack (the gVisor sentry's, or the micro-VM guest's), so
82-
// this address is not the pod's Kubernetes IP, but it is consistent
83-
// between the two ports on one actor. Asserting they match proves the
84-
// tunnel reached the same actor's extra port rather than some other,
85-
// unrelated open port.
86-
defaultResp, err := router.Get(ctx, actorRef, "/")
87-
if err != nil {
88-
t.Fatalf("GET the actor's default port through ingress: %v", err)
89-
}
90-
defaultBody, err := io.ReadAll(defaultResp.Body)
91-
defaultResp.Body.Close()
92-
if err != nil {
93-
t.Fatalf("reading default-port response body: %v", err)
94-
}
95-
wantIP := selfReportedIP(t, string(defaultBody))
96-
if !strings.Contains(body, wantIP) {
97-
t.Fatalf("tunneled response body = %q, want it to mention the same self-reported IP as the default port (%s): %q", body, wantIP, defaultBody)
98-
}
9977
t.Logf("arbitrary-port access through CONNECT succeeded; body: %s", body)
10078
})
10179

@@ -112,7 +90,7 @@ func TestActorArbitraryPortAccess(t *testing.T) {
11290

11391
held := connectH2(t, ctx, cc, actorRef, 80)
11492
defer held.Close()
115-
if body := getThroughTunnel(t, held, actorRef.Name); !counterDefaultPortIPPattern.MatchString(body) {
93+
if body := getThroughTunnel(t, held, actorRef.Name); !strings.Contains(body, "preserved memory count:") {
11694
t.Fatalf("tunnel to port 80 got %q, want the default port's response", body)
11795
}
11896

@@ -322,18 +300,3 @@ func requestTunneled(conn interface {
322300
}
323301
return resp, string(body), nil
324302
}
325-
326-
// counterDefaultPortIPPattern matches the "hello from: <IP> | ..." response
327-
// counter.go's default (port 80) handler returns.
328-
var counterDefaultPortIPPattern = regexp.MustCompile(`^hello from: (\S+)`)
329-
330-
// selfReportedIP extracts the IP counter.go's getCurrentIP() reported in a
331-
// default-port response body.
332-
func selfReportedIP(t *testing.T, body string) string {
333-
t.Helper()
334-
m := counterDefaultPortIPPattern.FindStringSubmatch(body)
335-
if m == nil {
336-
t.Fatalf("default-port response body = %q, want it to match %q", body, counterDefaultPortIPPattern)
337-
}
338-
return m[1]
339-
}

0 commit comments

Comments
 (0)