-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3102: Perf comp PR comment pipeline #2149
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
76ebbbf
Set up pipeline to generate perf comp comment during a PR run
zhouselena cd7c4da
Generate formatted perf comment with dynamic Evg URLs
zhouselena 50c1972
Make PR comment script and include permissions
zhouselena d81091a
Nit: add space in header
zhouselena 6d8358c
Sort significant benchmarks by percent change
zhouselena bf44195
Bold summary of dropdown
zhouselena ce710ae
Reiterate on display and include comments
zhouselena 2205f19
Rename header to Performance Results
zhouselena 078f430
Merge branch 'master' of github.com:zhouselena/mongo-go-driver into G…
zhouselena 9e2ca6d
Set up and install cobra
zhouselena 8e6dd5f
Restructure files to use cobra in main.go
zhouselena 690ea84
Merge branch 'master' of github.com:zhouselena/mongo-go-driver into G…
zhouselena d8c6c14
Add bin in gitignore
zhouselena 7c5791b
Add check for correct project flag
zhouselena 53c83de
Merge branch 'master' of github.com:zhouselena/mongo-go-driver into G…
zhouselena 2355f33
Merge branch 'master' of github.com:zhouselena/mongo-go-driver into G…
zhouselena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zhouselena marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright (C) MongoDB, Inc. 2025-present. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package main | ||
zhouselena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const parsePerfCompDir = "./internal/cmd/perfcomp/parseperfcomp/" | ||
const perfReportFileTxt = "perf-report.txt" | ||
const perfReportFileMd = "perf-report.md" | ||
const perfVariant = "^perf$" | ||
|
||
func main() { | ||
var line string | ||
|
||
// open file to read | ||
fRead, err := os.Open(parsePerfCompDir + perfReportFileTxt) | ||
if err != nil { | ||
log.Fatalf("Could not open %s: %v", perfReportFileTxt, err) | ||
} | ||
defer fRead.Close() | ||
|
||
// open file to write | ||
fWrite, err := os.Create(perfReportFileMd) | ||
if err != nil { | ||
log.Fatalf("Could not create %s: %v", perfReportFileMd, err) | ||
} | ||
defer fWrite.Close() | ||
|
||
fmt.Fprintf(fWrite, "## 👋 GoDriver Performance\n") | ||
|
||
// read the file line by line using scanner | ||
scanner := bufio.NewScanner(fRead) | ||
|
||
var version string | ||
var evgLink string | ||
|
||
for scanner.Scan() { | ||
line = scanner.Text() | ||
if strings.Contains(line, "Version ID:") { | ||
// parse version | ||
version = strings.Split(line, " ")[2] | ||
} else if strings.Contains(line, "Commit SHA:") { | ||
// parse commit SHA and write header | ||
fmt.Fprintf(fWrite, "\n<details>\n<summary><b>%s</b></summary>\n\t<br>\n\n", line) | ||
} else if strings.Contains(line, "version "+version) { | ||
// dynamic Evergreen perf task link | ||
evgLink, err = generateEvgLink(version, perfVariant) | ||
if err != nil { | ||
log.Println(err) | ||
fmt.Fprintf(fWrite, "%s\n", line) | ||
} else { | ||
printUrlToLine(fWrite, line, evgLink, "version", -1) | ||
} | ||
} else if strings.Contains(line, "For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.") { | ||
// last line of comment | ||
evgLink, err = generateEvgLink(version, "") | ||
if err != nil { | ||
log.Println(err) | ||
fmt.Fprintf(fWrite, "%s\n", line) | ||
} else { | ||
printUrlToLine(fWrite, line, evgLink, "Evergreen", 0) | ||
} | ||
} else { | ||
// all other regular lines | ||
fmt.Fprintf(fWrite, "%s\n", line) | ||
} | ||
} | ||
|
||
fmt.Fprintf(fWrite, "</details>\n") | ||
} | ||
|
||
func generateEvgLink(version string, variant string) (string, error) { | ||
baseUrl := "https://spruce.mongodb.com" | ||
page := "0" | ||
sorts := "STATUS:ASC;BASE_STATUS:DESC" | ||
|
||
u, err := url.Parse(baseUrl) | ||
if err != nil { | ||
return "", fmt.Errorf("Error parsing URL: %v", err) | ||
} | ||
|
||
u.Path = fmt.Sprintf("version/%s/tasks", version) | ||
|
||
// construct query parameters | ||
queryParams := url.Values{} | ||
queryParams.Add("page", page) | ||
queryParams.Add("sorts", sorts) | ||
if variant != "" { | ||
queryParams.Add("variant", variant) | ||
} | ||
|
||
u.RawQuery = queryParams.Encode() | ||
return u.String(), nil | ||
} | ||
|
||
func printUrlToLine(fWrite *os.File, line string, link string, targetWord string, step int) { | ||
words := strings.Split(line, " ") | ||
for i, w := range words { | ||
if i > 0 && words[i+step] == targetWord { | ||
fmt.Fprintf(fWrite, "[%s](%s)", w, link) | ||
} else { | ||
fmt.Fprint(fWrite, w) | ||
} | ||
|
||
if i < len(words)-1 { | ||
fmt.Fprint(fWrite, " ") | ||
} else { | ||
fmt.Fprint(fWrite, "\n") | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.