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

Update license headers / Format codes #2723

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

vdaas-ci
Copy link
Collaborator

@vdaas-ci vdaas-ci commented Oct 26, 2024

Update license headers / Format Go codes and YAML files.

Summary by CodeRabbit

  • New Features

    • Introduced a structured approach for managing deletion operations with enhanced error handling and tracing.
    • Added functional options for configuring the deletion service, improving flexibility in service setup.
  • Bug Fixes

    • Standardized formatting and quotation marks in the GitHub Actions workflow to ensure consistency.
  • Documentation

    • Enhanced clarity on the configuration options available for the deletion service.

Copy link

cloudflare-workers-and-pages bot commented Oct 26, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: a30c357
Status: ✅  Deploy successful!
Preview URL: https://28177ec0.vald.pages.dev
Branch Preview URL: https://formatter-go-and-yaml-format-y9zi.vald.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Oct 26, 2024

📝 Walkthrough

Walkthrough

This pull request introduces several changes, primarily focusing on the addition of new functionality for deletion operations within the service layer. It includes the creation of two new files: deleter.go, which defines a Deleter interface and its implementation, and options.go, which provides functional options for configuring the index. Additionally, minor formatting adjustments were made to the GitHub Actions workflow file to standardize quotation marks.

Changes

File Path Change Summary
.github/workflows/dockers-index-deletion-image.yaml Reformatted to standardize quotation marks and adjust the structure of the on section.
pkg/index/job/deletion/service/deleter.go Introduced Deleter interface and its implementation, including methods for starting clients and deletion processes.
pkg/index/job/deletion/service/options.go Added functional options for configuring an index, including options for discoverers, concurrency, target addresses, and index ID.

Possibly related PRs

Suggested labels

priority/low, size/S, type/ci, area/makefile

Suggested reviewers

  • kpango

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

Copy link
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: 0

🧹 Outside diff range and nitpick comments (6)
pkg/index/job/deletion/service/options.go (4)

Line range hint 22-31: Consider enhancing error message for nil discoverer

While the nil check is good, the error message could be more descriptive to help with troubleshooting.

Consider updating the error message:

 func WithDiscoverer(client discoverer.Client) Option {
 	return func(idx *index) error {
 		if client == nil {
-			return errors.NewErrCriticalOption("discoverer", client)
+			return errors.NewErrCriticalOption("discoverer client cannot be nil", client)
 		}
 		idx.client = client
 		return nil
 	}
 }

Line range hint 33-42: Consider adding upper bound for concurrency

While the function correctly validates the lower bound, consider adding an upper bound to prevent potential resource exhaustion.

Consider updating the validation:

 func WithIndexingConcurrency(num int) Option {
 	return func(idx *index) error {
-		if num <= 0 {
+		const maxConcurrency = 1000 // adjust based on your system's capacity
+		if num <= 0 || num > maxConcurrency {
 			return errors.NewErrInvalidOption("indexingConcurrency", num)
 		}
 		idx.concurrency = num
 		return nil
 	}
 }

Line range hint 44-52: Add validation for target addresses

The function should validate each address to ensure they are well-formed and non-empty.

Consider adding validation:

 func WithTargetAddrs(addrs ...string) Option {
 	return func(idx *index) error {
 		if len(addrs) != 0 {
+			for _, addr := range addrs {
+				if addr == "" {
+					return errors.NewErrInvalidOption("target address cannot be empty", addr)
+				}
+				// Add additional address format validation if needed
+			}
 			idx.targetAddrs = append(idx.targetAddrs, addrs...)
 		}
 		return nil
 	}
 }

Line range hint 54-60: Add validation for target index ID

The function should validate that the indexID is non-empty and meets any format requirements.

Consider adding validation:

 func WithTargetIndexID(indexID string) Option {
 	return func(idx *index) error {
+		if indexID == "" {
+			return errors.NewErrInvalidOption("target index ID cannot be empty", indexID)
+		}
 		idx.targetIndexID = indexID
 		return nil
 	}
 }
pkg/index/job/deletion/service/deleter.go (2)

Line range hint 52-53: Fix improper usage of errors.As function

In the New function, the usage of errors.As(oerr, &e) is incorrect because e is already a pointer to errors.ErrCriticalOption. Passing &e results in a double pointer **errors.ErrCriticalOption, which doesn't match the expected type. The correct usage is to pass e directly without the address operator.

Apply this diff to fix the issue:

 e := &errors.ErrCriticalOption{}
-if errors.As(oerr, &e) {
+if errors.As(oerr, e) {

Line range hint 114-212: Consider logging when no target addresses are found

In the doDeleteIndex method, if targetAddrs is empty, the function proceeds without logging or returning an error. This could lead to silent failures. Consider adding a check for empty targetAddrs and logging a warning or returning an error.

Apply this diff to add a check for empty targetAddrs:

 func (idx *index) doDeleteIndex(
 	ctx context.Context,
 	fn func(_ context.Context, _ vald.RemoveClient, _ ...grpc.CallOption) (*payload.Object_Location, error),
 ) (errs error) {
 	ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, grpcMethodName), apiName+"/service/index.doDeleteIndex")
 	defer func() {
 		if span != nil {
 			span.End()
 		}
 	}()

+	if len(targetAddrs) == 0 {
+		log.Warn("No target addresses found")
+		return errors.New("no target addresses found")
+	}
+
 	var emu sync.Mutex
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8fa3b7f and a30c357.

📒 Files selected for processing (3)
  • .github/workflows/dockers-index-deletion-image.yaml (1 hunks)
  • pkg/index/job/deletion/service/deleter.go (1 hunks)
  • pkg/index/job/deletion/service/options.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/dockers-index-deletion-image.yaml
🔇 Additional comments (4)
pkg/index/job/deletion/service/options.go (1)

1-13: LGTM: License header is properly updated

The Apache 2.0 license header is correctly formatted and includes the updated copyright year range (2019-2024).

pkg/index/job/deletion/service/deleter.go (3)

Line range hint 76-78: LGTM

The StartClient method correctly starts the gRPC client by calling idx.client.Start(ctx).


Line range hint 80-112: LGTM

The Start method appropriately initiates the deletion process with comprehensive error handling and tracing.


Line range hint 63-73: LGTM

The delDuplicateAddrs function efficiently removes duplicate addresses using a map to track existing entries.

@vdaas-ci
Copy link
Collaborator Author

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link

codecov bot commented Oct 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 23.95%. Comparing base (8fa3b7f) to head (a30c357).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2723      +/-   ##
==========================================
- Coverage   23.95%   23.95%   -0.01%     
==========================================
  Files         545      545              
  Lines       54324    54324              
==========================================
- Hits        13013    13011       -2     
- Misses      40535    40537       +2     
  Partials      776      776              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kpango kpango merged commit 46d05fc into main Oct 27, 2024
47 of 54 checks passed
@kpango kpango deleted the formatter/go_and_yaml/format_at_20241026_155747_597 branch October 27, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants