Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 1e3b643

Browse files
authored
Search blitz: updates for 3rd-party users (#64375)
The goal of this PR is to make search blitz usable for customers who want to run it against their instance for continuous performance analysis. Specifically, this does two things: 1) Enables configuring the set of queries to run with the `SEARCH_BLITZ_QUERY_FILE` env var 2) Packages the image in our standard format so we can publish it
1 parent 59ad280 commit 1e3b643

File tree

6 files changed

+93
-15
lines changed

6 files changed

+93
-15
lines changed

internal/cmd/search-blitz/BUILD.bazel

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("//dev:go_defs.bzl", "go_test")
22
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
3+
load("//dev:oci_defs.bzl", "image_repository", "oci_image", "oci_push", "oci_tarball", "pkg_tar")
4+
load("@container_structure_test//:defs.bzl", "container_structure_test")
35

46
go_library(
57
name = "search-blitz_lib",
@@ -50,3 +52,45 @@ go_test(
5052
embed = [":search-blitz_lib"],
5153
tags = [TAG_PLATFORM_SEARCH],
5254
)
55+
56+
pkg_tar(
57+
name = "tar_search_blitz",
58+
srcs = [":search-blitz"],
59+
)
60+
61+
oci_image(
62+
name = "image",
63+
base = "//wolfi-images/sourcegraph-base:base_image",
64+
entrypoint = [
65+
"/sbin/tini",
66+
"--",
67+
"/search-blitz",
68+
],
69+
tars = [":tar_search_blitz"],
70+
user = "sourcegraph",
71+
)
72+
73+
oci_tarball(
74+
name = "image_tarball",
75+
image = ":image",
76+
repo_tags = ["search-blitz:candidate"],
77+
)
78+
79+
container_structure_test(
80+
name = "image_test",
81+
timeout = "short",
82+
configs = ["image_test.yaml"],
83+
driver = "docker",
84+
image = ":image",
85+
tags = [
86+
"exclusive",
87+
"requires-network",
88+
TAG_PLATFORM_SEARCH,
89+
],
90+
)
91+
92+
oci_push(
93+
name = "candidate_push",
94+
image = ":image",
95+
repository = image_repository("search-blitz"),
96+
)

internal/cmd/search-blitz/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Search-Blitz
22

33
The purpose of Search-Blitz is to provide a baseline for our search performance.
4-
Search-Blitz calls the stream and GraphQL API of Sourcegraph.com for typical
4+
Search-Blitz calls the stream and GraphQL APIs for typical
55
queries in regular intervals. Sourcegraph recognizes the Search-Blitz's
66
`User-Agent` and sends metrics to Prometheus.
77

@@ -18,6 +18,8 @@ Add the query to [`queries.txt`](https://github.com/sourcegraph/sourcegraph/blob
1818

1919
For attribution search add a `.txt` file to the attribution directory.
2020

21+
A custom set of queries can be provided at runtime by pointing to a query file with the `SEARCH_BLITZ_QUERY_FILE` env var.
22+
2123
## How to deploy
2224

2325
1. Merge your changes to _main_

internal/cmd/search-blitz/config.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"embed"
66
_ "embed"
77
"io/fs"
8+
"os"
89
"strings"
910
"time"
1011

@@ -26,7 +27,7 @@ type QueryConfig struct {
2627
Snippet string
2728
Name string
2829

29-
// An unset interval defaults to 1m
30+
// An unset interval defaults to 5m
3031
Interval time.Duration
3132

3233
// An empty value for Protocols means "all"
@@ -43,7 +44,21 @@ const (
4344
Stream
4445
)
4546

46-
func loadQueries(env string) (_ *Config, err error) {
47+
// Loads queries from queryFile if set, otherwise falls back to
48+
// embedded set of queries.
49+
func loadConfig(queryFile, env string) (_ *Config, err error) {
50+
if queryFile != "" {
51+
queriesRaw, err := os.ReadFile(queryFile)
52+
if err != nil {
53+
return nil, err
54+
}
55+
queries, err := parseQueries(queriesRaw)
56+
if err != nil {
57+
return nil, err
58+
}
59+
return &Config{Queries: queries}, nil
60+
}
61+
4762
if env == "" {
4863
env = "cloud"
4964
}
@@ -69,6 +84,16 @@ func loadQueries(env string) (_ *Config, err error) {
6984
}
7085
queries = append(queries, attributions...)
7186

87+
parsedQueries, err := parseQueries(queriesRaw)
88+
if err != nil {
89+
return nil, err
90+
}
91+
queries = append(queries, parsedQueries...)
92+
93+
return &Config{Queries: queries}, nil
94+
}
95+
96+
func parseQueries(queriesRaw []byte) (queries []*QueryConfig, err error) {
7297
var current QueryConfig
7398
add := func() {
7499
q := &QueryConfig{
@@ -97,10 +122,7 @@ func loadQueries(env string) (_ *Config, err error) {
97122
}
98123
}
99124
add()
100-
101-
return &Config{
102-
Queries: queries,
103-
}, err
125+
return queries, err
104126
}
105127

106128
func loadAttributions() ([]*QueryConfig, error) {

internal/cmd/search-blitz/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "testing"
55
func TestLoadQueries(t *testing.T) {
66
for _, env := range []string{"", "cloud", "dogfood"} {
77
t.Run(env, func(t *testing.T) {
8-
c, err := loadQueries(env)
8+
c, err := loadConfig("", env)
99
if err != nil {
1010
t.Fatal(err)
1111
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
schemaVersion: "2.0.0"
2+
3+
commandTests:
4+
- name: "not running as root"
5+
command: "/usr/bin/id"
6+
args:
7+
- -u
8+
excludedOutput: ["^0"]
9+
exitCode: 0

internal/cmd/search-blitz/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
envLogDir = "LOG_DIR"
2525
)
2626

27-
func run(ctx context.Context, wg *sync.WaitGroup, env string) {
27+
func run(ctx context.Context, wg *sync.WaitGroup, config *Config) {
2828
defer wg.Done()
2929

3030
bc, err := newClient()
@@ -37,11 +37,6 @@ func run(ctx context.Context, wg *sync.WaitGroup, env string) {
3737
panic(err)
3838
}
3939

40-
config, err := loadQueries(env)
41-
if err != nil {
42-
panic(err)
43-
}
44-
4540
clientForProtocol := func(p Protocol) genericClient {
4641
switch p {
4742
case Batch:
@@ -196,10 +191,16 @@ func main() {
196191
defer cleanup()
197192

198193
env := os.Getenv("SEARCH_BLITZ_ENV")
194+
queryFile := os.Getenv("SEARCH_BLITZ_QUERY_FILE")
195+
196+
config, err := loadConfig(queryFile, env)
197+
if err != nil {
198+
panic(err)
199+
}
199200

200201
wg := sync.WaitGroup{}
201202
wg.Add(1)
202-
go run(ctx, &wg, env)
203+
go run(ctx, &wg, config)
203204

204205
wg.Add(1)
205206
srv := startServer(&wg)

0 commit comments

Comments
 (0)