Skip to content

Commit c33f7aa

Browse files
craig[bot]herkolateganpav-kvnormanchennspilchen
committed
142469: microbench-ci: combine compare and post r=rickystewart a=herkolategan Previously, the microbench-ci tool had separate commands for comparing benchmark results and posting them to GitHub. This change combines the compare and post functionality into a single command, simplifying the CI workflow by reducing the number of commands needed. When `--post` is specified, the tool will both generate the comparison summary and conditionally post it as a GitHub comment. Previously, a single comment was posted or updated on the PR for each invocation of the tool. Now, a new comment will be posted for each invocation of the tool if either the `X-perf-check` label is present or if the benchmark results have significant changes. Epic: None Release note: None 144051: raft: forward appended LogSlice to commit index r=tbg a=pav-kv When handling `MsgApp`, we never overwrite committed entries. Previously, `MsgApp` would be ignored if its `prev.index < raftLog.committed`. This was too strict: the appended slice can still have new entries > `committed` index. This PR makes it possible to accept such appends, after "forwarding" the appended slice to `committed` index. The `match` check still ensures that this partial append is correct. Epic: none Release note: none 144266: jsonpath: add support for `.size()`, `.type()` methods r=normanchenn a=normanchenn #### jsonpath: add support for .size() method This commit adds support for the `.size()` method in JSONPath queries, which returns the length of the array or 1 for non-array values (in lax mode). In strict mode, it returns an error when applied to non-array values. This commit also sets up the rest of the JSONPath methods, adding unimplemented errors when they are parsed. Informs: #22513 Release note (sql change): Add support for `.size()` method in JSONPath expressions. For example, `SELECT jsonb_path_query('[1, 2, 3]', '$.size()');`. #### jsonpath: add support for .type() method This commit adds support for the `.type()` method in JSONPath queries, which returns a string descripbing the type of the current JSON value ("object", "array", "string", "number", "boolean", "null"). Informs: #22513 Release note (sql change): Add support for `.type()` method for JSONPath queries. For example, `SELECT jsonb_path_query('[1, 2, 3]', '$.type()');`. 144297: sql: avoid unnecessary version bumps for UDTs during ALTER TABLE r=spilchen a=spilchen Previously, in the legacy schema changer, we unconditionally updated backreferences from tables to user-defined types (UDTs) during ALTER TABLE operations. This happened even when the backreferences remained unchanged. While this behavior was functionally harmless, it caused the version of the referenced types to be incremented unnecessarily. This change avoids version bumps unless the backreference actually changes. Fixes: #144293 Epic: none Release note: none Co-authored-by: Herko Lategan <[email protected]> Co-authored-by: Pavel Kalinnikov <[email protected]> Co-authored-by: Norman Chen <[email protected]> Co-authored-by: Matt Spilchen <[email protected]>
5 parents 8898577 + 20b36c1 + 94ace56 + a02c277 + a465010 commit c33f7aa

File tree

33 files changed

+749
-484
lines changed

33 files changed

+749
-484
lines changed

.github/workflows/microbenchmarks-ci.yaml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
name: build merge base
2020
runs-on: [self-hosted, basic_runner_group]
2121
timeout-minutes: 30
22+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'X-skip-perf-check') }}
2223
outputs:
2324
merge_base: ${{ steps.build.outputs.merge_base }}
2425
steps:
@@ -34,6 +35,7 @@ jobs:
3435
name: build head
3536
runs-on: [self-hosted, basic_runner_group]
3637
timeout-minutes: 30
38+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'X-skip-perf-check') }}
3739
steps:
3840
- name: Checkout
3941
uses: actions/checkout@v4
@@ -72,32 +74,11 @@ jobs:
7274
compare:
7375
runs-on: [self-hosted, basic_runner_group]
7476
timeout-minutes: 30
75-
needs: [base, run-group-1, run-group-2]
76-
steps:
77-
- name: Checkout
78-
uses: actions/checkout@v4
79-
- run: ./build/github/get-engflow-keys.sh
80-
shell: bash
81-
- name: Unique Build ID
82-
run: echo "BUILD_ID=${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV
83-
- name: Compare and Post
84-
run: ./build/github/microbenchmarks/compare.sh
85-
env:
86-
BASE_SHA: ${{ needs.base.outputs.merge_base }}
87-
HEAD_SHA: ${{ env.HEAD }}
88-
- name: Clean up
89-
run: ./build/github/cleanup-engflow-keys.sh
90-
shell: bash
91-
if: always()
92-
post:
93-
runs-on: [ self-hosted, basic_runner_group ]
94-
if: contains(github.event.pull_request.labels.*.name, 'T-microbench-post') # TODO: remove this check once results are confirmed to be stable on CI.
95-
timeout-minutes: 30
9677
permissions:
9778
contents: read
9879
pull-requests: write
99-
issues: write
100-
needs: [ base, compare ]
80+
issues: write
81+
needs: [base, run-group-1, run-group-2]
10182
steps:
10283
- name: Checkout
10384
uses: actions/checkout@v4
@@ -106,12 +87,13 @@ jobs:
10687
- name: Unique Build ID
10788
run: echo "BUILD_ID=${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV
10889
- name: Compare and Post
109-
run: ./build/github/microbenchmarks/post.sh
90+
run: ./build/github/microbenchmarks/compare.sh
11091
env:
92+
BASE_SHA: ${{ needs.base.outputs.merge_base }}
11193
HEAD_SHA: ${{ env.HEAD }}
11294
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113-
REPO: "cockroachdb/cockroach"
114-
PR_NUMBER: ${{ github.event.pull_request.number }}
95+
GITHUB_REPO: "cockroachdb/cockroach"
96+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
11597
- name: Clean up
11698
run: ./build/github/cleanup-engflow-keys.sh
11799
shell: bash

build/github/microbenchmarks/compare.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ done
2828
--github-summary="$output_dir/summary.md" \
2929
--build-id="$BUILD_ID" \
3030
--old="$BASE_SHA" \
31-
--new="$HEAD_SHA"
31+
--new="$HEAD_SHA" \
32+
--post
3233

3334
cat "$output_dir/summary.md" > "$GITHUB_STEP_SUMMARY"
3435

build/github/microbenchmarks/post.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

pkg/backup/restore_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ func createImportingDescriptors(
14011401
if err != nil {
14021402
return err
14031403
}
1404-
typDesc.AddReferencingDescriptorID(table.GetID())
1404+
_ = typDesc.AddReferencingDescriptorID(table.GetID())
14051405
if err := descsCol.WriteDescToBatch(
14061406
ctx, kvTrace, typDesc, b,
14071407
); err != nil {
@@ -3119,7 +3119,7 @@ func (r *restoreResumer) removeExistingTypeBackReferences(
31193119
}
31203120
existing := desc.(*typedesc.Mutable)
31213121
existing.MaybeIncrementVersion()
3122-
existing.RemoveReferencingDescriptorID(tbl.ID)
3122+
_ = existing.RemoveReferencingDescriptorID(tbl.ID)
31233123
}
31243124
}
31253125
}

pkg/cmd/microbench-ci/compare_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package main
77

88
import (
9+
"fmt"
910
"os"
1011
"os/exec"
1112
"path"
@@ -107,13 +108,13 @@ func TestRunAndCompare(t *testing.T) {
107108
require.NoError(t, err)
108109
results, err := suite.Benchmarks.compareBenchmarks()
109110
require.NoError(t, err)
110-
err = results.writeGitHubSummary(config.GitHubSummaryPath)
111+
summary, err := results.githubSummary()
111112
require.NoError(t, err)
112113
err = results.writeJSONSummary(config.SummaryPath)
113114
require.NoError(t, err)
114-
data, err := os.ReadFile(config.GitHubSummaryPath)
115-
require.NoError(t, err)
116-
return string(data)
115+
return summary
116+
case "changed":
117+
return fmt.Sprintf("%t", suite.changeDetected())
117118
case "json":
118119
data, err := os.ReadFile(config.SummaryPath)
119120
require.NoError(t, err)

pkg/cmd/microbench-ci/config/pull-request-suite.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ benchmarks:
1010
retries: 3
1111
metrics:
1212
- name: "sec/op"
13-
threshold: .3
13+
threshold: .6
1414
- name: "allocs/op"
15-
threshold: .1
15+
threshold: .2
1616

1717
- display_name: Sysbench
1818
labels: ["KV", "3node", "oltp_read_only"]
@@ -25,9 +25,9 @@ benchmarks:
2525
retries: 3
2626
metrics:
2727
- name: "sec/op"
28-
threshold: .4
28+
threshold: 0.9
2929
- name: "allocs/op"
30-
threshold: .1
30+
threshold: .3
3131

3232
- display_name: Sysbench
3333
labels: ["KV", "3node", "oltp_write_only"]
@@ -40,6 +40,6 @@ benchmarks:
4040
retries: 3
4141
metrics:
4242
- name: "sec/op"
43-
threshold: .4
43+
threshold: 0.9
4444
- name: "allocs/op"
45-
threshold: .1
45+
threshold: .3

pkg/cmd/microbench-ci/github.go

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,102 @@ import (
99
"context"
1010
"fmt"
1111
"os"
12+
"strconv"
1213
"strings"
1314

1415
"github.com/cockroachdb/errors"
1516
"github.com/google/go-github/v61/github"
1617
"golang.org/x/oauth2"
1718
)
1819

19-
// CommentTag is used to identify an existing comment.
20-
const CommentTag = "<!-- microbench-ci -->"
20+
type GitHubConfig struct {
21+
client *github.Client
22+
Owner string
23+
Repo string
24+
PrNum int
25+
}
26+
27+
const (
28+
CommentTag = "<!-- microbench-ci -->"
29+
PerfLabel = "X-perf-check"
30+
)
2131

22-
// post posts or updates a comment on a GitHub PR, with the given summary text,
23-
// that has the CommentTag marker in it.
24-
func post(summaryText, githubRepository string, prNumber int) error {
32+
// NewGithubConfig creates a new GitHubConfig from the environment variables.
33+
func NewGithubConfig() (*GitHubConfig, error) {
2534
token := os.Getenv("GITHUB_TOKEN")
2635
if token == "" {
27-
return errors.New("GITHUB_TOKEN is not set, this command is meant to be run in a GitHub Action")
36+
return nil, errors.New("GITHUB_TOKEN is not set")
2837
}
2938

30-
repoInfo := strings.Split(githubRepository, "/")
31-
if len(repoInfo) != 2 {
32-
return errors.New("invalid GitHub repository flag")
33-
}
34-
owner := repoInfo[0]
35-
repo := repoInfo[1]
36-
3739
ctx := context.Background()
3840
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
3941
tc := oauth2.NewClient(ctx, ts)
4042
client := github.NewClient(tc)
4143

42-
// Check for an existing comment
43-
comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil)
44+
githubRepository := os.Getenv("GITHUB_REPO")
45+
if githubRepository == "" {
46+
return nil, errors.New("GITHUB_REPO is not set")
47+
}
48+
prNumber := os.Getenv("GITHUB_PR_NUMBER")
49+
if prNumber == "" {
50+
return nil, errors.New("GITHUB_PR_NUMBER is not set")
51+
}
52+
prNumberInt, err := strconv.Atoi(prNumber)
4453
if err != nil {
45-
return err
54+
return nil, errors.Newf("invalid GITHUB_PR_NUMBER format %s", prNumber)
4655
}
47-
var existingComment *github.IssueComment
48-
for _, comment := range comments {
49-
if strings.Contains(comment.GetBody(), CommentTag) {
50-
existingComment = comment
51-
break
52-
}
56+
repoInfo := strings.Split(githubRepository, "/")
57+
if len(repoInfo) != 2 {
58+
return nil, errors.Newf("invalid GitHub repository flag, %s", githubRepository)
5359
}
60+
owner := repoInfo[0]
61+
repo := repoInfo[1]
62+
63+
return &GitHubConfig{
64+
client: client,
65+
Owner: owner,
66+
Repo: repo,
67+
PrNum: prNumberInt,
68+
}, nil
69+
}
5470

71+
// postComment posts a comment on a GitHub PR, with the given summary text, that
72+
// has the CommentTag marker in it.
73+
func (c *GitHubConfig) postComment(summaryText string) error {
74+
ctx := context.Background()
5575
commentBody := github.String(fmt.Sprintf("%s\n%s", summaryText, CommentTag))
56-
if existingComment != nil {
57-
// Update the existing comment
58-
existingComment.Body = commentBody
59-
_, _, err = client.Issues.EditComment(ctx, owner, repo, existingComment.GetID(), existingComment)
60-
return err
61-
}
76+
_, _, err := c.client.Issues.CreateComment(
77+
ctx, c.Owner, c.Repo, c.PrNum,
78+
&github.IssueComment{
79+
Body: commentBody,
80+
},
81+
)
82+
return err
83+
}
6284

63-
// Create a new comment
64-
_, _, err = client.Issues.CreateComment(ctx, owner, repo, prNumber, &github.IssueComment{
65-
Body: commentBody,
66-
})
85+
// addLabel adds a label to a GitHub PR.
86+
func (c *GitHubConfig) addLabel(label string) error {
87+
ctx := context.Background()
88+
_, _, err := c.client.Issues.AddLabelsToIssue(
89+
ctx, c.Owner, c.Repo, c.PrNum,
90+
[]string{label},
91+
)
6792
return err
6893
}
94+
95+
// hasLabel checks if a GitHub PR has a label.
96+
func (c *GitHubConfig) hasLabel(label string) (bool, error) {
97+
ctx := context.Background()
98+
labels, _, err := c.client.Issues.ListLabelsByIssue(
99+
ctx, c.Owner, c.Repo, c.PrNum, &github.ListOptions{PerPage: 100},
100+
)
101+
if err != nil {
102+
return false, err
103+
}
104+
for _, l := range labels {
105+
if *l.Name == label {
106+
return true, nil
107+
}
108+
}
109+
return false, nil
110+
}

0 commit comments

Comments
 (0)