Skip to content

Commit c5c74a4

Browse files
authored
DRIVERS-3264 Use first task and variant of the project by default for perf filtering (#715)
1 parent e7ba8d7 commit c5c74a4

4 files changed

Lines changed: 80 additions & 9 deletions

File tree

.evergreen/perfcomp/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ db.raw_results.find({
3737

3838
and look for the `variant` and `task_name` properties.
3939

40+
If you do not provide either the `variant` or `task_name`, they will be inferred by looking for the most recent
41+
perf data for the given `project`.
42+
4043
### perfcomp CLI
4144

4245
```bash
@@ -63,8 +66,8 @@ Usage:
6366
Flags:
6467
--perf-context string specify the performance triage context, ex. "GoDriver perf task" (required)
6568
--project string specify the name of an existing Evergreen project, ex. "mongo-go-driver" (required)
66-
--task string specify the evergreen perf task name, ex. "perf" (required)
67-
--variant string specify the perf task variant, ex. "perf" (required)
69+
--task string specify the evergreen perf task name, ex. "perf" (optional)
70+
--variant string specify the perf task variant, ex. "perf" (optional)
6871
```
6972

7073
#### mdreport

.evergreen/perfcomp/cmd/perfcomp/compare.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ func newCompareCommand() *cobra.Command {
3131
var project, task, variant, perfcontext string
3232
cmd.Flags().StringVar(&project, "project", "", `specify the name of an existing Evergreen project, ex. "mongo-go-driver"`)
3333
cmd.Flags().StringVar(&perfcontext, "perf-context", "", `specify the performance triage context, ex. "GoDriver perf task"`)
34-
// TODO(DRIVERS-3264): Use first task / variant of the project by default for perf filtering
3534
cmd.Flags().StringVar(&task, "task", "", `specify the evergreen performance task name, ex. "perf"`)
3635
cmd.Flags().StringVar(&variant, "variant", "", `specify the performance variant, ex. "perf"`)
3736

38-
for _, flag := range []string{"project", "task", "variant", "context"} {
39-
cmd.MarkFlagRequired(flag)
37+
for _, flag := range []string{"project", "perf-context"} {
38+
if flag == "" {
39+
log.Fatalf("must provide %s", flag)
40+
}
4041
}
4142

4243
cmd.Run = func(cmd *cobra.Command, args []string) {
@@ -47,12 +48,27 @@ func newCompareCommand() *cobra.Command {
4748
}
4849

4950
// Validate all flags
50-
for _, flag := range []string{"project", "task", "variant", "perf-context"} {
51+
for _, flag := range []string{"project", "perf-context"} {
5152
if flag == "" {
5253
log.Fatalf("must provide %s", flag)
5354
}
5455
}
5556

57+
// Fetch default task and variant if either not are provided
58+
if task == "" || variant == "" {
59+
var err error
60+
task, variant, err = perfcomp.GetDefaultTaskAndVariant(uri, project, task, variant)
61+
if err != nil {
62+
log.Fatalf("failed to fetch task/variant defaults: %v", err)
63+
}
64+
if task != "" {
65+
log.Printf("Using task: %s\n", task)
66+
}
67+
if variant != "" {
68+
log.Printf("Using variant: %s\n", variant)
69+
}
70+
}
71+
5672
// Run compare function
5773
err := runCompare(cmd, args,
5874
perfcomp.WithProject(project),

.evergreen/perfcomp/compare.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,60 @@ func validateOptions(copts CompareOptions) error {
179179
return nil
180180
}
181181

182+
// GetDefaultTaskAndVariant will find the default task and/or variant for a given project
183+
// using the most recent result in the raw_results collection.
184+
func GetDefaultTaskAndVariant(perfAnalyticsConnString, project, task, variant string) (string, string, error) {
185+
// Connect to analytics node
186+
client, err := mongo.Connect(options.Client().ApplyURI(perfAnalyticsConnString))
187+
if err != nil {
188+
return "", "", fmt.Errorf("error connecting client: %v", err)
189+
}
190+
191+
fmt.Println("Successfully connected to MongoDB")
192+
193+
defer func() { // Defer disconnect client
194+
err = client.Disconnect(context.Background())
195+
if err != nil {
196+
log.Fatalf("failed to disconnect client: %v", err)
197+
}
198+
}()
199+
200+
// Reference the collection in the database
201+
collection := client.Database(expandedMetricsDB).Collection(rawResultsColl)
202+
203+
// Build filter for querying raw_results
204+
filter := bson.M{
205+
"info.project": project,
206+
}
207+
if task != "" {
208+
filter["info.task_name"] = task
209+
}
210+
if variant != "" {
211+
filter["info.variant"] = variant
212+
}
213+
214+
// Set sort options for the query
215+
opts := options.FindOne().SetSort(bson.D{{Key: "created_at", Value: -1}}) // Sort by latest date
216+
217+
// Execute the query
218+
var result RawData
219+
findCtx, findCancel := context.WithTimeout(context.Background(), 30*time.Second)
220+
defer findCancel()
221+
222+
err = collection.FindOne(findCtx, filter, opts).Decode(&result)
223+
if err != nil {
224+
if err == mongo.ErrNoDocuments {
225+
fmt.Printf("No matching raw results found for project: %s\n", project)
226+
return "", "", fmt.Errorf("no matching raw results found for project: %s", project)
227+
}
228+
fmt.Printf("Failed to fetch defaults for project %s. Error: %v\n", project, err)
229+
return "", "", fmt.Errorf("failed to fetch defaults for project %s: %v", project, err)
230+
}
231+
232+
// Return the extracted values
233+
return result.Info.TaskName, result.Info.Variant, nil
234+
}
235+
182236
// Compare will return statistical results for a patch version using the
183237
// stable region defined by the performance analytics cluster.
184238
func Compare(ctx context.Context, perfAnalyticsConnString string, opts ...CompareOption) (*CompareResult, error) {

.evergreen/run-perf-comp.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ fi
6262
: "${VERSION_ID:?Error: VERSION_ID must be set}"
6363
: "${PROJECT:?Error: PROJECT must be set}"
6464
: "${CONTEXT:?Error: CONTEXT must be set}"
65-
: "${TASK:?Error: TASKNAME must be set}"
66-
: "${VARIANT:?Error: VARIANT must be set}"
6765

68-
./bin/perfcomp compare --project ${PROJECT} --perf-context "${CONTEXT}" --task ${TASK} --variant ${VARIANT} ${VERSION_ID}
66+
./bin/perfcomp compare --project ${PROJECT} --perf-context "${CONTEXT}" --task ${TASK:-} --variant ${VARIANT:-} ${VERSION_ID}
6967

7068
if [[ -n "${HEAD_SHA+set}" ]]; then
7169
./bin/perfcomp mdreport

0 commit comments

Comments
 (0)