Add cloud-2026-upgrade: step-by-step upgrade of the shop to Spring Boot 4.2.0 / Spring Cloud 2026.0.0, with probes
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4HkWoC7hLzk61vZa8
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Locale;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/** A dependency-free backend for the gateway probes. Run with: java scripts/Echo.java 9091 */
|
||||
public class Echo {
|
||||
public static void main(String[] args) throws IOException {
|
||||
AtomicInteger flaky = new AtomicInteger();
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", Integer.parseInt(args[0])), 0);
|
||||
|
||||
// Prints the forwarding headers exactly as they arrived, so we see what the gateway sent upstream.
|
||||
server.createContext("/headers", ex -> {
|
||||
var found = new TreeMap<String, String>();
|
||||
ex.getRequestHeaders().forEach((name, values) -> {
|
||||
String n = name.toLowerCase(Locale.ROOT);
|
||||
if (n.equals("forwarded") || n.startsWith("x-forwarded")) found.put(n, String.join(" | ", values));
|
||||
});
|
||||
StringBuilder body = new StringBuilder();
|
||||
found.forEach((k, v) -> body.append(k).append(": ").append(v.replaceAll("127\\.0\\.0\\.1:\\d+", "127.0.0.1:<port>")).append('\n'));
|
||||
if (found.isEmpty()) body.append("(no Forwarded or X-Forwarded-* header at all)\n");
|
||||
reply(ex, 200, body.toString());
|
||||
});
|
||||
// Always 500, and counts how often it was called.
|
||||
server.createContext("/flaky", ex -> {
|
||||
flaky.incrementAndGet();
|
||||
reply(ex, 500, "boom\n");
|
||||
});
|
||||
server.createContext("/count", ex -> reply(ex, 200, "upstream calls to /flaky: " + flaky.getAndSet(0) + "\n"));
|
||||
server.start();
|
||||
System.out.println("echo on " + args[0]);
|
||||
}
|
||||
|
||||
private static void reply(com.sun.net.httpserver.HttpExchange ex, int status, String body) throws IOException {
|
||||
byte[] bytes = body.getBytes();
|
||||
ex.getResponseHeaders().add("Content-Type", "text/plain");
|
||||
ex.sendResponseHeaders(status, bytes.length);
|
||||
ex.getResponseBody().write(bytes);
|
||||
ex.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""List what the spring-cloud-dependencies BOM manages in two release trains and print the difference.
|
||||
Usage: bom-diff.py OLD NEW (e.g. bom-diff.py 2025.1.5 2026.0.0). Set MAVEN_REPO to use another repository."""
|
||||
import os, re, sys, time, urllib.request
|
||||
import xml.etree.ElementTree as ET
|
||||
REPO = os.environ.get("MAVEN_REPO", "https://repo1.maven.org/maven2").rstrip("/")
|
||||
NS = "{http://maven.apache.org/POM/4.0.0}"
|
||||
cache = {}
|
||||
|
||||
def pom(g, a, v):
|
||||
key = (g, a, v)
|
||||
if key not in cache:
|
||||
url = f"{REPO}/{g.replace('.', '/')}/{a}/{v}/{a}-{v}.pom"
|
||||
for attempt in range(5):
|
||||
try:
|
||||
cache[key] = ET.fromstring(urllib.request.urlopen(url, timeout=30).read()); break
|
||||
except Exception:
|
||||
if attempt == 4: raise
|
||||
time.sleep(5 * (attempt + 1))
|
||||
return cache[key]
|
||||
|
||||
def managed(g, a, v, props=None, out=None):
|
||||
"""Collect groupId:artifactId -> version from a BOM, following imported BOMs and the parent POM's properties."""
|
||||
out = {} if out is None else out
|
||||
root = pom(g, a, v)
|
||||
p = {}
|
||||
parent = root.find(NS + "parent")
|
||||
chain = []
|
||||
while parent is not None:
|
||||
pr = pom(*(parent.findtext(NS + k) for k in ("groupId", "artifactId", "version")))
|
||||
chain.append(pr); parent = pr.find(NS + "parent")
|
||||
for doc in reversed(chain):
|
||||
for e in doc.findall(NS + "properties/*"): p[e.tag.replace(NS, "")] = (e.text or "").strip()
|
||||
for e in root.findall(NS + "properties/*"): p[e.tag.replace(NS, "")] = (e.text or "").strip()
|
||||
p.update(props or {})
|
||||
p["project.version"] = v; p["project.groupId"] = g
|
||||
def sub(s):
|
||||
for _ in range(5): s = re.sub(r"\$\{([^}]+)\}", lambda m: p.get(m.group(1), m.group(0)), s)
|
||||
return s
|
||||
for d in root.findall(f"{NS}dependencyManagement/{NS}dependencies/{NS}dependency"):
|
||||
dg, da, dv = (sub(d.findtext(NS + k, "").strip()) for k in ("groupId", "artifactId", "version"))
|
||||
if d.findtext(NS + "scope") == "import":
|
||||
managed(dg, da, dv, None, out)
|
||||
elif dg.startswith("org.springframework.cloud"):
|
||||
out.setdefault(f"{dg}:{da}", dv)
|
||||
return out
|
||||
|
||||
old, new = sys.argv[1], sys.argv[2]
|
||||
o = managed("org.springframework.cloud", "spring-cloud-dependencies", old)
|
||||
n = managed("org.springframework.cloud", "spring-cloud-dependencies", new)
|
||||
print(f"# org.springframework.cloud artifacts managed by spring-cloud-dependencies {old} vs {new}")
|
||||
print(f"managed in {old}: {len(o)} managed in {new}: {len(n)}")
|
||||
for title, keys, src in (("REMOVED", sorted(set(o) - set(n)), o), ("ADDED", sorted(set(n) - set(o)), n)):
|
||||
print(f"\n{title} ({len(keys)})")
|
||||
for k in keys:
|
||||
print(f" {k}:{src[k]}")
|
||||
if title == "REMOVED":
|
||||
g, a = k.split(":")
|
||||
try: pom(g, a, src[k]); print(" (that version's POM is published)")
|
||||
except Exception as e: print(f" (but that version's POM is NOT in the repository: {getattr(e, 'code', e)})")
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Compare the shop scenario output of the patched 4.1 line (step 1) with the final upgrade (step 5).
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
norm() { sed -E 's/"timestamp":"[^"]+"/"timestamp":"<ts>"/g; s/[0-9a-f]{32}-[0-9a-f]{16}/<trace>-<span>/g; s/[0-9a-f]{32}/<trace>/g' "$1"; }
|
||||
F=output/11-shop-before-after.txt
|
||||
{ echo "# The shop's scenario files, compared with Boot 4.1.3 / 2025.1.5 (timestamps and trace ids masked)."
|
||||
echo "# 00-startup-race.txt is left out: it records timing."
|
||||
for step in "2 only the two version numbers changed (step 2)" "5 all five steps applied"; do
|
||||
read -r n title <<<"$step"
|
||||
echo; echo "=== Boot 4.2.0 / 2026.0.0, $title"
|
||||
for f in 01-config-server 02-eureka-registry 03-gateway-requests 04-trace-propagation 05-circuit-breaker 06-eureka-lb-trap; do
|
||||
if diff -q <(norm run/shop1/output/$f.txt) <(norm run/shop$n/output/$f.txt) >/dev/null; then echo "$f.txt: identical"
|
||||
else echo "$f.txt: DIFFERENT"; diff <(norm run/shop1/output/$f.txt) <(norm run/shop$n/output/$f.txt) | grep '^[<>]' | grep -v '^[<>] *$' | cut -c1-110 | head -6 | sed 's/^/ /'; fi
|
||||
done
|
||||
done; } > $F
|
||||
cp run/shop1/output/06-eureka-lb-trap.txt output/12-eureka-lb-trap-before.txt
|
||||
# On 2026.0.0 the log is the evidence: the registry query in gotchas.sh can answer from Eureka's 30 s response cache.
|
||||
L=run/shop2/run/logs/order-service-broken.log
|
||||
{ echo "# order-service on 2026.0.0 with --shop.demo.primary-builder=false, taken from its own log"
|
||||
echo
|
||||
echo "lines with BeanCurrentlyInCreationException: $(grep -c BeanCurrentlyInCreationException $L)"
|
||||
echo "lines with 'No instances available for localhost': $(grep -c 'No instances available for localhost' $L)"
|
||||
grep -m1 -E 'registration status' $L | sed -E 's/^.*(DiscoveryClient_ORDER)/\1/'
|
||||
} > output/13-eureka-lb-trap-after.txt
|
||||
{ echo; echo "The yes/no registry line in 06-eureka-lb-trap.txt varies between runs on 2026.0.0 (Eureka caches that answer);"
|
||||
echo "the registration itself is recorded in 13-eureka-lb-trap-after.txt."; } >> $F
|
||||
cp run/shop5/output/03-gateway-requests.txt output/14-gateway-requests-after.txt
|
||||
cat $F output/1[23]-*.txt
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# Steps 4 and 5 on a running shop: change a value in the config repository and watch what refreshes.
|
||||
# $1 = directory produced by `upgrade.sh 4` (or 5) and built. $2 = output file name inside output/
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd "$1" || exit 1
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
F=$MOD/output/$2
|
||||
SECRET=demo-secret
|
||||
rm -rf run; mkdir -p run/logs; cp -r config-server/src/main/resources/config run/config
|
||||
trap 'scripts/stop.sh >/dev/null' EXIT
|
||||
start() { # service port extra...
|
||||
local name=$1 port=$2; shift 2
|
||||
nohup java -Xmx200m -XX:+UseSerialGC -jar "$name/target/$name-1.0.0.jar" "$@" > "run/logs/$name.log" 2>&1 &
|
||||
echo $! > "run/$name.pid"
|
||||
for _ in $(seq 1 90); do curl -fs "localhost:$port/actuator/health" >/dev/null 2>&1 && return; sleep 1; done
|
||||
echo "$name did not come up" >&2; tail -30 "run/logs/$name.log" >&2; exit 1
|
||||
}
|
||||
start config-server 8888 "--spring.cloud.config.server.native.search-locations=file:$PWD/run/config/" \
|
||||
"--spring.cloud.config.server.monitor.github.webhook-secret=$SECRET"
|
||||
start discovery-server 8761
|
||||
start product-service 8081
|
||||
start inventory-service 8083
|
||||
start order-service 8082
|
||||
for _ in $(seq 1 60); do
|
||||
curl -s -H 'Accept: application/json' localhost:8761/eureka/apps | grep -q 'order-service:8082' && break; sleep 2
|
||||
done
|
||||
sleep 35 # the config server's Eureka client fetches the registry every 30 s
|
||||
show() { echo "\$ curl localhost:$1$2"; curl -s "localhost:$1$2"; echo; }
|
||||
{
|
||||
echo "# order-service reads shop.order.* from the config server. $(grep -qE '^record' order-service/src/main/java/com/ankurm/shop/order/OrderProperties.java && echo 'OrderProperties is a Java record.' || echo 'OrderProperties is a class with setters.')"
|
||||
echo; echo "--- before"; show 8082 /orders/config
|
||||
echo; echo "--- an unsigned request to /monitor (the curl most tutorials show)"
|
||||
echo "\$ curl -X POST localhost:8888/monitor -d path=order-service"
|
||||
curl -s -o /dev/null -w 'HTTP %{http_code}\n' -X POST localhost:8888/monitor -d path=order-service
|
||||
echo; echo "--- edit order-service.yml in the config repository: currency EUR -> USD, max-quantity 10 -> 3"
|
||||
printf 'shop:\n order:\n currency: USD\n max-quantity: 3\n' > run/config/order-service.yml
|
||||
sleep 12
|
||||
echo "(no request sent: with a local file: repository the monitor module watches the directory itself)"
|
||||
echo; echo "--- config server log"
|
||||
grep -hE 'Monitoring for local|Refresh for: order-service|Failed to notify' run/logs/config-server.log | sed -E 's/^[^ ]+ +([A-Z]+) [0-9]+ --- (\[[^]]*\] )+/\1 /' | sed "s#$PWD/##" | head -4
|
||||
echo; echo "--- order-service log"
|
||||
grep -hE 'Refreshed keys' run/logs/order-service.log | sed -E 's/^[^ ]+ +([A-Z]+) [0-9]+ --- (\[[^]]*\] )+/\1 /' | tail -1
|
||||
echo; echo "--- what order-service uses after the refresh"; show 8082 /orders/config
|
||||
echo; echo "--- a signed GitHub-style push webhook, the way a remote Git repository would call"
|
||||
BODY='{"commits":[{"modified":["order-service.yml"]}]}'
|
||||
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.* //')
|
||||
echo "\$ curl -X POST localhost:8888/monitor -H 'X-GitHub-Event: push' -H 'X-Hub-Signature-256: sha256=<hmac>' -d '$BODY'"
|
||||
curl -s -w '\nHTTP %{http_code}\n' -X POST localhost:8888/monitor -H 'Content-Type: application/json' -H 'X-GitHub-Event: push' -H "X-Hub-Signature-256: sha256=$SIG" -d "$BODY"
|
||||
echo; echo "--- same webhook, wrong signature"
|
||||
curl -s -o /dev/null -w 'HTTP %{http_code}\n' -X POST localhost:8888/monitor -H 'Content-Type: application/json' -H 'X-GitHub-Event: push' -H "X-Hub-Signature-256: sha256=0000" -d "$BODY"
|
||||
} > "$F"
|
||||
cat "$F"
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# What actually changes on the classpath of the six services. Writes output/15-dependency-diff.txt
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd); cd "$MOD" || exit 1
|
||||
for s in 1 5; do
|
||||
(cd run/shop$s && mvn -B -q dependency:list -DoutputFile=deps.txt ${MVN_ARGS:-} >/dev/null)
|
||||
cat run/shop$s/*/deps.txt | grep -oE '^ +[a-z][^ ]+' | sed 's/ //g' | awk -F: '{print $1":"$2" "$(NF-1)}' | sort -u > run/deps$s.txt
|
||||
done
|
||||
{ echo "# Libraries of the six services: Boot 4.1.3 / 2025.1.5 -> Boot 4.2.0 / 2026.0.0 (selected groups)"
|
||||
python3 -I - <<'P'
|
||||
import collections
|
||||
def load(n):
|
||||
d=collections.defaultdict(set)
|
||||
for l in open(f'run/deps{n}.txt'):
|
||||
k,v=l.split(); d[k].add(v)
|
||||
return d
|
||||
a,b=load(1),load(5)
|
||||
want=('org.springframework.cloud:','io.github.resilience4j:','io.projectreactor','org.jetbrains','org.springframework:spring-core','org.springframework.boot:spring-boot ','io.micrometer:micrometer-core','org.eclipse.jgit:org.eclipse.jgit')
|
||||
for k in sorted(set(a)|set(b)):
|
||||
if not any((k+' ').startswith(w) for w in want): continue
|
||||
o,n=','.join(sorted(a.get(k,[]))) or '(absent)', ','.join(sorted(b.get(k,[]))) or '(gone)'
|
||||
if o!=n: print(f'{k:62} {o:10} -> {n}')
|
||||
P
|
||||
} > output/15-dependency-diff.txt
|
||||
cat output/15-dependency-diff.txt
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Bump only one of the two version numbers and capture what the config server says. Writes output/10-half-upgrades.txt
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd); cd "$MOD" || exit 1
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
F=output/10-half-upgrades.txt; : > $F
|
||||
for pair in "shopbootonly Boot 4.2.0 with Spring Cloud 2025.1.5" "shopcloudonly Boot 4.1.3 with Spring Cloud 2026.0.0"; do
|
||||
read -r dir title <<<"$pair"
|
||||
mkdir -p run/$dir/run/logs
|
||||
(cd run/$dir && timeout 60 java -Xmx200m -jar config-server/target/config-server-1.0.0.jar > run/logs/config-server.log 2>&1)
|
||||
{ echo "=== $title"; sed -n '/APPLICATION FAILED TO START/,/spring.cloud.compatibility-verifier.enabled=false/p' run/$dir/run/logs/config-server.log | grep -v '^\s*$'; echo; } >> $F
|
||||
done
|
||||
cat $F
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Native config repository asked for two labels at once ("a,b"): which one wins on each train?
|
||||
# $1 = built copy on 2025.1.5 (upgrade.sh 1), $2 = built copy on 2026.0.0 (upgrade.sh 2)
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd); cd "$MOD" || exit 1
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
repo=run/labels; mkdir -p $repo/a $repo/b
|
||||
echo 'demo.source: from a/app-prod.yml' > $repo/a/app-prod.yml
|
||||
echo 'demo.source: from b/app.yml' > $repo/b/app.yml
|
||||
F=output/43-native-multi-label.txt
|
||||
{ echo "# a/app-prod.yml and b/app.yml both set demo.source. Request: /app/prod/a,b"
|
||||
echo "# search-locations: file:<repo>/ (label directories are added automatically)"; } > $F
|
||||
ask() { # title dir extra...
|
||||
local title=$1 dir=$2; shift 2
|
||||
java -Xmx200m -jar "$dir/config-server/target/config-server-1.0.0.jar" \
|
||||
"--spring.cloud.config.server.native.search-locations=file:$MOD/$repo/" "$@" > run/labels.log 2>&1 &
|
||||
local pid=$!
|
||||
for _ in $(seq 1 60); do curl -fs localhost:8888/actuator/health >/dev/null 2>&1 && break; sleep 1; done
|
||||
{ echo; echo "=== $title"; curl -s localhost:8888/app/prod/a,b | python3 -I -c 'import sys,json
|
||||
for i,ps in enumerate(json.load(sys.stdin)["propertySources"]):
|
||||
print(" ", "wins " if i==0 else " ", ps["source"].get("demo.source"))'; } >> $F
|
||||
kill $pid; wait $pid 2>/dev/null
|
||||
}
|
||||
ask "Spring Cloud 2025.1.5" "$1"
|
||||
ask "Spring Cloud 2026.0.0" "$2"
|
||||
ask "Spring Cloud 2026.0.0 + spring.cloud.config.server.native.last-label-wins=false" "$2" --spring.cloud.config.server.native.last-label-wins=false
|
||||
cat $F
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# The config server with config-monitor and Eureka but no RestClient.Builder bean. $1 = built copy without spring-boot-starter-restclient.
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd); cd "$1" || exit 1
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
mkdir -p run/logs
|
||||
timeout 60 java -Xmx200m -jar config-server/target/config-server-1.0.0.jar > run/logs/config-server.log 2>&1
|
||||
{ echo "# config-server with spring-cloud-config-monitor and the Eureka client, WITHOUT spring-boot-starter-restclient"
|
||||
echo
|
||||
grep -m1 -oE 'java.lang.IllegalStateException: At least one PropertyPathNotifier[^\n]*' run/logs/config-server.log
|
||||
grep -m1 -E "Error creating bean with name 'propertyPathEndpoint'" run/logs/config-server.log | grep -oE "Error creating bean with name 'propertyPathEndpoint'"
|
||||
} > "$MOD/output/42-notifier-without-restclient.txt"
|
||||
cat "$MOD/output/42-notifier-without-restclient.txt"
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# The two class-level demos from the preview article, re-run on the GA jars (Boot 4.2.0 / Spring Cloud 2026.0.0).
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -B -q -f probes/preview-demos/pom.xml clean package ${MVN_ARGS:-} >/dev/null || exit 1
|
||||
CP='probes/preview-demos/target/classes:probes/preview-demos/target/dependency/*'
|
||||
clean() { grep -vE 'Picked up|DEBUG|^\s+at |^\s+\.\.\.|^org\.spring|^Caused by' | sed -E 's/^[0-9:.]+ \[main\] WARN org\.springframework\.cloud\.config\.monitor\./WARN /'; }
|
||||
for pair in "ForwardedDemo 50-forwarded-filters-ga" "HttpNotifierDemo 51-http-notifier-ga"; do
|
||||
read -r main file <<<"$pair"
|
||||
env -u JAVA_TOOL_OPTIONS java -cp "$CP" ankurm.sc.$main 2>&1 | clean > output/$file.txt
|
||||
cat output/$file.txt
|
||||
done
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
# Same two gateway apps, three release trains, three trusted-proxy settings. Writes output/20-*.txt ... 23-*.txt
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
TRAINS=("4.1.3 2025.1.3" "4.1.3 2025.1.5" "4.2.0 2026.0.0")
|
||||
|
||||
build() { # flavour boot cloud
|
||||
local dir=run/probe-$1-$3
|
||||
[ -d "$dir/dependency" ] && return
|
||||
mvn -B -q -f probes/gateway-$1/pom.xml -Dboot.version=$2 -Dcloud.version=$3 clean package ${MVN_ARGS:-} >/dev/null || exit 1
|
||||
mkdir -p "$dir"; cp -r probes/gateway-$1/target/classes probes/gateway-$1/target/dependency "$dir/"
|
||||
}
|
||||
if [ "${1:-}" = "--build" ]; then
|
||||
for t in "${TRAINS[@]}"; do read -r boot cloud <<<"$t"; build webmvc $boot $cloud; build webflux $boot $cloud; done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
unset JAVA_TOOL_OPTIONS # only for the runs: Maven above may need it
|
||||
start_gw() { # flavour cloud extra-args...
|
||||
local flavour=$1 cloud=$2; shift 2
|
||||
java -Xmx200m -XX:+UseSerialGC -cp "run/probe-$flavour-$cloud/classes:run/probe-$flavour-$cloud/dependency/*" \
|
||||
com.ankurm.upgrade.GatewayProbeApplication "$@" > run/probe.log 2>&1 &
|
||||
GW=$!
|
||||
for _ in $(seq 1 60); do curl -s -o /dev/null localhost:8090/ && return; sleep 1; done
|
||||
echo "gateway did not start" >&2; tail -20 run/probe.log >&2; exit 1
|
||||
}
|
||||
stop_gw() { kill $GW; wait $GW 2>/dev/null; }
|
||||
|
||||
java scripts/Echo.java 9091 > run/echo.log 2>&1 & ECHO=$!
|
||||
trap 'kill $ECHO 2>/dev/null' EXIT
|
||||
for _ in $(seq 1 30); do curl -s -o /dev/null localhost:9091/headers && break; sleep 1; done
|
||||
|
||||
FORGED=(-H 'Forwarded: for=198.51.100.7;proto=https' -H 'X-Forwarded-For: 198.51.100.7' -H 'X-Forwarded-Proto: https')
|
||||
|
||||
n=20
|
||||
for flavour in webmvc webflux; do
|
||||
F=output/$n-trusted-proxies-$flavour.txt; : > $F
|
||||
{ echo "# Gateway Server $flavour. The client is 127.0.0.1 and sends forged headers:"
|
||||
echo "# Forwarded: for=198.51.100.7;proto=https X-Forwarded-For: 198.51.100.7 X-Forwarded-Proto: https"
|
||||
echo "# Below: the forwarding headers the backend actually received."; } >> $F
|
||||
for t in "${TRAINS[@]}"; do
|
||||
read -r boot cloud <<<"$t"
|
||||
for setting in unset '10\..*' '127\.0\.0\.1'; do
|
||||
args=()
|
||||
[ "$setting" != unset ] && args=("--spring.cloud.gateway.server.$flavour.trusted-proxies=$setting")
|
||||
start_gw $flavour $cloud "${args[@]}"
|
||||
case "$setting" in unset) label="trusted-proxies not set";; '10\..*') label="trusted-proxies=$setting (caller NOT trusted)";; *) label="trusted-proxies=$setting (caller trusted)";; esac
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud | $label"; curl -s "${FORGED[@]}" localhost:8090/headers; } >> $F
|
||||
stop_gw
|
||||
done
|
||||
done
|
||||
n=$((n+1))
|
||||
done
|
||||
|
||||
# Behind a load balancer: the peer (127.0.0.1) plays the balancer and reports the real client, 203.0.113.50.
|
||||
H=output/24-behind-load-balancer.txt; : > $H
|
||||
echo "# 127.0.0.1 plays a load balancer. It sends: X-Forwarded-For: 203.0.113.50 Forwarded: for=203.0.113.50;proto=https" >> $H
|
||||
echo "# 203.0.113.50 is the real client. Does it survive the gateway?" >> $H
|
||||
LB=(-H 'X-Forwarded-For: 203.0.113.50' -H 'Forwarded: for=203.0.113.50;proto=https')
|
||||
for flavour in webmvc webflux; do
|
||||
for t in "${TRAINS[@]}"; do
|
||||
read -r boot cloud <<<"$t"
|
||||
for setting in '127\.0\.0\.1' '127\.0\.0\.1|203\.0\.113\.50'; do
|
||||
start_gw $flavour $cloud "--spring.cloud.gateway.server.$flavour.trusted-proxies=$setting"
|
||||
{ echo; echo "=== $flavour | Spring Cloud $cloud | trusted-proxies=$setting"; curl -s "${LB[@]}" localhost:8090/headers | grep -E '^(x-forwarded-for|forwarded):'; } >> $H
|
||||
stop_gw
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
F=output/22-retry-filter-webflux.txt; : > $F
|
||||
echo "# WebFlux gateway, Retry filter (retries: 3, statuses: INTERNAL_SERVER_ERROR) in front of a backend that always answers 500." >> $F
|
||||
G=output/23-websocket-origin-webflux.txt; : > $G
|
||||
echo "# WebFlux gateway with a ws:// route. A handshake with a foreign Origin header." >> $G
|
||||
echo "# The backend is a plain HTTP server, so a handshake the gateway lets through fails further down." >> $G
|
||||
for t in "${TRAINS[@]}"; do
|
||||
read -r boot cloud <<<"$t"
|
||||
start_gw webflux $cloud
|
||||
curl -s -o /dev/null localhost:8090/count
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud"
|
||||
echo "client status: $(curl -s -o /dev/null -w '%{http_code}' localhost:8090/flaky)"
|
||||
curl -s localhost:8090/count; } >> $F
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud"
|
||||
curl -s -i --max-time 5 -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' \
|
||||
-H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' -H 'Origin: https://evil.example' localhost:8090/ws/chat | head -1 | tr -d '\r'
|
||||
echo; } >> $G
|
||||
stop_gw
|
||||
done
|
||||
cat output/22*.txt output/23*.txt output/24*.txt
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# OpenFeign @SpringQueryMap and the vanished reactor-extra dependency, on the old and new train.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p run output
|
||||
F=output/30-openfeign-querymap.txt; : > $F
|
||||
echo "# A record with a nested record, a list and a map, sent with @SpringQueryMap. What the server received (URL-decoded)." >> $F
|
||||
G=output/31-reactor-extra.txt; : > $G
|
||||
echo "# A class that imports reactor.retry.Repeat in a project that declares only spring-cloud-starter-loadbalancer." >> $G
|
||||
for t in "4.1.3 2025.1.5" "4.2.0 2026.0.0"; do
|
||||
read -r boot cloud <<<"$t"
|
||||
mvn -B -q -f probes/openfeign-querymap/pom.xml -Dboot.version=$boot -Dcloud.version=$cloud clean package ${MVN_ARGS:-} >/dev/null || exit 1
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud"
|
||||
java -Xmx200m -cp "probes/openfeign-querymap/target/classes:probes/openfeign-querymap/target/dependency/*" \
|
||||
com.ankurm.upgrade.QueryMapProbeApplication --spring.main.banner-mode=off 2>&1 | grep -E '^RESULT' | sed 's/^RESULT //'
|
||||
ls probes/openfeign-querymap/target/dependency | grep -E '^feign-core|^spring-cloud-openfeign-core'; } >> $F
|
||||
if [ $cloud = 2026.0.0 ]; then
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud + spring.cloud.openfeign.client.config.default.nested-query-map-enabled=true"
|
||||
java -Xmx200m -cp "probes/openfeign-querymap/target/classes:probes/openfeign-querymap/target/dependency/*" \
|
||||
com.ankurm.upgrade.QueryMapProbeApplication --spring.main.banner-mode=off \
|
||||
--spring.cloud.openfeign.client.config.default.nested-query-map-enabled=true 2>&1 | grep -E '^RESULT' | sed 's/^RESULT //'; } >> $F
|
||||
fi
|
||||
{ echo; echo "=== Boot $boot / Spring Cloud $cloud"
|
||||
if out=$(mvn -B -q -f probes/reactor-extra/pom.xml -Dboot.version=$boot -Dcloud.version=$cloud clean compile ${MVN_ARGS:-} 2>&1); then
|
||||
echo "compiles"
|
||||
else
|
||||
echo "$out" | grep -E '^\[ERROR\] .*\.java' | head -3 | sed "s#$PWD/##"
|
||||
fi; } >> $G
|
||||
done
|
||||
cat $F $G
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Diff spring-configuration-metadata.json of Spring Cloud jars between 2025.1.5 and 2026.0.0.
|
||||
Usage: props-diff.py (set MAVEN_REPO to use another repository)"""
|
||||
import io, json, os, time, urllib.request, zipfile
|
||||
REPO = os.environ.get("MAVEN_REPO", "https://repo1.maven.org/maven2").rstrip("/")
|
||||
ARTIFACTS = [ # artifactId, version in 2025.1.5, version in 2026.0.0
|
||||
("spring-cloud-commons", "5.0.5", "5.1.0"), ("spring-cloud-context", "5.0.5", "5.1.0"),
|
||||
("spring-cloud-loadbalancer", "5.0.5", "5.1.0"),
|
||||
("spring-cloud-config-client", "5.0.7", "5.1.0"), ("spring-cloud-config-server", "5.0.7", "5.1.0"),
|
||||
("spring-cloud-config-monitor", "5.0.7", "5.1.0"),
|
||||
("spring-cloud-gateway-server-webflux", "5.0.5", "5.1.0"), ("spring-cloud-gateway-server-webmvc", "5.0.5", "5.1.0"),
|
||||
("spring-cloud-openfeign-core", "5.0.4", "5.1.0"), ("spring-cloud-stream", "5.0.5", "5.1.0"),
|
||||
("spring-cloud-netflix-eureka-client", "5.0.4", "5.1.0"), ("spring-cloud-netflix-eureka-server", "5.0.4", "5.1.0"),
|
||||
("spring-cloud-circuitbreaker-resilience4j", "5.0.3", "5.1.0"),
|
||||
]
|
||||
|
||||
def props(a, v):
|
||||
url = f"{REPO}/org/springframework/cloud/{a}/{v}/{a}-{v}.jar"
|
||||
for attempt in range(5):
|
||||
try:
|
||||
data = urllib.request.urlopen(url, timeout=60).read(); break
|
||||
except Exception:
|
||||
if attempt == 4: raise
|
||||
time.sleep(5 * (attempt + 1))
|
||||
out = {}
|
||||
with zipfile.ZipFile(io.BytesIO(data)) as z:
|
||||
for name in ("META-INF/spring-configuration-metadata.json", "META-INF/additional-spring-configuration-metadata.json"):
|
||||
if name in z.namelist():
|
||||
for p in json.loads(z.read(name)).get("properties", []):
|
||||
out.setdefault(p["name"], {}).update(p)
|
||||
return out
|
||||
|
||||
for a, old, new in ARTIFACTS:
|
||||
o, n = props(a, old), props(a, new)
|
||||
removed = sorted(set(o) - set(n)); added = sorted(set(n) - set(o))
|
||||
dep = sorted(k for k in set(n) & set(o) if ("deprecation" in n[k]) and ("deprecation" not in o[k]))
|
||||
changed = sorted(k for k in set(n) & set(o) if str(n[k].get("defaultValue")) != str(o[k].get("defaultValue")))
|
||||
print(f"== {a} {old} -> {new}: {len(o)} -> {len(n)} properties")
|
||||
for k in removed: print(f" removed {k}")
|
||||
for k in added: print(f" added {k}" + (f" (default {n[k]['defaultValue']})" if "defaultValue" in n[k] else ""))
|
||||
for k in dep: print(f" newly deprecated {k} -> {n[k]['deprecation'].get('replacement', '(no replacement)')}")
|
||||
for k in changed: print(f" default changed {k}: {o[k].get('defaultValue')} -> {n[k].get('defaultValue')}")
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuilds everything and regenerates output/. Needs JDK 25 (21+ works for the shop), Maven 3.9+, curl, python3,
|
||||
# openssl and patch. Ports 8081-8083, 8080, 8090-8095, 8761, 8888 and 9091 must be free.
|
||||
# Extra Maven arguments (for example a settings file) go in MVN_ARGS.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
build() { (cd "$1" && mvn -B -q -DskipTests package ${MVN_ARGS:-}) || exit 1; }
|
||||
M=${MAVEN_REPO:-https://repo1.maven.org/maven2}
|
||||
W=${RUN_WRAPPER:-} # optional command put in front of every script that starts servers
|
||||
|
||||
echo "== version facts"
|
||||
MAVEN_REPO=$M python3 -I scripts/bom-diff.py 2025.1.5 2026.0.0 > output/01-bom-diff.txt
|
||||
MAVEN_REPO=$M python3 -I scripts/props-diff.py > output/02-properties-diff.txt
|
||||
|
||||
echo "== the shop, step by step"
|
||||
scripts/upgrade.sh 0 0 && scripts/upgrade.sh 1 1 && scripts/upgrade.sh 2 2 && scripts/upgrade.sh 4 4 && scripts/upgrade.sh 5 5
|
||||
scripts/upgrade.sh 1 bootonly && sed -i '0,/<version>4.1.3<\/version>/s//<version>4.2.0<\/version>/' run/shopbootonly/pom.xml
|
||||
scripts/upgrade.sh 1 cloudonly && sed -i 's/<spring-cloud.version>2025.1.5</<spring-cloud.version>2026.0.0</' run/shopcloudonly/pom.xml
|
||||
for s in 0 1 2 4 5 bootonly cloudonly; do build run/shop$s; done
|
||||
scripts/upgrade.sh 4 norc
|
||||
python3 -I - <<'P'
|
||||
p='run/shopnorc/config-server/pom.xml'; s=open(p).read()
|
||||
i=s.index('<!-- ... and a RestClient.Builder bean -->'); j=s.index('</dependency>',i)+len('</dependency>'); open(p,'w').write(s[:i]+s[j:])
|
||||
P
|
||||
build run/shopnorc
|
||||
$W scripts/half-upgrades.sh
|
||||
for s in 1 2 5; do $W scripts/shop-scenarios.sh "$PWD/run/shop$s"; done
|
||||
scripts/collect-shop.sh
|
||||
scripts/dependency-diff.sh
|
||||
$W scripts/config-notify.sh "$PWD/run/shop4" 40-config-notify-record.txt
|
||||
$W scripts/config-notify.sh "$PWD/run/shop5" 41-config-notify-class.txt
|
||||
$W scripts/notify-without-restclient.sh "$PWD/run/shopnorc"
|
||||
$W scripts/native-labels.sh "$PWD/run/shop1" "$PWD/run/shop2"
|
||||
|
||||
echo "== probes"
|
||||
scripts/probe-gateway.sh --build && $W scripts/probe-gateway.sh
|
||||
$W scripts/shop-trusted-proxies.sh "$PWD/run/shop5"
|
||||
scripts/probe-libs.sh
|
||||
scripts/preview-demos.sh
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs the shop's own scenarios (scripts/demo.sh + gotchas.sh of the parent project) on an upgraded copy.
|
||||
# $1 = directory produced by upgrade.sh and already built with `mvn -DskipTests package`.
|
||||
cd "$1" || exit 1
|
||||
trap 'scripts/stop.sh >/dev/null' EXIT
|
||||
scripts/start.sh && scripts/demo.sh >/dev/null && scripts/gotchas.sh >/dev/null && echo SCENARIOS-DONE
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Step 3 on the real shop gateway: its configuration still comes from the config server, only the routes are
|
||||
# swapped for one that points at the echo backend. $1 = built copy from upgrade.sh 3 or later.
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd); cd "$1" || exit 1
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
mkdir -p run/logs
|
||||
F=$MOD/output/25-shop-gateway-trusted-proxies.txt
|
||||
java "$MOD/scripts/Echo.java" 9091 > run/logs/echo.log 2>&1 & ECHO=$!
|
||||
java -Xmx200m -jar config-server/target/config-server-1.0.0.jar --eureka.client.enabled=true > run/logs/config-server.log 2>&1 & CS=$!
|
||||
trap 'kill $ECHO $CS 2>/dev/null' EXIT
|
||||
for _ in $(seq 1 90); do curl -fs localhost:8888/actuator/health >/dev/null 2>&1 && break; sleep 1; done
|
||||
{ echo "# The shop gateway (WebMVC) on Spring Cloud 2026.0.0, client 127.0.0.1 sending: X-Forwarded-For: 198.51.100.7"; } > $F
|
||||
for value in '' '10\..*' '127\.0\.0\.1'; do
|
||||
TRUSTED_PROXIES="$value" java -Xmx200m -jar gateway/target/gateway-1.0.0.jar --eureka.client.enabled=false \
|
||||
'--spring.cloud.gateway.server.webmvc.routes[0].id=headers' \
|
||||
'--spring.cloud.gateway.server.webmvc.routes[0].uri=http://127.0.0.1:9091' \
|
||||
'--spring.cloud.gateway.server.webmvc.routes[0].predicates[0]=Path=/headers' > run/logs/gateway.log 2>&1 & GW=$!
|
||||
for _ in $(seq 1 90); do curl -fs localhost:8080/actuator/health >/dev/null 2>&1 && break; sleep 1; done
|
||||
{ echo; echo "=== TRUSTED_PROXIES=${value:-<not set>}"
|
||||
curl -s -H 'X-Forwarded-For: 198.51.100.7' localhost:8080/headers; } >> $F
|
||||
kill $GW; wait $GW 2>/dev/null
|
||||
done
|
||||
cat $F
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copies the six-service shop (../ ) into run/shop and applies the upgrade steps in order.
|
||||
# Usage: scripts/upgrade.sh <last-step 0..4> (0 = untouched baseline)
|
||||
set -euo pipefail
|
||||
MOD=$(cd "$(dirname "$0")/.." && pwd)
|
||||
SHOP=$MOD/run/shop${2:-}
|
||||
mkdir -p "$SHOP"
|
||||
for item in pom.xml scripts config-server discovery-server gateway product-service inventory-service order-service; do
|
||||
rm -rf "${SHOP:?}/$item"; cp -r "$MOD/../$item" "$SHOP/"
|
||||
done
|
||||
rm -rf "$SHOP"/*/target "$SHOP/run" "$SHOP/output"
|
||||
n=0
|
||||
for p in "$MOD"/steps/0*.patch; do
|
||||
n=$((n+1)); [ $n -le "$1" ] || break
|
||||
(cd "$SHOP" && patch -p1 -s < "$p"); echo "applied $(basename "$p")"
|
||||
done
|
||||
Reference in New Issue
Block a user