Repository navigation
[ISSUE #8427] Complete local uri registration in the opt-in client. - #8500
Conversation
wy471x
left a comment
There was a problem hiding this comment.
Reviewed the diff at 17c27ed. The wiring itself is right (bean + registry-mode gate + namespace/RPC/app/context/host/port coalescing + existing failback retry), but one field leaves the registration incomplete and one behaviour change deserves a decision.
Blocking
1. Published URIs carry no protocol, so https/wss clients are registered as plain http/ws — UriApiRegistrarImplImpl.registerUri
URIRegisterDTO uri = URIRegisterDTO.builder()
.namespaceId(namespaceId)
.contextPath(clientRegisterConfig.getContextPath())
.appName(clientRegisterConfig.getAppName())
.eventType(EventType.REGISTER)
.host(clientRegisterConfig.getHost())
.port(port)
.rpcType(rpcType)
.build();The legacy pipeline this replaces does set it (SpringMvcClientEventListener: props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.HTTP) at construction, .protocol(protocol) on the DTO), and URIRegisterDTO.protocol has no default. Downstream, ShenyuClientRegisterDivideServiceImpl.buildDivideUpstreamList maps dto.getProtocol() into the divide upstream, and Upstream.normalizeProtocol turns a blank protocol into DEFAULT_PROTOCOL (http://). Consequences:
- an opt-in client configured with
shenyu.client.http.props.protocol=https(orwss) registers an upstream that the gateway dials ashttp://host:port, so every request fails, with no error at registration time; - legacy rows carry
http://while opt-in rows carrynull, and upstream identity comparison in admin uses the canonical protocol, so a client migrating from the listener to@EnableClientRegisterdoes not match its own existing divide upstream and duplicates it.
Suggested change: expose the protocol on ClientRegisterConfig/ClientRegisterConfigImpl (props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.HTTP), exactly as the legacy listener does) and set .protocol(...) on the DTO. Please also assert it in EnableClientRegisterUriTest, which currently checks rpcType/contextPath/appName/host/port only.
Non-blocking
2. Invalid port aborts application startup. registerUri throws IllegalArgumentException, and it is reached from ClientApiRefreshedEventListener during ContextRefreshedEvent, so SpringApplication.run fails. This matters because ClientRegisterConfigImpl.getPort() falls back to PortUtils.findPort(...), which can be 0 when server.port=0 and the port is not resolved yet (the #8426 / #8453 case). If the port is only temporarily unknown, a warning plus "publish nothing this round" (the actual-port fix then publishes on the next refresh) keeps the application bootable; if a configured port is genuinely invalid, failing fast is fine. Please state which contract you want, and note it in docs/.
3. Per-namespace isolation. PR description says "Keep successful namespace enqueues when another enqueue throws", but the for (String namespaceId : ...) loop has no try/catch, so a synchronous publisher.publishEvent failure skips every remaining namespace until the next refresh. A per-namespace try/catch with a bounded warning (no configuration values) matches the stated behaviour.
4. Discovery predicate. The "shenyu.discovery.type"/local comparison is now the fifth copy (the listeners, the MVC starter and now this registrar). Either move the gate to the wiring (@ConditionalOnProperty on the uriApiRegistrar bean) or extract one helper, so a future change to how local mode is expressed cannot silently desync.
5. Set<List<?>> publishedIdentities. The six-element untyped tuple is rebuilt from the DTO it was just built from, and ShenyuClientURIExecutorSubscriber already defines instance identity differently (namespace + contextPath + host + port). A small record type shared with the subscriber would make the key self-describing and keep the two definitions from drifting. Also note the @ConditionalOnProperty guard on ClientRegisterConfiguration is byte-identical to the one added by #8504 (same author) — please coordinate ownership so only one PR carries it.
17c27ed to
e0edf7a
Compare
e0edf7a to
bfe663a
Compare
|
Thanks for the review, @wy471x. The URI payload now preserves the HTTP/WebSocket scheme, enqueue failures are isolated by namespace, and an unresolved port skips publication for that refresh without aborting startup. The global registration guard is now owned by #8504. All required CI checks passed, and the previously timed-out HTTP integration job passed on the latest run. Could you take another look? |
Aias00
left a comment
There was a problem hiding this comment.
Stream Agent analysis
Review of #8500 (Complete local uri registration in the opt-in client). The full diff was read and all previously raised blocking findings are addressed: URIs now carry the configured/defaulted protocol, enqueue failures are isolated per namespace, pending ports 0/-1 skip safely, and the local-discovery gate moved into wiring. No concrete new HIGH/CRITICAL defect found; CI passed.
Evidence: ["Full diff read via resource_diff: 8 pages, offset 0 to 42930 with has_more=false; 9 changed files (spec, config wiring, protocol accessor, UriApiRegistrarImplImpl, and new/updated tests).","Prior blocking protocol issue fixed: URIRegisterDTO now sets .protocol(clientRegisterConfig.getProtocol()); ClientRegisterConfigImpl.getProtocol() uses ShenyuClientConstants.HTTP/WS (verified http:// and ws://, PROTOCOL="protocol") with a backward-compatible default method on ClientRegisterConfig; protocol asserted in tests.","Prior non-blocking findings addressed: publish() try/catch isolates per-namespace enqueue failures, pending-port 0/-1 skip with warning (contract documented in spec.md), typed UriIdentity record dedup, discovery gate via @conditional(LocalDiscoveryCondition.class) matching isDiscoveryLocalMode; evidence reports CI passed with 38 checks and no failed/pending checks."]
Next steps: ["Coordinate merge ordering with #8504 for the global shenyu.register.enabled opt-in guard, which this PR intentionally leaves to that change."]
Verdict: PASS; publication: COMMENT (DIFF_DELIVERY_INCOMPLETE)
Findings: []
Scope: captured GitHub evidence only; no local tests were executed.
Task: dd071994-5e39-4446-9ab1-02d818d5a0ef Commit: bfe663a0a74773b034c5b2da6632a507d6052b9a
|
@wy471x Could you re-review the latest revision when you have a chance? URI registration now preserves the configured scheme and skips publishing when the port is unresolved. The required CI checks passed. Thanks! |
|
@wy471x Could you re-review |
wy471x
left a comment
There was a problem hiding this comment.
Re-review at bfe663a0
The blocking item from the previous review is resolved: ClientRegisterConfig gained an optional getProtocol() with a protocol-specific default, ClientRegisterConfigImpl returns http:// / ws:// from the props, the DTO carries it, and UriApiRegistrarTest#testWebSocketProtocolIsPublished covers both the default and an explicit wss://. The enqueue-failure isolation, the identity record and the port handling are also in place, and the shenyu.register.enabled guard is now owned by #8504 only, with this PR's spec saying so.
Two items still need work before merge.
1. The URI is published with the protocol and endpoint of the primary ClientRegisterConfig, not of the bean (blocking). ClientRegisterConfiguration#uriApiRegistrar is a single bean in the shared autoconfig and injects ClientRegisterConfig. In an application that wires both the HTTP and the WebSocket starter, that bean is the @Primary springMvcClientRegisterConfig, while the URI rpcType comes from the bean (ApiBeanUtil.getRpcType(apiBean)). A WebSocket bean then publishes rpcType=websocket with protocol=http:// and the HTTP port, which contradicts the spec requirement "HTTP and WebSocket URIs MUST retain the configured protocol, defaulting to http:// and ws:// respectively" and would register an upstream the gateway dials over the wrong scheme. EnableClientRegisterUriTest only exercises an HTTP fixture, and UriApiRegistrarTest#testWebSocketProtocolIsPublished constructs the registrar with a WebSocket config directly, so neither case is covered. Either resolve the config per registered rpc type (as the legacy listeners do through their own starter), or register one URI registrar per protocol starter.
2. Port handling does not match the spec's retryable-failure scenario. The scenario groups "a port is malformed or out of range" with the retryable cases and requires that startup is not failed, but registerUri throws IllegalArgumentException, which reaches ClientApiRefreshedEventListener during ContextRefreshedEvent and aborts the application. testMalformedPortDoesNotPublishUri asserts the exception, so the current behaviour is deliberate — it just is not what the spec says. Decide which contract you want, align spec, README and test, and note the choice in the durable spec.
Minor: when a processor leaves the bean REGISTRABLE and excludes every ApiDefinition, doRegisterBean still publishes one URI per namespace. If that is intended (bean-level registration), say so where the exclusion scenario is specified.
Verification (local, head bfe663a0, JDK 21, maven wrapper)
./mvnw -B -pl shenyu-client/shenyu-client-autoconfig,shenyu-client/shenyu-client-core,\
shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc \
-am test -Dtest=EnableClientRegisterUriTest,RegistrarNamespaceTest,UriApiRegistrarTest
./mvnw -B -pl <same modules> apache-rat:check
UriApiRegistrarTest 8/8, RegistrarNamespaceTest 2/2, EnableClientRegisterUriTest 10/10 (including the HTTPS protocol case and the partial-failure retry); checkstyle clean; RAT passes.
Verdict
Request changes — the mixed-protocol protocol/endpoint resolution is a correctness issue for applications that register more than one protocol, and the port contract needs to match the spec.
|
@wy471x Thanks for the review. Build and E2E both passed on this commit. Could you take another look? |
wy471x
left a comment
There was a problem hiding this comment.
Re-review at a3d54be8
Blocking item 1 (primary-config protocol/endpoint) is resolved. UriApiRegistrarImplImpl now takes the full List<ClientRegisterConfig> and resolves the configuration per registered rpc type:
private ClientRegisterConfig configurationFor(final String rpcType) {
if (protocolConfigurations.isEmpty() || matchesProtocol(clientRegisterConfig, rpcType)) {
return clientRegisterConfig;
}
List<ClientRegisterConfig> matching = protocolConfigurations.stream().filter(c -> matchesProtocol(c, rpcType)).toList();
if (matching.size() != 1) {
throw new IllegalStateException("Local URI registration requires one client configuration for RPC type " + rpcType);
}
return matching.get(0);
}The primary is still preferred when it matches (so single-starter applications are untouched), and a mismatch fails loudly instead of publishing another protocol's endpoint. MixedStarterUriRegistrationTest is the coverage that was missing: a real context with both the MVC and WebSocket starters asserts two published URIs, the WebSocket one carrying wss://, /websocket, 127.0.0.2 and 8001 while the HTTP one keeps https://, /http, 127.0.0.1 and 8080. UriApiRegistrarTest#testMissingProtocolConfigurationDoesNotPublishPrimaryEndpoint covers the ambiguous/missing case.
Blocking item 2 (port contract) is resolved by making the contract explicit. The spec now separates "unresolved advertised port (0 / -1)" from "invalid configured advertised port", and states that the latter fails startup with a bounded diagnostic that does not echo the value; docs/java-client-repository-boundary.md repeats it, and EnableClientRegisterUriTest#testInvalidAdvertisedPortFailsStartupWithoutPublishingUri is parameterised over invalid and 65536. advertisedPort truncates to the fixed INVALID_PORT message while still catching the real NumberFormatException from ClientRegisterConfigImpl#getPort (Integer::parseInt), so the redaction is genuine.
The minor point about bean-level registration with all APIs excluded is now stated in the spec ("A processor that explicitly enables bean-level registration can still publish the bean's URI even when all API definitions are excluded") and in the boundary doc.
Verified locally on a3d54be8 (JDK 21, -pl shenyu-client-autoconfig,shenyu-client-core,starter-client-springmvc,starter-client-spring-websocket -am): UriApiRegistrarTest 10, RegistrarNamespaceTest 2, EnableClientRegisterUriTest 11 (the invalid-port case is parameterised), MixedStarterUriRegistrationTest 1 — green; checkstyle clean.
CI. Green on this head: build (7 shards), e2e-case (6), native-sql (5), sql-matrix, rat_check, check-license-header, plugin_contract, registry_dependencies, CodeQL. Nothing attributable to this PR.
Verdict: Approve. Mixed-protocol applications now get the endpoint, scheme and identity of the starter that actually registered the URI, and the port contract matches the spec.
Fixes #8427
Problem and change
@EnableClientRegistersuppresses the legacy MVC listener, but its replacement registers metadata without a local upstream URI. The gateway has no upstream for an otherwise registered backend.Wire the URI registrar only for exact
shenyu.discovery.type=local(also the default). Each eligible namespace/RPC/app/context/host/port identity is queued once after URI-specific processor filtering. HTTP and WebSocket URI payloads carry the configured protocol, with the legacyhttp://andws://defaults. A default accessor keeps existing customClientRegisterConfigimplementations compatible. Heartbeat, offline and HTTP failback continue to use the same payload.A synchronous enqueue failure leaves that identity retryable and allows the remaining namespaces to queue. The registrar uses a typed snapshot of its enqueue key. The subscriber's endpoint key still serves its existing heartbeat bookkeeping and is unchanged.
The URI registrar selects the available client configuration by the registered RPC type. A primary HTTP configuration cannot supply the WebSocket endpoint in a mixed application. Missing or ambiguous matching configurations fail with a diagnostic. Metadata, API-documentation and broader multi-starter behavior remain in #8428.
Unresolved HTTP/WebSocket ports
0and-1skip URI publication for this refresh and allow startup. Malformed or out-of-range ports fail startup during context refresh before the affected endpoint's URI is published. If a processor explicitly enables bean-level publication, the bean can publish its URI even when every API definition is excluded. Actual random-port resolution remains #8426 / #8453.#8504 owns the global
shenyu.register.enabledopt-in guard and its regression test. Merge #8504 first to include that safeguard with URI registration. Both branches apply cleanly together. The separate migration in apache/shenyu-client-java#16 needs to carry the URI behavior over.IssueSpec
IssueSpec-Mode: full
IssueSpec-Reason: Complete opt-in local URI publication and preserve the existing discovery and endpoint contract.
IssueSpec-Proposal: #8497
IssueSpec-Design: #8498
IssueSpec-Implement: #8499
IssueSpec-Specs: SPEC-8497001
IssueSpec-Tasks: TASK-8499001
IssueSpec-Validation: Java 17 Maven-wrapper verify passed in 25 reactor modules with 258 tests in 44 classes and zero failures, errors or skips. Checkstyle and RAT passed. New-code gate reports zero findings. Implementation gate and durable-spec check passed. Full root clean install and Docker e2e were not run locally.
Verification
Exact affected Maven command (PowerShell, Java 17)
The servlet/HTTP fixture verifies default HTTP and configured HTTPS URI payloads, exact discovery-mode gating, repeated refresh, multiple namespaces, processor exclusion, unresolved and malformed ports, HTTP 503 failback and lifecycle payloads. Core tests verify WebSocket schemes, namespace isolation on an enqueue exception and a later refresh after the port becomes usable. The mixed-starter regression loads the actual MVC and WebSocket starter configurations with different hosts, ports, contexts, app names and schemes. It submits registration beans directly to the Spring-wired URI registrar and inspects both payloads. The pre-fix run advertised the HTTP scheme for the WebSocket URI. The embedded HTTP fixture also checks startup failure for malformed and out-of-range ports. The real gateway smoke below exercised a plain HTTP backend.
Actual Admin/bootstrap evidence from the initial revision
The initial revision
17c27edwas tested against an isolated Java 17 H2 Admin and a current-source bootstrap with websocket sync. The old source published two APIs but no URI, returning gateway code-119. The fixed local fixture persisted one live upstream and returned HTTP 200 with the backend response. A registry-mode control published two APIs and no local URI. Those live checks predate the review revision. The latest regression run covers the changed paths using the embedded MVC and HTTP transport fixture.Reproduce with the committed fixture
EnableClientRegisterUriTest.Fixture.mainstarts a normal application with the actual singleton publisher and HTTP repository; the test-only publisher replacement is installed only by JUnit setup. Start an isolated Admin and bootstrap using the normal project launch instructions and matching websocket URL/token/namespace. After installing this client reactor (test execution can be skipped for this preparation), build the starter's test classpath:Use the isolated Admin's credentials/ports. On Windows the Java classpath separator is
;. DirectGET http://127.0.0.1:18080/api/helloand bootstrapGET /client/api/helloshould both returnhello. Repeating with--shenyu.discovery.type=nacosand a fresh app/context identity should preserve metadata and leave the local upstream absent.Make sure that:
AGENTS.md(no magic numbers, focused methods, reuse of existing utilities)../mvnw clean install -Dmaven.javadoc.skip=true.