github.com/GoogleCloudPlatform/testgrid@v0.0.163/benchmark/tabulator_bench_test.go (about)

     1  /*
     2  Copyright 2022 The TestGrid Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package benchmark
    18  
    19  import (
    20  	"context"
    21  	"flag"
    22  	"runtime"
    23  	"testing"
    24  	"time"
    25  
    26  	"github.com/GoogleCloudPlatform/testgrid/pkg/tabulator"
    27  	"github.com/GoogleCloudPlatform/testgrid/util/gcs"
    28  	"github.com/GoogleCloudPlatform/testgrid/util/metrics/prometheus"
    29  )
    30  
    31  var config = flag.String("config", "", "Config file of working testgrid directory. The directory may be modified.")
    32  
    33  func BenchmarkTabulator(b *testing.B) {
    34  	ctx, cancel := context.WithCancel(context.Background())
    35  	defer cancel()
    36  
    37  	if config == nil || *config == "" {
    38  		b.Fatalf("needs --config flag")
    39  	}
    40  
    41  	cfgPath, err := gcs.NewPath(*config)
    42  	if err != nil {
    43  		b.Fatalf("bad config path %q: %v", *config, err)
    44  	}
    45  
    46  	storageClient, err := gcs.ClientWithCreds(ctx, "")
    47  	if err != nil {
    48  		b.Fatalf("create client: %v", err)
    49  	}
    50  	defer storageClient.Close()
    51  
    52  	client := gcs.NewClient(storageClient)
    53  
    54  	mets := tabulator.CreateMetrics(prometheus.NewFactory()) // TODO(chases2): replace with logging metrics factory or teach tabulator to tolerate missing metrics
    55  
    56  	opts := &tabulator.UpdateOptions{
    57  		ConfigPath:          *cfgPath,
    58  		ReadConcurrency:     2 * runtime.NumCPU(),
    59  		WriteConcurrency:    4 * runtime.NumCPU(),
    60  		GridPathPrefix:      "grid",
    61  		TabsPathPrefix:      "tabs",
    62  		AllowedGroups:       nil,
    63  		Confirm:             true,
    64  		CalculateStats:      true,
    65  		UseTabAlertSettings: true,
    66  		ExtendState:         false,
    67  		Freq:                time.Duration(0),
    68  	}
    69  	if err = tabulator.Update(ctx, client, mets, opts); err != nil {
    70  		b.Fatalf("update error: %v", err)
    71  	}
    72  }