Skip to content

Commit

Permalink
fix: use *time.Time to represent finish time (chaos-mesh#4056)
Browse files Browse the repository at this point in the history
* fix: use `*time.Time` to represent finish time

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Update CHANGELOG.md

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

---------

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
  • Loading branch information
g1eny0ung authored and xlgao-zju committed Jun 19, 2023
1 parent c713634 commit d86a8ec
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ For more information and how-to, see [RFC: Keep A Changelog](https://github.com/

- Fix version comparison in install.sh [#3901](https://github.com/chaos-mesh/chaos-mesh/pull/3901)
- Fix stuck dashboard updates when using ReadWriteOnce PVCs [#3876](https://github.com/chaos-mesh/chaos-mesh/issues/3876)
- Fix MySQL NO_ZERO_IN_DATE by using `*time.Time` to represent finish time [#4056](https://github.com/chaos-mesh/chaos-mesh/pull/4056)

### Security

Expand Down
5 changes: 4 additions & 1 deletion pkg/config/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ type ChaosDashboardConfig struct {

// DatabaseConfig defines the configuration for databases
type DatabaseConfig struct {
Driver string `envconfig:"DATABASE_DRIVER" default:"sqlite3"`
Driver string `envconfig:"DATABASE_DRIVER" default:"sqlite3"`
// Datasource is the connection string for database.
// For sqlite3, it is the path of the database file.
// For mysql, it is the DSN (https://github.com/go-sql-driver/mysql#dsn-data-source-name).
Datasource string `envconfig:"DATABASE_DATASOURCE" default:"core.sqlite"`
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/dashboard/apiserver/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *MockExperimentStore) ListMeta(ctx context.Context, kind, namespace, nam
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
}
res = append(res, expMeta)
Expand All @@ -90,7 +90,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -106,7 +106,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -122,7 +122,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -138,7 +138,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -154,7 +154,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -170,7 +170,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: string(jsonStr),
Expand All @@ -184,7 +184,7 @@ func (m *MockExperimentStore) FindByUID(ctx context.Context, UID string) (*core.
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Experiment: "",
Expand All @@ -209,7 +209,7 @@ func (m *MockExperimentStore) FindMetaByUID(ctx context.Context, UID string) (*c
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
}
case "testErrRecordNotFound":
Expand Down Expand Up @@ -259,7 +259,7 @@ func (m *MockScheduleStore) ListMeta(ctx context.Context, namespace, name string
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
}
res = append(res, schMeta)
Expand All @@ -284,7 +284,7 @@ func (m *MockScheduleStore) FindByUID(ctx context.Context, UID string) (*core.Sc
Namespace: "testNamespace",
Action: "testAction",
StartTime: time.Time{},
FinishTime: time.Time{},
FinishTime: &time.Time{},
Archived: true,
},
Schedule: string(jsonStr),
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func convertInnerObjectToExperiment(obj v1alpha1.InnerObject) (*core.Experiment,

archive.StartTime = chaosMeta.GetCreationTimestamp().Time
if chaosMeta.GetDeletionTimestamp() != nil {
archive.FinishTime = chaosMeta.GetDeletionTimestamp().Time
archive.FinishTime = &chaosMeta.GetDeletionTimestamp().Time
}

data, err := json.Marshal(chaosMeta)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/collector/schedule_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *ScheduleCollector) setUnarchivedSchedule(req ctrl.Request, schedule v1a

archive.StartTime = schedule.GetCreationTimestamp().Time
if schedule.GetDeletionTimestamp() != nil {
archive.FinishTime = schedule.GetDeletionTimestamp().Time
archive.FinishTime = &schedule.GetDeletionTimestamp().Time
}

data, err := json.Marshal(schedule)
Expand Down
16 changes: 8 additions & 8 deletions pkg/dashboard/core/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ type Experiment struct {
// ExperimentMeta defines the metadata of an experiment. Use in db.
type ExperimentMeta struct {
gorm.Model
UID string `gorm:"index:uid" json:"uid"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Action string `json:"action"`
StartTime time.Time `json:"start_time"`
FinishTime time.Time `json:"finish_time"`
Archived bool `json:"archived"`
UID string `gorm:"index:uid" json:"uid"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Action string `json:"action"`
StartTime time.Time `json:"start_time"`
FinishTime *time.Time `json:"finish_time"`
Archived bool `json:"archived"`
}
16 changes: 8 additions & 8 deletions pkg/dashboard/core/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ type Schedule struct {
// ScheduleMeta defines the metadata of a schedule instance. Use in db.
type ScheduleMeta struct {
gorm.Model
UID string `gorm:"index:schedule_uid" json:"uid"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Action string `json:"action"`
StartTime time.Time `json:"start_time"`
FinishTime time.Time `json:"finish_time"`
Archived bool `json:"archived"`
UID string `gorm:"index:schedule_uid" json:"uid"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Action string `json:"action"`
StartTime time.Time `json:"start_time"`
FinishTime *time.Time `json:"finish_time"`
Archived bool `json:"archived"`
}
4 changes: 2 additions & 2 deletions pkg/dashboard/core/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type WorkflowMeta struct {
Entry string `json:"entry"` // the entry node name
CreatedAt time.Time `json:"created_at"`
// FinishTime represents the time when the workflow was deleted from Kubernetes.
FinishTime time.Time `json:"finish_time"`
FinishTime *time.Time `json:"finish_time"`
// EndTime represents the time when the workflow completed all steps.
EndTime string `json:"end_time"`
Status WorkflowStatus `json:"status,omitempty"`
Expand Down Expand Up @@ -261,7 +261,7 @@ func convertWorkflow(kubeWorkflow v1alpha1.Workflow) WorkflowMeta {
}

if kubeWorkflow.GetDeletionTimestamp() != nil {
result.FinishTime = kubeWorkflow.GetDeletionTimestamp().Time
result.FinishTime = &kubeWorkflow.GetDeletionTimestamp().Time
}

if wfcontrollers.WorkflowConditionEqualsTo(kubeWorkflow.Status, v1alpha1.WorkflowConditionAccomplished, corev1.ConditionTrue) {
Expand Down

0 comments on commit d86a8ec

Please sign in to comment.