Skip to content

Commit 4eff6b7

Browse files
scjohnscamdencheek
authored andcommitted
Scj/update/executor validate (#974)
* add executor option for src validate install * remove commented code, remove option * remove binary * lint * update error int to -1
1 parent 1ef7956 commit 4eff6b7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

internal/validate/install/config.go

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ type Insight struct {
5252
DeleteWhenDone bool `yaml:"deleteWhenDone"`
5353
}
5454

55+
type Executor struct {
56+
Enabled bool `yaml:"enabled"`
57+
Count bool `yaml:"count"`
58+
}
59+
5560
type Smtp struct {
5661
Enabled bool `yaml:"enabled"`
5762
To string `yaml:"to"`
@@ -67,6 +72,9 @@ type ValidationSpec struct {
6772
// Insight used for validation testing.
6873
Insight Insight `yaml:"insight"`
6974

75+
// Executor check configuration
76+
Executor Executor `yaml:"executor"`
77+
7078
//Test SMTP configuration
7179
Smtp Smtp `yaml:"smtp"`
7280
}
@@ -116,6 +124,9 @@ func DefaultConfig() *ValidationSpec {
116124
},
117125
DeleteWhenDone: true,
118126
},
127+
Executor: Executor{
128+
Enabled: false,
129+
},
119130
Smtp: Smtp{
120131
Enabled: false,
121132

internal/validate/install/install.go

+52
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er
4747
}
4848
}
4949

50+
// run executor queries
51+
if config.Executor.Enabled {
52+
log.Printf("%s validating executor connections", validate.EmojiFingerPointRight)
53+
54+
executorQuery := `query executors($query: String, $active: Boolean, $first: Int, $after: String) {
55+
executors(query: $query, active: $active, first: $first, after: $after){
56+
totalCount
57+
}
58+
}`
59+
executorVars := map[string]interface{}{
60+
"query": "",
61+
"active": true,
62+
"first": 100,
63+
"after": "",
64+
}
65+
66+
totalCount, err := checkExecutors(ctx, client, executorQuery, executorVars)
67+
if err != nil {
68+
return err
69+
}
70+
if totalCount == 0 {
71+
log.Printf("%s validation failed, 0 executors found", validate.FlashingLightEmoji)
72+
}
73+
if totalCount >= 1 {
74+
log.Printf("%s executors found, %d executor(s) connected to Sourcegraph instance", validate.SuccessEmoji, totalCount)
75+
}
76+
}
77+
5078
if config.Smtp.Enabled {
5179
log.Printf("%s validating smtp connection", validate.EmojiFingerPointRight)
5280

@@ -88,6 +116,30 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er
88116
return nil
89117
}
90118

119+
func checkExecutors(ctx context.Context, client api.Client, query string, variables map[string]interface{}) (int, error) {
120+
q := clientQuery{
121+
opName: "CheckExecutorConnection",
122+
query: query,
123+
variables: variables,
124+
}
125+
126+
var result struct {
127+
Executor struct {
128+
TotalCount int `json:"totalCount"`
129+
} `json:"executors"`
130+
}
131+
132+
ok, err := client.NewRequest(q.query, q.variables).Do(ctx, &result)
133+
if err != nil {
134+
return -1, errors.Wrap(err, "checkExecutors failed")
135+
}
136+
if !ok {
137+
return -1, errors.New("checkExecutors failed, no data to unmarshal")
138+
}
139+
140+
return result.Executor.TotalCount, nil
141+
}
142+
91143
func removeExternalService(ctx context.Context, client api.Client, id string) error {
92144
q := clientQuery{
93145
opName: "DeleteExternalService",

0 commit comments

Comments
 (0)