Skip to content

Conversation

@wuhuizuo
Copy link
Contributor

@wuhuizuo wuhuizuo commented Jan 30, 2026

Summary

  • Add sendTestCaseRunReport() function to prow.groovy shared library
  • Replace inline curl commands with function call in all pipeline files
  • CloudEvents URL centralized: https://internal2-do.pingcap.net/cloudevents-server/events

Changes

Benefits

  • Reduced code duplication: ~85% reduction (from 12 lines to 2 lines per file)
  • Single source of truth: CloudEvents URL configuration in one place
  • Easier maintenance: Future URL changes only need one update
  • Cleaner code: Declarative pipelines remain readable and concise

Modified Files

  • libraries/tipipeline/vars/prow.groovy - Added shared function
  • 23 pipeline files - Replaced inline curl with function call

Example

Before:

sh label: 'Send event to cloudevents server', script: """timeout 10 \\
    curl --verbose --request POST --url https://internal2-do.pingcap.net/cloudevents-server/events \\
    --header "ce-id: \\\$(uuidgen)" \\
    --header "ce-source: \\\${JENKINS_URL}" \\
    --header 'ce-type: test-case-run-report' \\
    --header 'ce-repo: \\\${REFS.org}/\\${REFS.repo}' \\
    --header 'ce-branch: \\\${REFS.base_ref}' \\
    --header "ce-buildurl: \\\${BUILD_URL}" \\
    --header 'ce-specversion: 1.0' \\
    --header 'content-type: application/json; charset=UTF-8' \\
    --data @bazel-go-test-problem-cases.json || true
"""

After:

script {
    prow.sendTestCaseRunReport("${REFS.org}/${REFS.repo}", "${REFS.base_ref}")
}

- Add sendTestCaseRunReport() function to prow.groovy library
- Replace inline curl commands with function call in all pipeline files
- CloudEvents URL centralized: https://internal2-do.pingcap.net/cloudevents-server/events
- Benefits:
  * Reduced code duplication (~85% reduction from 12 lines to 2 lines)
  * Single source of truth for CloudEvents URL
  * Easier maintenance and updates
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 30, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign wuhuizuo for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@ti-chi-bot ti-chi-bot bot left a comment

Choose a reason for hiding this comment

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

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary

This pull request refactors the Jenkins pipeline scripts to encapsulate the task of sending CloudEvents into a reusable shared function, sendTestCaseRunReport, defined within prow.groovy. It replaces verbose inline curl commands across ~23 pipeline files with concise function calls, centralizes CloudEvents URL configuration, and reduces code duplication significantly. The overall quality of these changes is good, with improvements in readability, maintainability, and consistency. However, there are minor areas that could be improved for better robustness and adherence to best practices.


Critical Issues

No critical issues were identified in the proposed changes. The refactoring appears to work as intended and does not introduce bugs, security vulnerabilities, or performance bottlenecks.


Code Improvements

1. Error Handling in sendTestCaseRunReport

  • File: libraries/tipipeline/vars/prow.groovy (lines 260-272)
  • Issue: The curl command in the new shared function uses || true to suppress all errors, which could mask legitimate issues during CloudEvents reporting. This makes debugging difficult if the server is unavailable or if there is a malformed request.
  • Suggested Solution: Implement better error handling to log failures explicitly or retry the operation. For example, capture the exit code and provide meaningful logs:
    def sendTestCaseRunReport(repo, branch, dataFile = 'bazel-go-test-problem-cases.json') {
        try {
            sh label: 'Send event to cloudevents server', script: """timeout 10 \
                curl --verbose --request POST --url https://internal2-do.pingcap.net/cloudevents-server/events \
                --header "ce-id: \$(uuidgen)" \
                --header "ce-source: \${JENKINS_URL}" \
                --header 'ce-type: test-case-run-report' \
                --header 'ce-repo: ${repo}' \
                --header 'ce-branch: ${branch}' \
                --header "ce-buildurl: \${BUILD_URL}" \
                --header 'ce-specversion: 1.0' \
                --header 'content-type: application/json; charset=UTF-8' \
                --data @${dataFile}
            """
        } catch (Exception e) {
            echo "Error sending CloudEvents report: ${e.message}"
            throw e
        }
    }

2. Parameter Validation

  • File: libraries/tipipeline/vars/prow.groovy (lines 260-272)
  • Issue: The function does not validate the repo, branch, or dataFile parameters before constructing the curl command. Invalid or empty parameters could lead to runtime failures or incorrect API requests.
  • Suggested Solution: Add validation for input parameters:
    if (!repo || !branch || !dataFile) {
        error("Invalid arguments passed to sendTestCaseRunReport: repo=${repo}, branch=${branch}, dataFile=${dataFile}")
    }

Best Practices

1. Improve Documentation

  • File: libraries/tipipeline/vars/prow.groovy (lines 260-272)
  • Issue: The newly added function lacks detailed comments or documentation about its purpose, parameters, and expected behavior.
  • Suggested Solution: Add a clear comment block above the function to explain its usage:
    /**
     * Sends a test case run report to the CloudEvents server.
     *
     * @param repo      Repository identifier (e.g., "pingcap/tidb").
     * @param branch    Branch name (e.g., "master").
     * @param dataFile  Path to the JSON file containing report data (default: 'bazel-go-test-problem-cases.json').
     */
    def sendTestCaseRunReport(repo, branch, dataFile = 'bazel-go-test-problem-cases.json') { ... }

2. Testing Coverage

  • Issue: The new function is used in multiple pipelines, but there is no indication of added tests to ensure the function behaves correctly under different scenarios (e.g., invalid inputs, server unavailability). This could lead to undetected errors in production pipelines.
  • Suggested Solution: Add unit tests for the sendTestCaseRunReport function within the shared library testing framework. Mock the sh command to simulate various scenarios, including success and failure.

3. Centralize Timeout Configuration

  • File: libraries/tipipeline/vars/prow.groovy (line 261)
  • Issue: The timeout value (timeout 10) is hardcoded, making it difficult to adjust globally. If the timeout needs to be updated in the future, each usage of the function must be revisited.
  • Suggested Solution: Use a configurable parameter or global constant for the timeout value:
    def timeoutSeconds = 10
    sh label: 'Send event to cloudevents server', script: """timeout ${timeoutSeconds} ...

4. Naming Conventions

  • File: libraries/tipipeline/vars/prow.groovy (line 260)
  • Issue: The function name sendTestCaseRunReport is descriptive but could be more precise about its dependency on CloudEvents.
  • Suggested Solution: Consider renaming the function to sendCloudEventTestReport for clarity.

Conclusion

The refactoring significantly improves pipeline maintainability and reduces code duplication. However, error handling, documentation, and testing should be enhanced to ensure robustness, clarity, and reliability. Addressing these issues will make the shared function more resilient and easier to use across the pipelines.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @wuhuizuo, 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 improves the maintainability and readability of the CI/CD pipelines by refactoring the mechanism for sending test case run reports to a CloudEvents server. By encapsulating the curl command and its associated configuration into a reusable shared Groovy function, it eliminates extensive code duplication and centralizes the CloudEvents endpoint, making the pipelines cleaner and easier to manage.

Highlights

  • New Shared Function: A new shared function, sendTestCaseRunReport(), has been introduced in prow.groovy to encapsulate the logic for sending test case run reports to the CloudEvents server.
  • Reduced Code Duplication: The repetitive inline curl commands previously used for sending CloudEvents have been replaced with calls to the new sendTestCaseRunReport() function across 23 pipeline files, resulting in an approximate 85% reduction in related code.
  • Centralized Configuration: The CloudEvents server URL is now centralized within the sendTestCaseRunReport() function, simplifying future updates and maintenance of the endpoint.
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.

@wuhuizuo
Copy link
Contributor Author

@copilot fix the PR description

Copy link
Contributor

Copilot AI commented Jan 30, 2026

@wuhuizuo I've opened a new pull request, #4135, to work on those changes. Once the pull request is ready, I'll request review from you.

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 is a great refactoring effort. It successfully encapsulates the logic for sending CloudEvents into a shared function sendTestCaseRunReport in prow.groovy. This significantly reduces code duplication across numerous pipeline files and centralizes the endpoint URL, which improves maintainability. The changes are well-executed and make the pipeline code cleaner and more concise. I have one suggestion to make the new shared function more robust and the CI logs cleaner.

// send test case run report to cloudevents server
def sendTestCaseRunReport(repo, branch, dataFile = 'bazel-go-test-problem-cases.json') {
sh label: 'Send event to cloudevents server', script: """timeout 10 \
curl --verbose --request POST --url https://internal2-do.pingcap.net/cloudevents-server/events \
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using --verbose for curl can make CI logs unnecessarily noisy. It's generally better to use -sS (--silent --show-error) to suppress progress output but still show errors. Additionally, adding the -f (--fail) flag will ensure that curl returns a non-zero exit code for HTTP server errors (like 4xx or 5xx), which is a more robust way to detect failures, even with || true.

        curl -sSf --request POST --url https://internal2-do.pingcap.net/cloudevents-server/events \

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants