Skip to content

Commit

Permalink
fix: add timeout to grpc conn (#4107)
Browse files Browse the repository at this point in the history
* fix: added timout to grpc conn

* fix: log in valid place

* fix: allow to configure timeout with env variable

* fix: print timout

* fix: print timout

* fix: timeout as seconds
  • Loading branch information
exu authored Jun 30, 2023
1 parent e90ef19 commit 6c901d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
38 changes: 20 additions & 18 deletions pkg/envs/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import (

// Params are the environment variables provided by the Testkube api-server
type Params struct {
Endpoint string // RUNNER_ENDPOINT
AccessKeyID string // RUNNER_ACCESSKEYID
SecretAccessKey string // RUNNER_SECRETACCESSKEY
Region string // RUNNER_REGION
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
DashboardURI string `envconfig:"RUNNER_DASHBOARD_URI"` // RUNNER_DASHBOARD_URI
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
Endpoint string // RUNNER_ENDPOINT
AccessKeyID string // RUNNER_ACCESSKEYID
SecretAccessKey string // RUNNER_SECRETACCESSKEY
Region string // RUNNER_REGION
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
DashboardURI string `envconfig:"RUNNER_DASHBOARD_URI"` // RUNNER_DASHBOARD_URI
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
CloudConnectionTimeoutSec int `envconfig:"RUNNER_CLOUD_CONNECTION_TIMEOUT" default:"10"` // RUNNER_CLOUD_CONNECTION_TIMEOUT
}

// LoadTestkubeVariables loads the parameters provided as environment variables in the Test CRD
Expand Down Expand Up @@ -66,6 +67,7 @@ func printParams(params Params) {
output.PrintLogf("RUNNER_CLOUD_API_TLS_INSECURE=\"%t\"", params.CloudAPITLSInsecure)
output.PrintLogf("RUNNER_CLOUD_API_URL=\"%s\"", params.CloudAPIURL)
printSensitiveParam("RUNNER_CLOUD_API_KEY", params.CloudAPIKey)
output.PrintLogf("RUNNER_CLOUD_CONNECTION_TIMEOUT=%d", params.CloudConnectionTimeoutSec)
}

// printSensitiveParam shows in logs if a parameter is set or not
Expand Down
9 changes: 7 additions & 2 deletions pkg/executor/scraper/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package factory
import (
"context"
"fmt"
"time"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -89,12 +90,16 @@ func GetScraper(ctx context.Context, params envs.Params, extractorType Extractor
}

func getCloudLoader(ctx context.Context, params envs.Params) (uploader *cloudscraper.CloudUploader, err error) {
output.PrintLog(fmt.Sprintf("%s Uploading artifacts using Cloud Uploader", ui.IconCheckMark))
// timeout blocking connection to cloud
ctxTimeout, cancel := context.WithTimeout(ctx, time.Duration(params.CloudConnectionTimeoutSec)*time.Second)
defer cancel()

grpcConn, err := agent.NewGRPCConnection(ctx, params.CloudAPITLSInsecure, params.CloudAPIURL, log.DefaultLogger)
output.PrintLogf("%s Uploading artifacts using Cloud Uploader (timeout:%ds)", ui.IconCheckMark, params.CloudConnectionTimeoutSec)
grpcConn, err := agent.NewGRPCConnection(ctxTimeout, params.CloudAPITLSInsecure, params.CloudAPIURL, log.DefaultLogger)
if err != nil {
return nil, err
}
output.PrintLogf("%s Connected to Testkube Cloud", ui.IconCheckMark)

grpcClient := cloud.NewTestKubeCloudAPIClient(grpcConn)
cloudExecutor := cloudexecutor.NewCloudGRPCExecutor(grpcClient, grpcConn, params.CloudAPIKey)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/test_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGetExecuteOptions(t *testing.T) {
ExecutionLabels: map[string]string{"label": "value"},
Namespace: "namespace",
VariablesFile: "",
Variables: map[string]testkube.Variable{"var": testkube.Variable{Name: "one"}},
Variables: map[string]testkube.Variable{"var": {Name: "one"}},
Command: []string{"run"},
Args: []string{},
ArgsMode: "",
Expand Down

0 comments on commit 6c901d6

Please sign in to comment.