Skip to content

feat(api): get instance overview statistics #3021

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Apr 18, 2025
Merged

feat(api): get instance overview statistics #3021

merged 3 commits into from
Apr 18, 2025

Conversation

winfredLIN
Copy link
Collaborator

@winfredLIN winfredLIN commented Apr 17, 2025

User description

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2321

描述你的变更

  1. 增加获取数据源全局资源概览需要的统计信息接口,以供DMS调用(前端不使用)

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 新增GET /statistic/instances/resource_overview_statistics接口

  • 添加实例概览统计请求和响应结构体

  • 增加社区版不支持统计的桩函数

  • 更新API文档及Swagger配置文件


Changes walkthrough 📝

Relevant files
Enhancement
app.go
新增接口路由调用                                                                                                 

sqle/api/app.go

  • 添加新统计接口路由
+1/-0     
statistic.go
新增统计接口实现                                                                                                 

sqle/api/controller/v1/statistic.go

  • 添加实例概览统计请求、响应结构体
  • 定义InstanceOverviewStatistics数据结构
  • 新增GetInstanceOverviewStatistics接口函数
  • +29/-0   
    statistic_ce.go
    新增统计接口桩函数                                                                                               

    sqle/api/controller/v1/statistic_ce.go

    • 添加getInstanceOverviewStatistics桩函数
    • 返回社区版不支持统计功能的错误提示
    +4/-0     
    Documentation
    docs.go
    更新文档添加新接口定义                                                                                           

    sqle/docs/docs.go

    • 添加新接口文档描述
    • 增加v1.GetInstanceOverviewStatisticsRes及相关定义
    +70/-0   
    swagger.json
    更新swagger.json添加新接口                                                                           

    sqle/docs/swagger.json

    • 添加新接口swagger描述
    • 定义实例概览统计响应格式
    +70/-0   
    swagger.yaml
    更新swagger.yaml添加新接口                                                                           

    sqle/docs/swagger.yaml

    • 添加新接口swagger条目
    • 更新实例概览统计相关定义
    +46/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • - Add new API endpoint for getting instance overview statistics
    - Implement GetInstanceOverviewStatistics function in statistic controller
    - Update router to include new endpoint
    - Add placeholder implementation for community edition
    - Add new API endpoint: GET /v1/statistic/instances/resource_overview_statistics
    - This endpoint provides statistics on instance average score, high priority SQL count, and pending workflow count
    - Update API documentation in docs.go, swagger.json, and swagger.yaml
    @actiontech-bot actiontech-bot requested a review from iwanghc April 17, 2025 07:44
    Copy link

    github-actions bot commented Apr 17, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit 831c075)

    🎫 Ticket compliance analysis 🔶

    2321 - Partially compliant

    Compliant requirements:

    • 新增实例全局资源概览统计接口供DMS调用
    • 添加统计请求及响应结构体
    • 对社区版返回错误信息处理
    • 更新API文档及Swagger配置

    Non-compliant requirements:

    None

    Requires further human verification:

    None

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    缺少权限控制

    在新增的 GET /statistic/instances/resource_overview_statistics 路由中没有使用与其他接口一致的权限中间件,如 sqleMiddleware.ViewGlobalAllowed()。建议确认该接口的访问权限需求,并根据实际需求添加相应的权限控制。

    v1Router.GET("/statistic/instances/resource_overview_statistics", v1.GetInstanceOverviewStatistics)

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    添加鉴权中间件

    建议为新添加的接口路由增加鉴权中间件,以确保接口调用时进行安全验证,防止未授权访问导致安全漏洞。

    sqle/api/app.go [155]

    -v1Router.GET("/statistic/instances/resource_overview_statistics", v1.GetInstanceOverviewStatistics)
    +v1Router.GET("/statistic/instances/resource_overview_statistics", v1.GetInstanceOverviewStatistics, sqleMiddleware.ViewGlobalAllowed())
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion addresses a security concern by adding a middleware for authorization on the new endpoint, aligning it with the other endpoints in the file. The improvement is both relevant and accurate, though its impact is moderate since it may depend on the intended accessibility of the endpoint.

    Medium

    - Add jdk/ directory to .gitignore file
    - This change helps to prevent JDK-related files from being tracked by git
    Copy link

    Persistent review updated to latest commit 831c075

    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @iwanghc iwanghc merged commit abf3f0c into main Apr 18, 2025
    4 checks passed
    # for free to join this conversation on GitHub. Already have an account? # to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants