-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat: add intelligent configuration detection feature #5582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,15 @@ | |
| </dependency> | ||
| <!-- end of test --> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-webflux</artifactId> | ||
| </dependency> | ||
|
Comment on lines
+140
to
+143
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check web stack dependencies in portal module =="
rg -n -C2 '<artifactId>spring-boot-starter-web</artifactId>|<artifactId>spring-boot-starter-webflux</artifactId>|<artifactId>spring-webflux</artifactId>' apollo-portal/pom.xml
echo
echo "== Verify blocking servlet SSE pattern in controller =="
rg -n -C3 'class ItemDetectionController|HttpServletResponse|blockLast\(' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemDetectionController.java
echo
echo "== Verify reactive service contract =="
rg -n -C3 'Flux<.*>\s+detectStream|streamChat\(' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection/ConfigDetectionService.javaRepository: apolloconfig/apollo Length of output: 2115 WebFlux starter is mismatched with the current blocking servlet SSE flow. At Line 142, adding Two options: (1) if only client-side reactive APIs are needed, replace with Suggested POM adjustment (if only client-side reactive APIs are needed)- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-webflux</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webflux</artifactId>
+ </dependency>🤖 Prompt for AI Agents |
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
| <build> | ||
| <!-- openapi-generator configuration --> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright 2026 Apollo Authors | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||
| package com.ctrip.framework.apollo.portal.controller; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import com.ctrip.framework.apollo.portal.service.config.detection.ConfigDetectionService; | ||||||||||||||||||||||||||||||||||||||||||||||
| import com.ctrip.framework.apollo.portal.service.config.detection.model.DetectionRequest; | ||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.servlet.http.HttpServletResponse; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.*; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.PrintWriter; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||
| * Item detection controller for intelligent configuration detection | ||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||
| @RestController | ||||||||||||||||||||||||||||||||||||||||||||||
| @RequestMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}") | ||||||||||||||||||||||||||||||||||||||||||||||
| public class ItemDetectionController { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private final ConfigDetectionService configDetectionService; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public ItemDetectionController(ConfigDetectionService configDetectionService) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.configDetectionService = configDetectionService; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @GetMapping(value = "/items/intelligent-detection") | ||||||||||||||||||||||||||||||||||||||||||||||
| public void detectConfigStream( | ||||||||||||||||||||||||||||||||||||||||||||||
| @PathVariable String appId, | ||||||||||||||||||||||||||||||||||||||||||||||
| @PathVariable String env, | ||||||||||||||||||||||||||||||||||||||||||||||
| @PathVariable String clusterName, | ||||||||||||||||||||||||||||||||||||||||||||||
| @PathVariable String namespaceName, | ||||||||||||||||||||||||||||||||||||||||||||||
| @RequestParam String key, | ||||||||||||||||||||||||||||||||||||||||||||||
| @RequestParam String value, | ||||||||||||||||||||||||||||||||||||||||||||||
| @RequestParam(required = false) String comment, | ||||||||||||||||||||||||||||||||||||||||||||||
| HttpServletResponse response) throws IOException { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the detection payload out of the URL. Lines 47-49 accept 🤖 Prompt for AI AgentsProtect this endpoint with namespace modify permission. This route can send arbitrary config content to an external provider, but unlike the sibling item mutation endpoints it has no Suggested fix+ `@PreAuthorize`(
+ value = "@unifiedPermissionValidator.hasModifyNamespacePermission(`#appId`, `#env`, `#clusterName`, `#namespaceName`)")
`@GetMapping`(value = "/items/intelligent-detection")
public void detectConfigStream(Also add this import near the top of the file: import org.springframework.security.access.prepost.PreAuthorize;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| response.setContentType("text/event-stream;charset=UTF-8"); | ||||||||||||||||||||||||||||||||||||||||||||||
| response.setCharacterEncoding("UTF-8"); | ||||||||||||||||||||||||||||||||||||||||||||||
| response.setHeader("Cache-Control", "no-cache"); | ||||||||||||||||||||||||||||||||||||||||||||||
| response.setHeader("Connection", "keep-alive"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| PrintWriter writer = response.getWriter(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| DetectionRequest request = DetectionRequest.builder() | ||||||||||||||||||||||||||||||||||||||||||||||
| .appId(appId) | ||||||||||||||||||||||||||||||||||||||||||||||
| .env(env) | ||||||||||||||||||||||||||||||||||||||||||||||
| .clusterName(clusterName) | ||||||||||||||||||||||||||||||||||||||||||||||
| .namespaceName(namespaceName) | ||||||||||||||||||||||||||||||||||||||||||||||
| .key(key) | ||||||||||||||||||||||||||||||||||||||||||||||
| .value(value) | ||||||||||||||||||||||||||||||||||||||||||||||
| .comment(comment) | ||||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| configDetectionService.detectStream(request) | ||||||||||||||||||||||||||||||||||||||||||||||
| .doOnNext(chunk -> { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| String[] lines = chunk.split("\n", -1); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("event: message\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| for (String line : lines) { | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("data: " + line + "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.flush(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| .doOnComplete(() -> { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("event: done\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("data: [DONE]\n\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.flush(); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.close(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| .doOnError(e -> { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("event: error\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.write("data: check error:" + e.getMessage() + "\n\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.flush(); | ||||||||||||||||||||||||||||||||||||||||||||||
| writer.close(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception ex) { | ||||||||||||||||||||||||||||||||||||||||||||||
| ex.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| .blockLast(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "ItemDetectionController.java" -type fRepository: apolloconfig/apollo Length of output: 166 🏁 Script executed: cat -n apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemDetectionController.java | head -120Repository: apolloconfig/apollo Length of output: 4739 🏁 Script executed: find apollo-portal -name "*ManagementApi*" -type f | head -20Repository: apolloconfig/apollo Length of output: 45 🏁 Script executed: rg -A 50 "blockLast" apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemDetectionController.javaRepository: apolloconfig/apollo Length of output: 100 🏁 Script executed: find apollo-portal -name "*.openapi.*" -o -name "*openapi*" -type f | head -20Repository: apolloconfig/apollo Length of output: 45 🏁 Script executed: find apollo-portal -path "*generated*" -name "*Api.java" -type f | head -20Repository: apolloconfig/apollo Length of output: 45 🏁 Script executed: rg -l "text/event-stream" apollo-portal/src/main/java --type javaRepository: apolloconfig/apollo Length of output: 164 🏁 Script executed: rg -l "blockLast|subscribe|doOnError" apollo-portal/src/main/java --type java | head -10Repository: apolloconfig/apollo Length of output: 403 🏁 Script executed: cat -n apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection/ConfigDetectionService.javaRepository: apolloconfig/apollo Length of output: 4058 🏁 Script executed: cat -n apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection/adapter/OpenAICompatibleAdapter.java | head -150Repository: apolloconfig/apollo Length of output: 7801 Replace Lines 69–103: Using Use |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2026 Apollo Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
| package com.ctrip.framework.apollo.portal.service.config.detection; | ||
|
|
||
|
|
||
| import com.ctrip.framework.apollo.portal.service.config.detection.adapter.DetectionModelAdapter; | ||
| import com.ctrip.framework.apollo.portal.service.config.detection.adapter.DetectionModelAdapterFactory; | ||
| import com.ctrip.framework.apollo.portal.service.config.detection.config.DetectionProperties; | ||
| import com.ctrip.framework.apollo.portal.service.config.detection.model.ChatMessage; | ||
| import com.ctrip.framework.apollo.portal.service.config.detection.model.ChatRequest; | ||
| import com.ctrip.framework.apollo.portal.service.config.detection.model.DetectionRequest; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.stereotype.Service; | ||
| import reactor.core.publisher.Flux; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Configuration detection service | ||
| */ | ||
| @Service | ||
| public class ConfigDetectionService { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ConfigDetectionService.class); | ||
|
|
||
| private final DetectionProperties properties; | ||
| private final DetectionModelAdapterFactory adapterFactory; | ||
| private final PromptBuilder promptBuilder; | ||
|
|
||
| public ConfigDetectionService( | ||
| DetectionProperties properties, | ||
| DetectionModelAdapterFactory adapterFactory, | ||
| PromptBuilder promptBuilder) { | ||
| this.properties = properties; | ||
| this.adapterFactory = adapterFactory; | ||
| this.promptBuilder = promptBuilder; | ||
| } | ||
|
|
||
| public Flux<String> detectStream(DetectionRequest request) { | ||
| if (!properties.isEnabled()) { | ||
| return Flux.error(new IllegalStateException("Detection is not enabled")); | ||
| } | ||
| try { | ||
| String provider = properties.getActiveProvider(); | ||
| logger.info("Starting detection for key: {}, provider: {}", request.getKey(), provider); | ||
| DetectionModelAdapter adapter = adapterFactory.getAdapter(provider); | ||
| String systemPrompt = promptBuilder.getSystemPrompt(); | ||
| String userPrompt = promptBuilder.buildDetectionPrompt(request); | ||
|
|
||
| ChatRequest chatRequest = ChatRequest.builder() | ||
| .messages(Arrays.asList( | ||
| new ChatMessage("system", systemPrompt), | ||
| new ChatMessage("user", userPrompt) | ||
| )) | ||
| .stream(true) | ||
| .build(); | ||
|
|
||
| return adapter.streamChat(chatRequest) | ||
| .doOnComplete(() -> logger.info("Detection completed for key: {}", request.getKey())) | ||
| .doOnError(error -> logger.error("Detection failed for key: {}", request.getKey(), error)); | ||
|
Comment on lines
+74
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
fd 'ConfigDetectionService\.java$' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection -x sed -n '55,120p' {}
fd 'DetectionModelAdapterFactory\.java$' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection/adapter -x sed -n '48,90p' {}
fd 'OpenAICompatibleAdapter\.java$' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detection/adapter -x sed -n '45,170p' {}
rg -n '\.timeout\s*\(' apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/config/detectionRepository: apolloconfig/apollo Length of output: 8009 Enforce the configured timeout on the returned stream. Line 74 exposes the model Suggested fix return adapter.streamChat(chatRequest)
+ .timeout(Duration.ofMillis(properties.getTimeout()))
.doOnComplete(() -> logger.info("Detection completed for key: {}", request.getKey()))
.doOnError(error -> logger.error("Detection failed for key: {}", request.getKey(), error));Also add this import near the top of the file: import java.time.Duration;🤖 Prompt for AI Agents |
||
|
|
||
| } catch (Exception e) { | ||
| logger.error("Failed to start detection", e); | ||
| return Flux.error(e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the empty bullet item.
This leaves a dangling list marker in release notes and should be deleted.
Proposed fix
-*📝 Committable suggestion
🤖 Prompt for AI Agents