Skip to content

Commit c7d2a47

Browse files
Feature/213 add names and descriptions to reporting (#217)
1 parent ad8e139 commit c7d2a47

File tree

6 files changed

+70
-18
lines changed

6 files changed

+70
-18
lines changed

internal/reporter/downstream_reporter/cache/cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ func (cacheReporter *Cache) ReportWorkflowStart(executionId uuid.UUID, playbook
229229
newExecutionEntry := cache_report.ExecutionEntry{
230230
ExecutionId: executionId,
231231
PlaybookId: playbook.ID,
232+
Name: playbook.Name,
233+
Description: playbook.Description,
232234
Started: cacheReporter.timeUtil.Now(),
233235
Ended: time.Time{},
234236
StepResults: map[string]cache_report.StepResult{},
@@ -266,6 +268,8 @@ func (cacheReporter *Cache) ReportStepStart(executionId uuid.UUID, step cacao.St
266268
newStep := cache_report.StepResult{
267269
ExecutionId: executionId,
268270
StepId: step.ID,
271+
Name: step.Name,
272+
Description: step.Description,
269273
Started: cacheReporter.timeUtil.Now(),
270274
Ended: time.Time{},
271275
Variables: variables,

models/api/reporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const (
3434
)
3535

3636
type PlaybookExecutionReport struct {
37+
Name string `bson:"name" json:"name"`
38+
Description string `bson:"description" json:"description"`
3739
Type string `bson:"type" json:"type"`
3840
ExecutionId string `bson:"execution_id" json:"execution_id"`
3941
PlaybookId string `bson:"playbook_id" json:"playbook_id"`
@@ -46,6 +48,8 @@ type PlaybookExecutionReport struct {
4648
}
4749

4850
type StepExecutionReport struct {
51+
Name string `bson:"name" json:"name"`
52+
Description string `bson:"description" json:"description"`
4953
ExecutionId string `bson:"execution_id" json:"execution_id"`
5054
StepId string `bson:"step_id" json:"step_id"`
5155
Started time.Time `bson:"started" json:"started"`

models/cache/cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func (status Status) String() string {
3535

3636
type ExecutionEntry struct {
3737
ExecutionId uuid.UUID
38+
Name string
39+
Description string
3840
PlaybookId string
3941
Started time.Time
4042
Ended time.Time
@@ -46,6 +48,8 @@ type ExecutionEntry struct {
4648
type StepResult struct {
4749
ExecutionId uuid.UUID
4850
StepId string
51+
Name string
52+
Description string
4953
Started time.Time
5054
Ended time.Time
5155
// Make sure we can have a playbookID for playbook actions, and also

routes/reporter/reporter_parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func parseCachePlaybookEntry(cacheEntry cache_model.ExecutionEntry) (api_model.P
2525

2626
executionReport := api_model.PlaybookExecutionReport{
2727
Type: "execution_status",
28+
Name: cacheEntry.Name,
29+
Description: cacheEntry.Description,
2830
ExecutionId: cacheEntry.ExecutionId.String(),
2931
PlaybookId: cacheEntry.PlaybookId,
3032
Started: cacheEntry.Started,
@@ -55,6 +57,8 @@ func parseCacheStepEntries(cacheStepEntries map[string]cache_model.StepResult) (
5557
parsedEntries[stepId] = api_model.StepExecutionReport{
5658
ExecutionId: stepEntry.ExecutionId.String(),
5759
StepId: stepEntry.StepId,
60+
Name: stepEntry.Name,
61+
Description: stepEntry.Description,
5862
Started: stepEntry.Started,
5963
Ended: stepEntry.Ended,
6064
Status: stepStatus,

test/unittest/reporters/downstream_reporter/cache_test.go

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestReportWorkflowStartFirst(t *testing.T) {
3434
Type: "action",
3535
ID: "action--test",
3636
Name: "ssh-tests",
37+
Description: "test step",
3738
StepVariables: cacao.NewVariables(expectedVariables),
3839
Commands: []cacao.Command{expectedCommand},
3940
Cases: map[string]string{},
@@ -67,7 +68,8 @@ func TestReportWorkflowStartFirst(t *testing.T) {
6768
playbook := cacao.Playbook{
6869
ID: "test",
6970
Type: "test",
70-
Name: "ssh-test",
71+
Name: "ssh-test-playbook",
72+
Description: "Playbook description",
7173
WorkflowStart: step1.ID,
7274
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
7375
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
@@ -82,29 +84,49 @@ func TestReportWorkflowStartFirst(t *testing.T) {
8284
timeNow, _ := time.Parse(layout, str)
8385
mock_time.On("Now").Return(timeNow)
8486

85-
expectedExecutionEntry := cache_model.ExecutionEntry{
86-
ExecutionId: executionId0,
87-
PlaybookId: "test",
88-
StepResults: map[string]cache_model.StepResult{},
89-
Status: cache_model.Ongoing,
90-
Started: timeNow,
91-
Ended: time.Time{},
87+
err := cacheReporter.ReportWorkflowStart(executionId0, playbook)
88+
if err != nil {
89+
t.Fail()
9290
}
9391

94-
err := cacheReporter.ReportWorkflowStart(executionId0, playbook)
92+
mock_time.On("Now").Return(timeNow)
93+
94+
err = cacheReporter.ReportStepStart(executionId0, step1, cacao.NewVariables(expectedVariables))
95+
if err != nil {
96+
t.Fail()
97+
}
98+
99+
mock_time.On("Now").Return(timeNow)
100+
err = cacheReporter.ReportStepEnd(executionId0, step1, cacao.NewVariables(), nil)
95101
if err != nil {
96102
t.Fail()
97103
}
98104

99105
expectedStarted, _ := time.Parse(layout, "2014-11-12T11:45:26.371Z")
100106
expectedEnded, _ := time.Parse(layout, "0001-01-01T00:00:00Z")
107+
expetedStepReport := cache_model.StepResult{
108+
ExecutionId: executionId0,
109+
StepId: "action--test",
110+
Name: "ssh-tests",
111+
Description: "test step",
112+
IsAutomated: true,
113+
Started: timeNow,
114+
Ended: timeNow,
115+
CommandsB64: []string{b64.StdEncoding.EncodeToString([]byte(expectedCommand.Command))},
116+
Variables: cacao.NewVariables(),
117+
Status: cache_model.SuccessfullyExecuted,
118+
Error: nil,
119+
}
120+
101121
expectedExecutions := []cache_model.ExecutionEntry{
102122
{
103123
ExecutionId: executionId0,
104124
PlaybookId: "test",
125+
Name: "ssh-test-playbook",
126+
Description: "Playbook description",
105127
Started: expectedStarted,
106128
Ended: expectedEnded,
107-
StepResults: map[string]cache_model.StepResult{},
129+
StepResults: map[string]cache_model.StepResult{expetedStepReport.StepId: expetedStepReport},
108130
Error: nil,
109131
Status: 2,
110132
},
@@ -114,12 +136,13 @@ func TestReportWorkflowStartFirst(t *testing.T) {
114136

115137
exec, err := cacheReporter.GetExecutionReport(executionId0)
116138
assert.Equal(t, expectedExecutions, returnedExecutions)
117-
assert.Equal(t, expectedExecutionEntry.ExecutionId, exec.ExecutionId)
118-
assert.Equal(t, expectedExecutionEntry.PlaybookId, exec.PlaybookId)
119-
assert.Equal(t, expectedExecutionEntry.StepResults, exec.StepResults)
120-
assert.Equal(t, expectedExecutionEntry.Started, timeNow)
121-
assert.Equal(t, expectedExecutionEntry.Ended, time.Time{})
122-
assert.Equal(t, expectedExecutionEntry.Status, exec.Status)
139+
assert.Equal(t, len(expectedExecutions), 1)
140+
assert.Equal(t, expectedExecutions[0].ExecutionId, exec.ExecutionId)
141+
assert.Equal(t, expectedExecutions[0].PlaybookId, exec.PlaybookId)
142+
assert.Equal(t, expectedExecutions[0].StepResults, exec.StepResults)
143+
assert.Equal(t, expectedExecutions[0].Started, timeNow)
144+
assert.Equal(t, expectedExecutions[0].Ended, time.Time{})
145+
assert.Equal(t, expectedExecutions[0].Status, exec.Status)
123146
assert.Equal(t, err, nil)
124147
mock_time.AssertExpectations(t)
125148
}
@@ -143,6 +166,7 @@ func TestReportWorkflowStartFifo(t *testing.T) {
143166
Type: "action",
144167
ID: "action--test",
145168
Name: "ssh-tests",
169+
Description: "step description",
146170
StepVariables: cacao.NewVariables(expectedVariables),
147171
Commands: []cacao.Command{expectedCommand},
148172
Cases: map[string]string{},
@@ -176,7 +200,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
176200
playbook := cacao.Playbook{
177201
ID: "test",
178202
Type: "test",
179-
Name: "ssh-test",
203+
Name: "ssh-test-playbook",
204+
Description: "Playbook description",
180205
WorkflowStart: step1.ID,
181206
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
182207
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
@@ -209,6 +234,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
209234
entry := cache_model.ExecutionEntry{
210235
ExecutionId: executionId,
211236
PlaybookId: "test",
237+
Name: "ssh-test-playbook",
238+
Description: "Playbook description",
212239
Started: expectedStarted,
213240
Ended: expectedEnded,
214241
StepResults: map[string]cache_model.StepResult{},
@@ -224,6 +251,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
224251
entry := cache_model.ExecutionEntry{
225252
ExecutionId: executionId,
226253
PlaybookId: "test",
254+
Name: "ssh-test-playbook",
255+
Description: "Playbook description",
227256
Started: expectedStarted,
228257
Ended: expectedEnded,
229258
StepResults: map[string]cache_model.StepResult{},
@@ -283,6 +312,7 @@ func TestReportWorkflowEnd(t *testing.T) {
283312
Type: "action",
284313
ID: "action--test",
285314
Name: "ssh-tests",
315+
Description: "step 1",
286316
StepVariables: cacao.NewVariables(expectedVariables),
287317
Commands: []cacao.Command{expectedCommand},
288318
Cases: map[string]string{},
@@ -316,7 +346,8 @@ func TestReportWorkflowEnd(t *testing.T) {
316346
playbook := cacao.Playbook{
317347
ID: "test",
318348
Type: "test",
319-
Name: "ssh-test",
349+
Name: "ssh-test-playbook",
350+
Description: "Playbook description",
320351
WorkflowStart: step1.ID,
321352
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
322353
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
@@ -343,6 +374,8 @@ func TestReportWorkflowEnd(t *testing.T) {
343374
expectedExecutionEntry := cache_model.ExecutionEntry{
344375
ExecutionId: executionId0,
345376
PlaybookId: "test",
377+
Name: "ssh-test-playbook",
378+
Description: "Playbook description",
346379
Started: timeNow,
347380
Ended: timeNow,
348381
StepResults: map[string]cache_model.StepResult{},

test/unittest/routes/reporter_api/reporter_api_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestGetExecutions(t *testing.T) {
109109
Type: "execution_status",
110110
ExecutionId: executionId.String(),
111111
PlaybookId: "test",
112+
Name: "ssh-test",
112113
Started: expectedStarted,
113114
Ended: expectedEnded,
114115
Status: expectedStatus,
@@ -262,6 +263,7 @@ func TestGetExecutionReport(t *testing.T) {
262263
"type":"execution_status",
263264
"execution_id":"6ba7b810-9dad-11d1-80b4-00c04fd430c0",
264265
"playbook_id":"test",
266+
"name":"ssh-test",
265267
"started":"2014-11-12T11:45:26.371Z",
266268
"ended":"0001-01-01T00:00:00Z",
267269
"status":"ongoing",
@@ -270,6 +272,7 @@ func TestGetExecutionReport(t *testing.T) {
270272
"action--test":{
271273
"execution_id":"6ba7b810-9dad-11d1-80b4-00c04fd430c0",
272274
"step_id":"action--test",
275+
"name":"ssh-tests",
273276
"started":"2014-11-12T11:45:26.371Z",
274277
"ended":"2014-11-12T11:45:26.371Z",
275278
"status":"successfully_executed",

0 commit comments

Comments
 (0)