Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/213 add names and descriptions to reporting #217

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/reporter/downstream_reporter/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func (cacheReporter *Cache) ReportWorkflowStart(executionId uuid.UUID, playbook
newExecutionEntry := cache_report.ExecutionEntry{
ExecutionId: executionId,
PlaybookId: playbook.ID,
Name: playbook.Name,
Description: playbook.Description,
Started: cacheReporter.timeUtil.Now(),
Ended: time.Time{},
StepResults: map[string]cache_report.StepResult{},
Expand Down Expand Up @@ -266,6 +268,8 @@ func (cacheReporter *Cache) ReportStepStart(executionId uuid.UUID, step cacao.St
newStep := cache_report.StepResult{
ExecutionId: executionId,
StepId: step.ID,
Name: step.Name,
Description: step.Description,
Started: cacheReporter.timeUtil.Now(),
Ended: time.Time{},
Variables: variables,
Expand Down
4 changes: 4 additions & 0 deletions models/api/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
)

type PlaybookExecutionReport struct {
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
Type string `bson:"type" json:"type"`
ExecutionId string `bson:"execution_id" json:"execution_id"`
PlaybookId string `bson:"playbook_id" json:"playbook_id"`
Expand All @@ -46,6 +48,8 @@ type PlaybookExecutionReport struct {
}

type StepExecutionReport struct {
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
ExecutionId string `bson:"execution_id" json:"execution_id"`
StepId string `bson:"step_id" json:"step_id"`
Started time.Time `bson:"started" json:"started"`
Expand Down
4 changes: 4 additions & 0 deletions models/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (status Status) String() string {

type ExecutionEntry struct {
ExecutionId uuid.UUID
Name string
Description string
PlaybookId string
Started time.Time
Ended time.Time
Expand All @@ -46,6 +48,8 @@ type ExecutionEntry struct {
type StepResult struct {
ExecutionId uuid.UUID
StepId string
Name string
Description string
Started time.Time
Ended time.Time
// Make sure we can have a playbookID for playbook actions, and also
Expand Down
4 changes: 4 additions & 0 deletions routes/reporter/reporter_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func parseCachePlaybookEntry(cacheEntry cache_model.ExecutionEntry) (api_model.P

executionReport := api_model.PlaybookExecutionReport{
Type: "execution_status",
Name: cacheEntry.Name,
Description: cacheEntry.Description,
ExecutionId: cacheEntry.ExecutionId.String(),
PlaybookId: cacheEntry.PlaybookId,
Started: cacheEntry.Started,
Expand Down Expand Up @@ -55,6 +57,8 @@ func parseCacheStepEntries(cacheStepEntries map[string]cache_model.StepResult) (
parsedEntries[stepId] = api_model.StepExecutionReport{
ExecutionId: stepEntry.ExecutionId.String(),
StepId: stepEntry.StepId,
Name: stepEntry.Name,
Description: stepEntry.Description,
Started: stepEntry.Started,
Ended: stepEntry.Ended,
Status: stepStatus,
Expand Down
69 changes: 51 additions & 18 deletions test/unittest/reporters/downstream_reporter/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestReportWorkflowStartFirst(t *testing.T) {
Type: "action",
ID: "action--test",
Name: "ssh-tests",
Description: "test step",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Cases: map[string]string{},
Expand Down Expand Up @@ -67,7 +68,8 @@ func TestReportWorkflowStartFirst(t *testing.T) {
playbook := cacao.Playbook{
ID: "test",
Type: "test",
Name: "ssh-test",
Name: "ssh-test-playbook",
Description: "Playbook description",
WorkflowStart: step1.ID,
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
Expand All @@ -82,29 +84,49 @@ func TestReportWorkflowStartFirst(t *testing.T) {
timeNow, _ := time.Parse(layout, str)
mock_time.On("Now").Return(timeNow)

expectedExecutionEntry := cache_model.ExecutionEntry{
ExecutionId: executionId0,
PlaybookId: "test",
StepResults: map[string]cache_model.StepResult{},
Status: cache_model.Ongoing,
Started: timeNow,
Ended: time.Time{},
err := cacheReporter.ReportWorkflowStart(executionId0, playbook)
if err != nil {
t.Fail()
}

err := cacheReporter.ReportWorkflowStart(executionId0, playbook)
mock_time.On("Now").Return(timeNow)

err = cacheReporter.ReportStepStart(executionId0, step1, cacao.NewVariables(expectedVariables))
if err != nil {
t.Fail()
}

mock_time.On("Now").Return(timeNow)
err = cacheReporter.ReportStepEnd(executionId0, step1, cacao.NewVariables(), nil)
if err != nil {
t.Fail()
}

expectedStarted, _ := time.Parse(layout, "2014-11-12T11:45:26.371Z")
expectedEnded, _ := time.Parse(layout, "0001-01-01T00:00:00Z")
expetedStepReport := cache_model.StepResult{
ExecutionId: executionId0,
StepId: "action--test",
Name: "ssh-tests",
Description: "test step",
IsAutomated: true,
Started: timeNow,
Ended: timeNow,
CommandsB64: []string{b64.StdEncoding.EncodeToString([]byte(expectedCommand.Command))},
Variables: cacao.NewVariables(),
Status: cache_model.SuccessfullyExecuted,
Error: nil,
}

expectedExecutions := []cache_model.ExecutionEntry{
{
ExecutionId: executionId0,
PlaybookId: "test",
Name: "ssh-test-playbook",
Description: "Playbook description",
Started: expectedStarted,
Ended: expectedEnded,
StepResults: map[string]cache_model.StepResult{},
StepResults: map[string]cache_model.StepResult{expetedStepReport.StepId: expetedStepReport},
Error: nil,
Status: 2,
},
Expand All @@ -114,12 +136,13 @@ func TestReportWorkflowStartFirst(t *testing.T) {

exec, err := cacheReporter.GetExecutionReport(executionId0)
assert.Equal(t, expectedExecutions, returnedExecutions)
assert.Equal(t, expectedExecutionEntry.ExecutionId, exec.ExecutionId)
assert.Equal(t, expectedExecutionEntry.PlaybookId, exec.PlaybookId)
assert.Equal(t, expectedExecutionEntry.StepResults, exec.StepResults)
assert.Equal(t, expectedExecutionEntry.Started, timeNow)
assert.Equal(t, expectedExecutionEntry.Ended, time.Time{})
assert.Equal(t, expectedExecutionEntry.Status, exec.Status)
assert.Equal(t, len(expectedExecutions), 1)
assert.Equal(t, expectedExecutions[0].ExecutionId, exec.ExecutionId)
assert.Equal(t, expectedExecutions[0].PlaybookId, exec.PlaybookId)
assert.Equal(t, expectedExecutions[0].StepResults, exec.StepResults)
assert.Equal(t, expectedExecutions[0].Started, timeNow)
assert.Equal(t, expectedExecutions[0].Ended, time.Time{})
assert.Equal(t, expectedExecutions[0].Status, exec.Status)
assert.Equal(t, err, nil)
mock_time.AssertExpectations(t)
}
Expand All @@ -143,6 +166,7 @@ func TestReportWorkflowStartFifo(t *testing.T) {
Type: "action",
ID: "action--test",
Name: "ssh-tests",
Description: "step description",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Cases: map[string]string{},
Expand Down Expand Up @@ -176,7 +200,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
playbook := cacao.Playbook{
ID: "test",
Type: "test",
Name: "ssh-test",
Name: "ssh-test-playbook",
Description: "Playbook description",
WorkflowStart: step1.ID,
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
Expand Down Expand Up @@ -209,6 +234,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
entry := cache_model.ExecutionEntry{
ExecutionId: executionId,
PlaybookId: "test",
Name: "ssh-test-playbook",
Description: "Playbook description",
Started: expectedStarted,
Ended: expectedEnded,
StepResults: map[string]cache_model.StepResult{},
Expand All @@ -224,6 +251,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
entry := cache_model.ExecutionEntry{
ExecutionId: executionId,
PlaybookId: "test",
Name: "ssh-test-playbook",
Description: "Playbook description",
Started: expectedStarted,
Ended: expectedEnded,
StepResults: map[string]cache_model.StepResult{},
Expand Down Expand Up @@ -283,6 +312,7 @@ func TestReportWorkflowEnd(t *testing.T) {
Type: "action",
ID: "action--test",
Name: "ssh-tests",
Description: "step 1",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Cases: map[string]string{},
Expand Down Expand Up @@ -316,7 +346,8 @@ func TestReportWorkflowEnd(t *testing.T) {
playbook := cacao.Playbook{
ID: "test",
Type: "test",
Name: "ssh-test",
Name: "ssh-test-playbook",
Description: "Playbook description",
WorkflowStart: step1.ID,
AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth},
AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent},
Expand All @@ -343,6 +374,8 @@ func TestReportWorkflowEnd(t *testing.T) {
expectedExecutionEntry := cache_model.ExecutionEntry{
ExecutionId: executionId0,
PlaybookId: "test",
Name: "ssh-test-playbook",
Description: "Playbook description",
Started: timeNow,
Ended: timeNow,
StepResults: map[string]cache_model.StepResult{},
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/routes/reporter_api/reporter_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestGetExecutions(t *testing.T) {
Type: "execution_status",
ExecutionId: executionId.String(),
PlaybookId: "test",
Name: "ssh-test",
Started: expectedStarted,
Ended: expectedEnded,
Status: expectedStatus,
Expand Down Expand Up @@ -262,6 +263,7 @@ func TestGetExecutionReport(t *testing.T) {
"type":"execution_status",
"execution_id":"6ba7b810-9dad-11d1-80b4-00c04fd430c0",
"playbook_id":"test",
"name":"ssh-test",
"started":"2014-11-12T11:45:26.371Z",
"ended":"0001-01-01T00:00:00Z",
"status":"ongoing",
Expand All @@ -270,6 +272,7 @@ func TestGetExecutionReport(t *testing.T) {
"action--test":{
"execution_id":"6ba7b810-9dad-11d1-80b4-00c04fd430c0",
"step_id":"action--test",
"name":"ssh-tests",
"started":"2014-11-12T11:45:26.371Z",
"ended":"2014-11-12T11:45:26.371Z",
"status":"successfully_executed",
Expand Down