Skip to content

[issue-87][apollo-java]: Added a new feature to get instance count by namespace.#5381

Merged
nobodyiam merged 2 commits intoapolloconfig:masterfrom
yuhaowin:feature/issue-87
Apr 25, 2025
Merged

[issue-87][apollo-java]: Added a new feature to get instance count by namespace.#5381
nobodyiam merged 2 commits intoapolloconfig:masterfrom
yuhaowin:feature/issue-87

Conversation

@yuhaowin
Copy link
Copy Markdown
Contributor

@yuhaowin yuhaowin commented Apr 24, 2025

What's the purpose of this PR

Get instance count by namespaces

Which issue(s) this PR fixes:

For #87

Brief changelog

Added a new feature to get instance count by namespace.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • New Features
    • Added a new REST API endpoint to retrieve the count of instances for a specific namespace, accessible via the OpenAPI.
    • Users can now query instance counts by specifying application ID, environment, cluster name, and namespace name.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 24, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 24, 2025

Walkthrough

A new REST API endpoint has been introduced to provide the count of instances for a specific namespace within an application, cluster, and environment. This is achieved by adding a new controller class that exposes the endpoint and a corresponding service class that implements the required business logic. The controller receives HTTP GET requests, extracts the necessary parameters from the URL, and delegates the processing to the service, which interacts with the internal instance service to retrieve the instance count.

Changes

File(s) Change Summary
.../openapi/server/service/ServerInstanceOpenApiService.java Added a new service class implementing InstanceOpenApiService with a method to get instance count by namespace.
.../openapi/v1/controller/InstanceController.java Added a new REST controller exposing a GET endpoint to retrieve the instance count for a namespace.
CHANGES.md Added release note entry documenting the new feature to get instance count by namespace.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant InstanceController
    participant ServerInstanceOpenApiService
    participant InstanceService

    Client->>InstanceController: GET /openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/instances
    InstanceController->>ServerInstanceOpenApiService: getInstanceCountByNamespace(appId, env, clusterName, namespaceName)
    ServerInstanceOpenApiService->>InstanceService: getInstanceCountByNamespace(appId, Env.valueOf(env), clusterName, namespaceName)
    InstanceService-->>ServerInstanceOpenApiService: instance count
    ServerInstanceOpenApiService-->>InstanceController: instance count
    InstanceController-->>Client: instance count
Loading

Suggested labels

size:S, lgtm

Poem

🐇 Hopping through code with nimble feet,
Counting instances, a task so neat.
A new API to call and see,
How many bunnies live in the tree.
With clusters, namespaces all in line,
The count returns, quick and fine!
🌿✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 722b42d and f7c5e9c.

📒 Files selected for processing (1)
  • CHANGES.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGES.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 24, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java (1)

31-35: Endpoint implementation looks correct

The GET endpoint follows REST conventions and has appropriate path variables. The method signature matches the HTTP request structure and properly delegates to the service.

Consider adding API documentation using Swagger annotations to improve API discoverability:

+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;

 @RestController("openapiInstanceController")
 @RequestMapping("/openapi/v1/envs/{env}")
+@Api(tags = "Instance APIs")
 public class InstanceController {
     // ...
     
+    @ApiOperation("Get instance count by namespace")
     @GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/instances")
     public int getInstanceCountByNamespace(
+        @ApiParam("Application ID") 
         @PathVariable String appId, 
+        @ApiParam("Environment") 
         @PathVariable String env,
+        @ApiParam("Cluster name") 
         @PathVariable String clusterName, 
+        @ApiParam("Namespace name") 
         @PathVariable String namespaceName) {
         // ...
     }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 362735d and 722b42d.

📒 Files selected for processing (2)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java (1)
  • Env (34-237)
🪛 GitHub Actions: build
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java

[error] 19-25: Compilation error: cannot find symbol 'InstanceOpenApiService' in package 'com.ctrip.framework.apollo.openapi.api'.

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java

[error] 19-27: Compilation error: cannot find symbol 'InstanceOpenApiService' in package 'com.ctrip.framework.apollo.openapi.api'.

🔇 Additional comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java (1)

22-24: Controller name and request mapping look good

The controller uses a bean name qualifier "openapiInstanceController" which helps avoid conflicts with other instance controllers. The request mapping follows the RESTful pattern of Apollo's OpenAPI.

@yuhaowin
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@nobodyiam
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 25, 2025
@nobodyiam nobodyiam merged commit fc4c81c into apolloconfig:master Apr 25, 2025
7 of 11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2025
@nobodyiam nobodyiam added this to the 2.5.0 milestone Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants