Skip to content

Commit f8c795f

Browse files
authored
enhance(log): do not return log object for POST and PUT requests (#879)
1 parent ad8d7d7 commit f8c795f

20 files changed

+48
-70
lines changed

api/log/create_service.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ import (
6161
// responses:
6262
// '201':
6363
// description: Successfully created the service logs
64-
// schema:
65-
// "$ref": "#/definitions/Log"
6664
// '400':
6765
// description: Unable to create the service logs
6866
// schema:
@@ -113,7 +111,7 @@ func CreateServiceLog(c *gin.Context) {
113111
input.SetRepoID(r.GetID())
114112

115113
// send API call to create the logs
116-
l, err := database.FromContext(c).CreateLog(input)
114+
err = database.FromContext(c).CreateLog(input)
117115
if err != nil {
118116
retErr := fmt.Errorf("unable to create logs for service %s: %w", entry, err)
119117

@@ -122,5 +120,5 @@ func CreateServiceLog(c *gin.Context) {
122120
return
123121
}
124122

125-
c.JSON(http.StatusCreated, l)
123+
c.JSON(http.StatusCreated, nil)
126124
}

api/log/create_step.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ import (
6161
// responses:
6262
// '201':
6363
// description: Successfully created the logs for step
64-
// schema:
65-
// "$ref": "#/definitions/Log"
6664
// '400':
6765
// description: Unable to create the logs for a step
6866
// schema:
@@ -113,7 +111,7 @@ func CreateStepLog(c *gin.Context) {
113111
input.SetRepoID(r.GetID())
114112

115113
// send API call to create the logs
116-
l, err := database.FromContext(c).CreateLog(input)
114+
err = database.FromContext(c).CreateLog(input)
117115
if err != nil {
118116
retErr := fmt.Errorf("unable to create logs for step %s: %w", entry, err)
119117

@@ -122,5 +120,5 @@ func CreateStepLog(c *gin.Context) {
122120
return
123121
}
124122

125-
c.JSON(http.StatusCreated, l)
123+
c.JSON(http.StatusCreated, nil)
126124
}

api/log/update_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func UpdateServiceLog(c *gin.Context) {
124124
}
125125

126126
// send API call to update the log
127-
l, err = database.FromContext(c).UpdateLog(l)
127+
err = database.FromContext(c).UpdateLog(l)
128128
if err != nil {
129129
retErr := fmt.Errorf("unable to update logs for service %s: %w", entry, err)
130130

@@ -133,5 +133,5 @@ func UpdateServiceLog(c *gin.Context) {
133133
return
134134
}
135135

136-
c.JSON(http.StatusOK, l)
136+
c.JSON(http.StatusOK, nil)
137137
}

api/log/update_step.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func UpdateStepLog(c *gin.Context) {
124124
}
125125

126126
// send API call to update the log
127-
l, err = database.FromContext(c).UpdateLog(l)
127+
err = database.FromContext(c).UpdateLog(l)
128128
if err != nil {
129129
retErr := fmt.Errorf("unable to update logs for step %s: %w", entry, err)
130130

@@ -133,5 +133,5 @@ func UpdateStepLog(c *gin.Context) {
133133
return
134134
}
135135

136-
c.JSON(http.StatusOK, l)
136+
c.JSON(http.StatusOK, nil)
137137
}

api/service/plan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func PlanServices(database database.Interface, p *pipeline.Build, b *library.Bui
6161
l.SetData([]byte{})
6262

6363
// send API call to create the service logs
64-
_, err = database.CreateLog(l)
64+
err = database.CreateLog(l)
6565
if err != nil {
6666
return services, fmt.Errorf("unable to create service logs for service %s: %w", s.GetName(), err)
6767
}

api/step/plan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func planStep(database database.Interface, b *library.Build, c *pipeline.Contain
8888
l.SetData([]byte{})
8989

9090
// send API call to create the step logs
91-
_, err = database.CreateLog(l)
91+
err = database.CreateLog(l)
9292
if err != nil {
9393
return nil, fmt.Errorf("unable to create logs for step %s: %w", s.GetName(), err)
9494
}

database/log/count_build_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func TestLog_Engine_CountLogsForBuild(t *testing.T) {
4343
_sqlite := testSqlite(t)
4444
defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }()
4545

46-
_, err := _sqlite.CreateLog(_service)
46+
err := _sqlite.CreateLog(_service)
4747
if err != nil {
4848
t.Errorf("unable to create test service log for sqlite: %v", err)
4949
}
5050

51-
_, err = _sqlite.CreateLog(_step)
51+
err = _sqlite.CreateLog(_step)
5252
if err != nil {
5353
t.Errorf("unable to create test step log for sqlite: %v", err)
5454
}

database/log/count_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func TestLog_Engine_CountLogs(t *testing.T) {
3737
_sqlite := testSqlite(t)
3838
defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }()
3939

40-
_, err := _sqlite.CreateLog(_service)
40+
err := _sqlite.CreateLog(_service)
4141
if err != nil {
4242
t.Errorf("unable to create test service log for sqlite: %v", err)
4343
}
4444

45-
_, err = _sqlite.CreateLog(_step)
45+
err = _sqlite.CreateLog(_step)
4646
if err != nil {
4747
t.Errorf("unable to create test step log for sqlite: %v", err)
4848
}

database/log/create.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
// CreateLog creates a new log in the database.
17-
func (e *engine) CreateLog(l *library.Log) (*library.Log, error) {
17+
func (e *engine) CreateLog(l *library.Log) error {
1818
// check what the log entry is for
1919
switch {
2020
case l.GetServiceID() > 0:
@@ -33,7 +33,7 @@ func (e *engine) CreateLog(l *library.Log) (*library.Log, error) {
3333
// https://pkg.go.dev/github.com/go-vela/types/database#Log.Validate
3434
err := log.Validate()
3535
if err != nil {
36-
return nil, err
36+
return err
3737
}
3838

3939
// compress log data for the resource
@@ -43,14 +43,15 @@ func (e *engine) CreateLog(l *library.Log) (*library.Log, error) {
4343
if err != nil {
4444
switch {
4545
case l.GetServiceID() > 0:
46-
return nil, fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err)
46+
return fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err)
4747
case l.GetStepID() > 0:
48-
return nil, fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err)
48+
return fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err)
4949
}
5050
}
5151

5252
// send query to the database
53-
result := e.client.Table(constants.TableLog).Create(log)
54-
55-
return log.ToLibrary(), result.Error
53+
return e.client.
54+
Table(constants.TableLog).
55+
Create(log).
56+
Error
5657
}

database/log/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ VALUES ($1,$2,$3,$4,$5,$6) RETURNING "id"`).
7373
for _, test := range tests {
7474
t.Run(test.name, func(t *testing.T) {
7575
for _, log := range test.logs {
76-
_, err := test.database.CreateLog(log)
76+
err := test.database.CreateLog(log)
7777

7878
if test.failure {
7979
if err == nil {

0 commit comments

Comments
 (0)