diff --git a/internal/validate/install/config.go b/internal/validate/install/config.go index 7578522f13..930cf2027b 100644 --- a/internal/validate/install/config.go +++ b/internal/validate/install/config.go @@ -52,6 +52,11 @@ type Insight struct { DeleteWhenDone bool `yaml:"deleteWhenDone"` } +type Executor struct { + Enabled bool `yaml:"enabled"` + Count bool `yaml:"count"` +} + type Smtp struct { Enabled bool `yaml:"enabled"` To string `yaml:"to"` @@ -67,6 +72,9 @@ type ValidationSpec struct { // Insight used for validation testing. Insight Insight `yaml:"insight"` + // Executor check configuration + Executor Executor `yaml:"executor"` + //Test SMTP configuration Smtp Smtp `yaml:"smtp"` } @@ -116,6 +124,9 @@ func DefaultConfig() *ValidationSpec { }, DeleteWhenDone: true, }, + Executor: Executor{ + Enabled: false, + }, Smtp: Smtp{ Enabled: false, To: "example@domain.com", diff --git a/internal/validate/install/install.go b/internal/validate/install/install.go index a9d905a696..9b3966190c 100644 --- a/internal/validate/install/install.go +++ b/internal/validate/install/install.go @@ -47,6 +47,34 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er } } + // run executor queries + if config.Executor.Enabled { + log.Printf("%s validating executor connections", validate.EmojiFingerPointRight) + + executorQuery := `query executors($query: String, $active: Boolean, $first: Int, $after: String) { + executors(query: $query, active: $active, first: $first, after: $after){ + totalCount + } + }` + executorVars := map[string]interface{}{ + "query": "", + "active": true, + "first": 100, + "after": "", + } + + totalCount, err := checkExecutors(ctx, client, executorQuery, executorVars) + if err != nil { + return err + } + if totalCount == 0 { + log.Printf("%s validation failed, 0 executors found", validate.FlashingLightEmoji) + } + if totalCount >= 1 { + log.Printf("%s executors found, %d executor(s) connected to Sourcegraph instance", validate.SuccessEmoji, totalCount) + } + } + if config.Smtp.Enabled { log.Printf("%s validating smtp connection", validate.EmojiFingerPointRight) @@ -88,6 +116,30 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er return nil } +func checkExecutors(ctx context.Context, client api.Client, query string, variables map[string]interface{}) (int, error) { + q := clientQuery{ + opName: "CheckExecutorConnection", + query: query, + variables: variables, + } + + var result struct { + Executor struct { + TotalCount int `json:"totalCount"` + } `json:"executors"` + } + + ok, err := client.NewRequest(q.query, q.variables).Do(ctx, &result) + if err != nil { + return -1, errors.Wrap(err, "checkExecutors failed") + } + if !ok { + return -1, errors.New("checkExecutors failed, no data to unmarshal") + } + + return result.Executor.TotalCount, nil +} + func removeExternalService(ctx context.Context, client api.Client, id string) error { q := clientQuery{ opName: "DeleteExternalService", diff --git a/src b/src new file mode 100755 index 0000000000..16741a8eee Binary files /dev/null and b/src differ