diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index e275289..49ee093 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -12,7 +12,7 @@ import ( func resourceLog(db *gorm.DB, taskUUID string) *gorm.DB { return db.Table("tfo_task_logs"). - Select("message"). + Select("message, updated_at, created_at"). Where("task_pod_uuid = ?", taskUUID) } @@ -56,7 +56,14 @@ func allTasksGeneratedForResource(db *gorm.DB, tfoResourceUUID, generation strin func resourceSpec(db *gorm.DB, uuid, generation string) *gorm.DB { return db.Table("tfo_resource_specs"). - Select("generation, resource_spec, annotations, labels"). + Select(` + generation, + resource_spec, + annotations, + labels, + created_at, + updated_at + `). Where("tfo_resource_uuid = ? and generation = ?", uuid, generation) } @@ -68,7 +75,10 @@ func approvalQuery(db *gorm.DB, uuid string) *gorm.DB { func workflow(db *gorm.DB, clusterName uint, namespace, name string) *gorm.DB { return db.Table("tfo_resources"). - Select("tfo_resources.*, clusters.name AS cluster_name"). + Select(` + tfo_resources.*, + clusters.name AS cluster_name + `). Joins("JOIN clusters ON tfo_resources.cluster_id = clusters.id"). Where("tfo_resources.deleted_at is null and tfo_resources.cluster_id = ? and tfo_resources.namespace = ? and tfo_resources.name = ?", clusterName, namespace, name) } diff --git a/pkg/api/resource.go b/pkg/api/resource.go index a1c426e..f521258 100644 --- a/pkg/api/resource.go +++ b/pkg/api/resource.go @@ -734,8 +734,12 @@ func logs(db *gorm.DB, tfoResourceUUID string, generation string) []TaskLog { var logs []TaskLog for _, task := range filteredData { - message := "" - if result := resourceLog(db, task.UUID).Scan(&message); result.Error == nil { + log := struct { + Message string + CreatedAt time.Time + UpdatedAt time.Time + }{} + if result := resourceLog(db, task.UUID).Scan(&log); result.Error == nil { taskID := -1 switch task.TaskType { case "setup": @@ -783,12 +787,12 @@ func logs(db *gorm.DB, tfoResourceUUID string, generation string) []TaskLog { } logs = append(logs, TaskLog{ UUID: task.UUID, - Message: message, + Message: log.Message, TaskType: task.TaskType, Rerun: task.Rerun, TaskID: taskID, - CreatedAt: task.CreatedAt, - UpdatedAt: task.UpdatedAt, + CreatedAt: log.CreatedAt, + UpdatedAt: log.UpdatedAt, }) } } @@ -811,41 +815,53 @@ func (h APIHandler) getWorkflowInfo(c *gin.Context) { } var tfoResourcesData []struct { - Name string `json:"name"` - Namespace string `json:"namespace"` - ClusterName string `json:"cluster_name"` - CurrentState string `json:"state"` - UUID string `json:"uuid"` - CurrentGeneration string `json:"current_generation"` + Name string `json:"name"` + Namespace string `json:"namespace"` + ClusterName string `json:"cluster_name"` + CurrentState string `json:"state"` + UUID string `json:"uuid"` + CurrentGeneration string `json:"current_generation"` + UpdatedAt time.Time `json:"updated_at"` + CreatedAt time.Time `json:"created_at"` } var tfoResourceSpecsData []struct { - ResourceSpec string `json:"resource_spec"` - Annotations string `json:"annotations"` - Labels string `json:"labels"` + ResourceSpec string `json:"resource_spec"` + Annotations string `json:"annotations"` + Labels string `json:"labels"` + UpdatedAt time.Time `json:"updated_at"` + CreatedAt time.Time `json:"created_at"` } type task struct { - UUID string `json:"uuid"` - TaskType string `json:"task_type"` - Rerun int `json:"rerun"` - InClusterGeneration string `json:"in_cluster_generation"` + UUID string `json:"uuid"` + TaskType string `json:"task_type"` + Rerun int `json:"rerun"` + InClusterGeneration string `json:"in_cluster_generation"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } var tasks []task var approvals []struct { - IsApproved bool `json:"is_approved"` - TaskPodUUID string `json:"task_pod_uuid"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + IsApproved bool `json:"is_approved"` + TaskPodUUID string `json:"task_pod_uuid"` } type ResponseItem struct { - Name string `json:"name"` - Namespace string `json:"namespace"` - ClusterName string `json:"cluster_name"` - CurrentState string `json:"state"` - UUID string `json:"uuid"` - QueryGeneration string `json:"query_generation"` - CurrentGeneration string `json:"current_generation"` - ResourceSpec string `json:"resource_spec"` - Annotations string `json:"annotations"` - Labels string `json:"labels"` + Name string `json:"name"` + Namespace string `json:"namespace"` + ClusterName string `json:"cluster_name"` + CurrentState string `json:"state"` + UUID string `json:"uuid"` + QueryGeneration string `json:"query_generation"` + CurrentGeneration string `json:"current_generation"` + ResourceSpec string `json:"resource_spec"` + Annotations string `json:"annotations"` + Labels string `json:"labels"` + UpdatedAt time.Time `json:"updated_at"` + CreatedAt time.Time `json:"created_at"` + ResourceSpecCreatedAt time.Time `json:"resource_spec_created_at"` + ResourceSpecUpdatedAt time.Time `json:"resource_spec_updated_at"` Tasks []task `json:"tasks"` IsApproved *bool `json:"is_approved"` @@ -874,6 +890,8 @@ func (h APIHandler) getWorkflowInfo(c *gin.Context) { finalResult[0].CurrentGeneration = tfoResourcesData[0].CurrentGeneration finalResult[0].QueryGeneration = generation finalResult[0].UUID = resourceUUID + finalResult[0].CreatedAt = tfoResourcesData[0].CreatedAt + finalResult[0].UpdatedAt = tfoResourcesData[0].UpdatedAt queryResult = resourceSpec(h.DB, resourceUUID, generation).Scan(&tfoResourceSpecsData) if queryResult.Error != nil { @@ -888,6 +906,8 @@ func (h APIHandler) getWorkflowInfo(c *gin.Context) { finalResult[0].ResourceSpec = tfoResourceSpecsData[0].ResourceSpec finalResult[0].Annotations = tfoResourceSpecsData[0].Annotations finalResult[0].Labels = tfoResourceSpecsData[0].Labels + finalResult[0].ResourceSpecCreatedAt = tfoResourceSpecsData[0].CreatedAt + finalResult[0].ResourceSpecUpdatedAt = tfoResourceSpecsData[0].UpdatedAt queryResult = allTasksGeneratedForResource(h.DB, resourceUUID, generation).Scan(&tasks) if queryResult.Error != nil {