Skip to content

Conversation

@j3ttt
Copy link
Collaborator

@j3ttt j3ttt commented Nov 17, 2025

Thank you for your contribution to CloudRec!

What About:

  • Server (java)
  • Collector (go)
  • Rule (opa)

Description:

refactor alicloud fc collector for better data structure

Summary by Sourcery

Refactor the Alicloud FC collector to simplify data structures by modeling resources as individual functions with triggers and full pagination support

Enhancements:

  • Update schema row mapping to use function IDs and names
  • Emit each function as a separate detail record with associated triggers
  • Remove custom domain fields and related logic from the collector
  • Introduce a describeTriggers function to fetch function triggers with pagination
  • Extend describeFunction to support paginated retrieval of all functions
  • Clean up the Detail struct to include only Function and Triggers fields

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 17, 2025

Reviewer's Guide

Refactored the Alicloud FC collector to improve the data structure by moving resource identifiers to row fields, emitting one record per function with its triggers, and implementing pagination for functions and triggers.

Sequence diagram for paginated function and trigger collection

sequenceDiagram
    participant Collector
    participant FCClient
    Collector->>FCClient: ListFunctionsRequest
    FCClient-->>Collector: Functions + NextToken
    loop while NextToken exists
        Collector->>FCClient: ListFunctionsRequest (with NextToken)
        FCClient-->>Collector: Functions + NextToken
    end
    loop for each Function
        Collector->>FCClient: ListTriggersRequest(FunctionName)
        FCClient-->>Collector: Triggers + NextToken
        loop while NextToken exists
            Collector->>FCClient: ListTriggersRequest(FunctionName, NextToken)
            FCClient-->>Collector: Triggers + NextToken
        end
    end
Loading

Entity relationship diagram for FC function and triggers

erDiagram
    FUNCTION ||--o{ TRIGGER : has
    FUNCTION {
        string functionId
        string functionName
    }
    TRIGGER {
        string triggerId
        string triggerName
    }
Loading

Class diagram for refactored FC collector data structures

classDiagram
    class Detail {
        +Function *fc20230330.Function
        +Triggers []*fc20230330.Trigger
    }
    fc20230330.Function <|-- Detail: contains
    fc20230330.Trigger <|-- Detail: contains multiple
Loading

Flow diagram for emitting records per function with triggers

flowchart TD
    A["Start: Collect FC Resources"] --> B["Describe Functions (paginated)"]
    B --> C["For each Function"]
    C --> D["Describe Triggers (paginated)"]
    D --> E["Emit Detail record: Function + Triggers"]
Loading

File-Level Changes

Change Details Files
Updated RowField mappings for resource identification
  • Changed ResourceId path to $.Function.functionId
  • Changed ResourceName path to $.Function.functionName
collector/alicloud/collector/fc/fc.go
Reworked GetInstanceDetail to emit per-function records
  • Removed custom domain logic
  • Iterate over each function
  • Send Detail containing Function and its triggers
collector/alicloud/collector/fc/fc.go
Modified Detail struct
  • Removed ResourceId, ResourceName, Domain fields
  • Changed Function from slice to single pointer
  • Added Triggers slice
collector/alicloud/collector/fc/fc.go
Introduced describeTriggers with pagination
  • Created describeTriggers to list triggers by function name
  • Looped through NextToken for full pagination
collector/alicloud/collector/fc/fc.go
Enhanced describeFunction to support pagination
  • Accumulate functions across multiple pages
  • Appended results to functions slice
collector/alicloud/collector/fc/fc.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @j3ttt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the Alicloud Function Compute (FC) collector to improve its data structure and collection methodology. The primary goal is to provide a more accurate and comprehensive representation of FC resources by tightly coupling triggers with their respective functions and ensuring all relevant data is retrieved through pagination. These changes streamline the data model and enhance the collector's ability to gather complete information about FC instances.

Highlights

  • Data Structure Refinement: The Detail struct has been refactored to directly embed a single Function and include a slice of Triggers, providing a more cohesive representation of Alicloud FC resources. The ResourceId and ResourceName fields within the Detail struct have been removed, as these are now derived directly from the Function object.
  • Resource ID Mapping Update: The ResourceId and ResourceName mappings in the GetFCResource function have been updated to $.Function.functionId and $.Function.functionName respectively, ensuring that resource identification is consistent with the new data structure.
  • Trigger Collection Integration: A new describeTriggers function has been introduced to fetch triggers associated with each function. The GetInstanceDetail function now iterates through collected functions and retrieves their corresponding triggers, emitting a Detail object for each function with its associated triggers.
  • Pagination for Functions and Triggers: Pagination logic has been implemented in both describeFunction and describeTriggers to ensure that all available functions and their triggers are collected, preventing data truncation in cases where the API returns results in pages.
  • Removal of Custom Domain Collection: The describeCustomDomain function and its related logic for collecting custom domain information have been removed from the collector.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • describeTriggers returns resp.Body.Triggers instead of the accumulated triggers slice, so earlier pages get discarded—return the aggregated ‘triggers’ variable instead.
  • Pagination in describeFunction only handles one extra page; wrap the NextToken logic in a loop to ensure you collect all pages.
  • In GetInstanceDetail, a single describeTriggers error will stop processing all functions; consider handling per-function errors without aborting the loop.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- describeTriggers returns resp.Body.Triggers instead of the accumulated triggers slice, so earlier pages get discarded—return the aggregated ‘triggers’ variable instead.
- Pagination in describeFunction only handles one extra page; wrap the NextToken logic in a loop to ensure you collect all pages.
- In GetInstanceDetail, a single describeTriggers error will stop processing all functions; consider handling per-function errors without aborting the loop.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Alicloud FC collector to improve the data structure, fetching functions and their associated triggers individually. This is a good structural improvement. However, I've identified critical bugs in the new pagination logic for both describeTriggers and describeFunction. The current implementation will lead to incomplete data collection if there are more results than fit on a single page (or two, in one case). My review includes suggestions to implement correct, robust pagination loops to fix these issues.

Comment on lines 89 to 109
func describeTriggers(ctx context.Context, cli *fc20230330.Client, name *string) (triggers []*fc20230330.Trigger) {
request := &fc20230330.ListTriggersRequest{}
resp, err := cli.ListTriggers(name, request)
if err != nil {
log.CtxLogger(ctx).Warn("ListCustomDomainsWithOptions error", zap.Error(err))
log.CtxLogger(ctx).Warn("ListTriggersWithOptions error", zap.Error(err))
return nil
}
triggers = append(triggers, resp.Body.Triggers...)

for resp.Body.NextToken != nil {
request.NextToken = resp.Body.NextToken
resp, err = cli.ListTriggers(name, request)
if err != nil {
log.CtxLogger(ctx).Warn("ListTriggersWithOptions error", zap.Error(err))
return nil
}
triggers = append(triggers, resp.Body.Triggers...)
}

return result.Body.CustomDomains
return resp.Body.Triggers
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The pagination logic in this function has a critical bug and can be simplified.

  1. Bug: The final return resp.Body.Triggers on line 108 will only return the triggers from the last fetched page, discarding all triggers from previous pages that were appended to the triggers slice. This will result in incomplete data.
  2. Refactoring: The code for fetching and appending triggers is duplicated before and inside the loop. This can be consolidated into a single loop structure for better readability and maintainability.

I've suggested a refactoring that fixes the bug and cleans up the code.

func describeTriggers(ctx context.Context, cli *fc20230330.Client, name *string) (triggers []*fc20230330.Trigger) {
	request := &fc20230330.ListTriggersRequest{}
	for {
		resp, err := cli.ListTriggers(name, request)
		if err != nil {
			log.CtxLogger(ctx).Warn("ListTriggers error", zap.Error(err))
			return nil
		}

		if resp.Body != nil {
			triggers = append(triggers, resp.Body.Triggers...)
			if resp.Body.NextToken == nil {
				break
			}
			request.NextToken = resp.Body.NextToken
		} else {
			break
		}
	}
	return triggers
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant