From d5f121eff70085efe650b207dce84bac6fc2d06a Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Thu, 17 Aug 2023 12:12:53 +0100 Subject: [PATCH] address comments --- internal/api/controller/logs/find.go | 2 +- internal/api/controller/logs/tail.go | 2 +- internal/api/handler/logs/tail.go | 3 ++- internal/store/database/stage.go | 2 +- internal/store/database/step.go | 2 +- internal/store/logs/wire.go | 10 +++++----- types/config.go | 14 ++++++++------ types/stage.go | 2 +- types/step.go | 2 +- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/internal/api/controller/logs/find.go b/internal/api/controller/logs/find.go index 5992de80b..e82bb815c 100644 --- a/internal/api/controller/logs/find.go +++ b/internal/api/controller/logs/find.go @@ -25,7 +25,7 @@ func (c *Controller) Find( ) (io.ReadCloser, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { - return nil, fmt.Errorf("could not find parent space: %w", err) + return nil, fmt.Errorf("failed to find parent space: %w", err) } pipeline, err := c.pipelineStore.FindByUID(ctx, space.ID, pipelineUID) diff --git a/internal/api/controller/logs/tail.go b/internal/api/controller/logs/tail.go index 981d10f95..dbe053437 100644 --- a/internal/api/controller/logs/tail.go +++ b/internal/api/controller/logs/tail.go @@ -25,7 +25,7 @@ func (c *Controller) Tail( ) (<-chan *livelog.Line, <-chan error, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { - return nil, nil, fmt.Errorf("could not find parent space: %w", err) + return nil, nil, fmt.Errorf("failed to find parent space: %w", err) } pipeline, err := c.pipelineStore.FindByUID(ctx, space.ID, pipelineUID) diff --git a/internal/api/handler/logs/tail.go b/internal/api/handler/logs/tail.go index cc456fbc9..e21d94878 100644 --- a/internal/api/handler/logs/tail.go +++ b/internal/api/handler/logs/tail.go @@ -97,7 +97,8 @@ func HandleTail(logCtrl *logs.Controller) http.HandlerFunc { select { case <-ctx.Done(): break L - case <-errc: + case err := <-errc: + log.Err(err).Msg("received error in the tail channel") break L case <-msgDelayTimer.C: io.WriteString(w, ": ping\n\n") diff --git a/internal/store/database/stage.go b/internal/store/database/stage.go index 178cce23d..4e2bb8183 100644 --- a/internal/store/database/stage.go +++ b/internal/store/database/stage.go @@ -52,7 +52,7 @@ const ( type stage struct { ID int64 `db:"stage_id"` ExecutionID int64 `db:"stage_execution_id"` - Number int `db:"stage_number"` + Number int64 `db:"stage_number"` Name string `db:"stage_name"` Kind string `db:"stage_kind"` Type string `db:"stage_type"` diff --git a/internal/store/database/step.go b/internal/store/database/step.go index c87474fcb..8e3ac9daf 100644 --- a/internal/store/database/step.go +++ b/internal/store/database/step.go @@ -41,7 +41,7 @@ const ( type step struct { ID int64 `db:"step_id"` StageID int64 `db:"step_stage_id"` - Number int `db:"step_number"` + Number int64 `db:"step_number"` Name string `db:"step_name"` Status string `db:"step_status"` Error string `db:"step_error"` diff --git a/internal/store/logs/wire.go b/internal/store/logs/wire.go index 5c0c18aeb..c2243c232 100644 --- a/internal/store/logs/wire.go +++ b/internal/store/logs/wire.go @@ -19,12 +19,12 @@ var WireSet = wire.NewSet( func ProvideLogStore(db *sqlx.DB, config *types.Config) store.LogStore { s := NewDatabaseLogStore(db) - if config.S3.Bucket != "" { + if config.Logs.S3.Bucket != "" { p := NewS3LogStore( - config.S3.Bucket, - config.S3.Prefix, - config.S3.Endpoint, - config.S3.PathStyle, + config.Logs.S3.Bucket, + config.Logs.S3.Prefix, + config.Logs.S3.Endpoint, + config.Logs.S3.PathStyle, ) return NewCombined(p, s) } diff --git a/types/config.go b/types/config.go index c5d2e2b98..81c388072 100644 --- a/types/config.go +++ b/types/config.go @@ -90,12 +90,14 @@ type Config struct { Expire time.Duration `envconfig:"GITNESS_TOKEN_EXPIRE" default:"720h"` } - // S3 provides optional storage option for logs. - S3 struct { - Bucket string `envconfig:"GITNESS_S3_BUCKET"` - Prefix string `envconfig:"GITNESS_S3_PREFIX"` - Endpoint string `envconfig:"GITNESS_S3_ENDPOINT"` - PathStyle bool `envconfig:"GITNESS_S3_PATH_STYLE"` + Logs struct { + // S3 provides optional storage option for logs. + S3 struct { + Bucket string `envconfig:"GITNESS_LOGS_S3_BUCKET"` + Prefix string `envconfig:"GITNESS_LOGS_S3_PREFIX"` + Endpoint string `envconfig:"GITNESS_LOGS_S3_ENDPOINT"` + PathStyle bool `envconfig:"GITNESS_LOGS_S3_PATH_STYLE"` + } } // Cors defines http cors parameters diff --git a/types/stage.go b/types/stage.go index 5fcecde3e..d07218845 100644 --- a/types/stage.go +++ b/types/stage.go @@ -7,7 +7,7 @@ package types type Stage struct { ID int64 `json:"-"` ExecutionID int64 `json:"execution_id"` - Number int `json:"number"` + Number int64 `json:"number"` Name string `json:"name"` Kind string `json:"kind,omitempty"` Type string `json:"type,omitempty"` diff --git a/types/step.go b/types/step.go index 597a7f466..17413017a 100644 --- a/types/step.go +++ b/types/step.go @@ -7,7 +7,7 @@ package types type Step struct { ID int64 `json:"-"` StageID int64 `json:"-"` - Number int `json:"number"` + Number int64 `json:"number"` Name string `json:"name"` Status string `json:"status"` Error string `json:"error,omitempty"`