Skip to content

Commit

Permalink
add more timestamps where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaguilar committed May 2, 2024
1 parent f68c7bf commit 295d08e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
16 changes: 13 additions & 3 deletions pkg/api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down
80 changes: 50 additions & 30 deletions pkg/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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,
})
}
}
Expand All @@ -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"`
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 295d08e

Please sign in to comment.