Skip to content
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

添加快速查询资源 #11

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

shinny-taojiachun
Copy link
Collaborator

@shinny-taojiachun shinny-taojiachun commented Jul 8, 2024

背景

cdk项目需要添加快速查询,但是官方terraform插件里并未提供相关资源

方案

依靠sdk已有的快速查询相关接口,参照logdashboard的相关代码结构新增快速查询资源

Summary by CodeRabbit

  • 新功能

    • 添加了 alicloud_log_saved_search 资源,用于管理阿里云日志服务中的已保存搜索功能。
  • 文档

    • 在网站文档中添加了有关 alicloud_log_saved_search 资源的使用指南,包括创建和使用已保存搜索进行查询和分析操作的说明。

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

Walkthrough

新增了一个名为 alicloud_log_saved_search 的资源,以便在阿里云日志服务 (SLS) 中管理保存的搜索功能。此功能包括创建、读取、更新和删除保存的搜索操作,并已更新相关文档以反映这些更改。

Changes

文件路径 变更摘要
alicloud/provider.go 新增了 alicloud_log_saved_search 资源至 Provider() 函数。
alicloud/resource_alicloud_log_saved_search.go 提供了创建、读取、更新和删除阿里云日志服务中的保存搜索的功能。
alicloud/service_alicloud_log.go 新增了 DescribeSavedSearchWaitForSavedSearch 方法,用于检索和监控保存搜索的状态。
...log_saved_search.html.markdown 文档新增了 alicloud_log_saved_search 资源的使用说明。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Provider
    participant LogService

    User ->> Provider: 提交创建/更新保存搜索请求
    Provider ->> LogService: 调用DescribeSavedSearch方法
    LogService -->> Provider: 返回保存搜索详情
    Provider ->> LogService: 调用WaitForSavedSearch方法
    LogService -->> Provider: 返回搜索状态
    Provider -->> User: 返回操作结果
Loading

Poem

🐰代码小兔子,功能新升级,
日志搜索快,管理更便捷。
文档同步改,用户妙体验,
阿里云服务,未来更可期。


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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 github-actions bot added the size/l label Jul 8, 2024
@shinny-taojiachun shinny-taojiachun force-pushed the add-logstore-savedsearch branch from 8df0321 to e75c11c Compare July 8, 2024 06:34
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1821728 and e75c11c.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Additional comments not posted (8)
alicloud/resource_alicloud_log_savedsearch.go (5)

14-54: 资源 schema 定义和 CRUD 操作绑定

资源 alicloud_log_saved_search 的 schema 定义和 CRUD 操作绑定看起来很好。所有必要的字段都已包含,并且类型和约束也合适。


56-97: 创建资源函数

resourceAlicloudLogSavedSearchCreate 函数处理保存搜索资源的创建。函数使用 SDK 创建保存搜索,并包含针对临时错误的重试逻辑。错误处理和日志记录都很到位。

请确保 WaitForSavedSearch 函数的使用是正确的。


99-123: 读取资源函数

resourceAlicloudLogSavedSearchRead 函数处理保存搜索资源的读取。函数使用 SDK 检索保存搜索并设置资源数据字段。错误处理和字段设置都很到位。

请确保错误处理是正确的。


125-161: 更新资源函数

resourceAlicloudLogSavedSearchUpdate 函数处理保存搜索资源的更新。函数检查相关字段的更改,并使用 SDK 更新保存搜索。错误处理和更改检测逻辑都很到位。

请确保更改检测逻辑是正确的。


163-195: 删除资源函数

resourceAlicloudLogSavedSearchDelete 函数处理保存搜索资源的删除。函数使用 SDK 删除保存搜索,并包含针对临时错误的重试逻辑。错误处理和日志记录都很到位。

请确保 WaitForSavedSearch 函数的使用是正确的。

alicloud/service_alicloud_log.go (2)

556-596: 描述保存搜索函数

DescribeSavedSearch 函数使用 SDK 检索保存搜索,并包含针对临时错误的重试逻辑。错误处理和日志记录都很到位。

请确保错误处理是正确的。


598-621: 等待保存搜索函数

WaitForSavedSearch 函数等待保存搜索在给定超时时间内达到指定状态。错误处理和日志记录都很到位。

请确保超时逻辑是正确的。

alicloud/provider.go (1)

995-995: 新增资源 alicloud_log_saved_search

已成功添加新资源 alicloud_log_saved_search,符合现有的资源映射结构。

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1821728 and e75c11c.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • alicloud/provider.go
Additional comments not posted (7)
alicloud/resource_alicloud_log_savedsearch.go (5)

14-54: 定义资源架构和CRUD操作

资源架构和CRUD操作定义看起来是正确的。


99-123: 读取资源数据

读取资源数据的实现看起来是正确的,包括错误处理。


125-161: 更新资源数据

更新资源数据的实现看起来是正确的,检查特定字段的变化并相应地更新资源。


163-195: 删除资源时验证 WaitForSavedSearch 的使用

删除资源的实现看起来是正确的,包括错误处理和重试机制。

但是,请确保 WaitForSavedSearch 的使用是正确的。

Verification successful

删除资源时验证 WaitForSavedSearch 的使用

删除资源的实现看起来是正确的,包括错误处理和重试机制。WaitForSavedSearch 函数的实现也符合预期。

  • WaitForSavedSearch 函数的实现位于 alicloud/service_alicloud_log.go 文件的第 598 行。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of WaitForSavedSearch function.

# Test: Search for the function implementation. Expect: Correct implementation of WaitForSavedSearch.
rg --type go $'func (s *LogService) WaitForSavedSearch'

Length of output: 56


Script:

#!/bin/bash
# Description: Verify the implementation of WaitForSavedSearch function or similar functions.

# Test: Search for all functions in LogService. Expect: To find WaitForSavedSearch or similar functions.
rg --type go --pcre2 'func \(s \*LogService\) \w+'

Length of output: 4551


Script:

#!/bin/bash
# Description: Retrieve the implementation details of WaitForSavedSearch function.

# Test: Get the implementation of the WaitForSavedSearch function in LogService.
ast-grep --lang go --pattern $'func (s *LogService) WaitForSavedSearch($_, $_, $_) error { $$$ }'

Length of output: 1694


56-97: 创建资源时验证 WaitForSavedSearch 的使用

创建资源的实现看起来是正确的,包括错误处理和重试机制。

但是,请确保 WaitForSavedSearch 的使用是正确的。

alicloud/service_alicloud_log.go (2)

556-596: 检索保存的搜索

检索保存的搜索的实现看起来是正确的,包括错误处理和重试机制。


598-621: 等待保存的搜索达到指定状态

等待保存的搜索达到指定状态的实现看起来是正确的,包括错误处理和循环检查状态直到超时。

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1821728 and e75c11c.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • alicloud/provider.go
Additional comments not posted (3)
alicloud/resource_alicloud_log_savedsearch.go (3)

14-54: 定义资源 schema 成功

资源 schema 定义良好,包含必要的和可选的字段。资源具有创建、读取、更新、删除操作。


99-123: 读取资源操作成功

函数结构良好,适当处理了错误情况。


126-161: 更新资源操作成功

函数正确检查更改并更新资源,同时适当处理错误。

alicloud/resource_alicloud_log_savedsearch.go Outdated Show resolved Hide resolved
alicloud/resource_alicloud_log_savedsearch.go Outdated Show resolved Hide resolved
alicloud/service_alicloud_log.go Outdated Show resolved Hide resolved
alicloud/service_alicloud_log.go Outdated Show resolved Hide resolved
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1821728 and e75c11c.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Additional comments not posted (8)
alicloud/resource_alicloud_log_savedsearch.go (5)

14-54: 资源定义实现正确

resourceAlicloudLogSavedSearch 函数定义了 alicloud_log_saved_search 资源的 schema 和 CRUD 操作,字段和属性配置正确。


56-97: 创建资源函数实现正确

resourceAlicloudLogSavedSearchCreate 函数处理 alicloud_log_saved_search 资源的创建操作,包含重试逻辑和错误处理,逻辑实现正确。


99-123: 读取资源函数实现正确

resourceAlicloudLogSavedSearchRead 函数处理 alicloud_log_saved_search 资源的读取操作,检索已保存的搜索并正确设置 schema 字段。


126-161: 更新资源函数实现正确

resourceAlicloudLogSavedSearchUpdate 函数处理 alicloud_log_saved_search 资源的更新操作,检查特定字段的更改并相应地更新已保存的搜索。


163-195: 删除资源函数实现正确

resourceAlicloudLogSavedSearchDelete 函数处理 alicloud_log_saved_search 资源的删除操作,包含重试逻辑和错误处理,逻辑实现正确。

alicloud/service_alicloud_log.go (2)

556-596: 描述已保存搜索函数实现正确

DescribeSavedSearch 函数通过 ID 检索已保存的搜索,包含重试逻辑和错误处理,逻辑实现正确。


598-621: 等待已保存搜索函数实现正确

WaitForSavedSearch 函数在超时时间内等待已保存的搜索达到指定状态,包含重试逻辑和错误处理,逻辑实现正确。

alicloud/provider.go (1)

995-995: 新增资源 alicloud_log_saved_search 看起来不错!

该资源已正确添加到 ResourcesMap 中。

@shinny-taojiachun shinny-taojiachun force-pushed the add-logstore-savedsearch branch from e75c11c to 7aa2f3c Compare July 8, 2024 07:20
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e75c11c and 7aa2f3c.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • alicloud/provider.go
  • alicloud/resource_alicloud_log_savedsearch.go
Additional comments not posted (2)
alicloud/service_alicloud_log.go (2)

556-596: 建议添加日志记录

函数实现了全面的检索操作,包括重试和错误处理。但缺少日志记录,建议添加日志以便更好地追踪。

// 在检索操作中添加日志记录
log.Printf("[INFO] Describing Alicloud Log Saved Search: %s", id)

598-621: 建议添加日志记录

函数实现了全面的等待操作,包括超时和错误处理。但缺少日志记录,建议添加日志以便更好地追踪。

// 在等待操作中添加日志记录
log.Printf("[INFO] Waiting for Alicloud Log Saved Search: %s to reach status: %s", id, status)

@shinny-taojiachun shinny-taojiachun force-pushed the add-logstore-savedsearch branch from 7aa2f3c to 074631f Compare July 9, 2024 03:32
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7aa2f3c and 074631f.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • alicloud/provider.go
  • alicloud/resource_alicloud_log_savedsearch.go
  • alicloud/service_alicloud_log.go

@shinny-taojiachun shinny-taojiachun force-pushed the add-logstore-savedsearch branch from 074631f to 4ceae76 Compare July 9, 2024 05:48
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 074631f and 4ceae76.

Files selected for processing (3)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_savedsearch.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • alicloud/provider.go
  • alicloud/resource_alicloud_log_savedsearch.go
  • alicloud/service_alicloud_log.go

@shinny-taojiachun shinny-taojiachun force-pushed the add-logstore-savedsearch branch from 4ceae76 to fb37e9c Compare July 9, 2024 06:44
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ceae76 and fb37e9c.

Files selected for processing (4)
  • alicloud/provider.go (1 hunks)
  • alicloud/resource_alicloud_log_saved_search.go (1 hunks)
  • alicloud/service_alicloud_log.go (1 hunks)
  • website/docs/r/log_saved_search.html.markdown (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • alicloud/provider.go
  • alicloud/service_alicloud_log.go
Additional comments not posted (9)
website/docs/r/log_saved_search.html.markdown (4)

1-8: 元数据字段正确

文档头部的元数据字段设置正确。


10-15: 描述准确

描述部分准确地介绍了 alicloud_log_saved_search 资源的功能。


16-37: 示例用法正确

示例用法部分提供了一个完整的 Terraform 配置,展示了如何使用 alicloud_log_saved_search 资源。


40-55: 参数和属性描述正确

参数参考和属性参考部分准确且完整地描述了 alicloud_log_saved_search 资源的参数和导出的属性。

alicloud/resource_alicloud_log_saved_search.go (5)

1-51: 资源定义正确

resourceAlicloudLogSavedSearch 函数正确定义了 alicloud_log_saved_search 资源的 schema 和 CRUD 操作绑定。


53-93: 创建逻辑正确

resourceAlicloudLogSavedSearchCreate 函数正确地处理了保存搜索资源的创建逻辑,包括错误处理和重试逻辑。


95-119: 读取逻辑正确

resourceAlicloudLogSavedSearchRead 函数正确地处理了保存搜索资源的读取逻辑,包括错误处理和状态设置。


121-160: 更新逻辑正确

resourceAlicloudLogSavedSearchUpdate 函数正确地处理了保存搜索资源的更新逻辑,包括变更检测和更新执行。


162-194: 删除逻辑正确

resourceAlicloudLogSavedSearchDelete 函数正确地处理了保存搜索资源的删除逻辑,包括错误处理和重试逻辑。

@shinny-taojiachun shinny-taojiachun merged commit 59772fe into master Jul 15, 2024
14 checks passed
@shinny-taojiachun shinny-taojiachun deleted the add-logstore-savedsearch branch July 15, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants