Skip to content

Commit

Permalink
Scj/update/executor validate (#974)
Browse files Browse the repository at this point in the history
* add executor option for src validate install

* remove commented code, remove  option

* remove binary

* lint

* update error int to -1
  • Loading branch information
scjohns authored and camdencheek committed Apr 24, 2023
1 parent 1ef7956 commit 4eff6b7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/validate/install/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}
Expand Down Expand Up @@ -116,6 +124,9 @@ func DefaultConfig() *ValidationSpec {
},
DeleteWhenDone: true,
},
Executor: Executor{
Enabled: false,
},
Smtp: Smtp{
Enabled: false,
To: "[email protected]",
Expand Down
52 changes: 52 additions & 0 deletions internal/validate/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 4eff6b7

Please sign in to comment.