Skip to content

Commit ca461a3

Browse files
authored
Change VisibilityRow execution duration type to int64 (#10524)
## What changed? Change `VisibilityRow.ExecutionDuration` type from `*time.Duration` to `*int64`. ## Why? `time.Duration` is not always translated correctly to integer values when inserting into the database (eg: `jackc/pgx` module with connection attributes `default_query_exec_mode: simple_protocol` translates `time.Duration` into a string instead of an integer). Furthermore, the VisibilityRow is meant to represent the values from DB, so making it `int64` also makes it more explicitly. #10514 ## How did you test it? - [x] built - [x] run locally and tested manually - [x] covered by existing tests (updated existing tests) - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Users implementing their own `VisibilityStore` based on the SQL implementation which uses the `VisibilityRow` might need to double check their code.
1 parent 93056af commit ca461a3

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

common/persistence/sql/sqlplugin/tests/visibility.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,9 +1395,9 @@ func (s *visibilitySuite) newRandomVisibilityRow(
13951395
historyLength *int64,
13961396
) sqlplugin.VisibilityRow {
13971397
s.version++
1398-
var executionDuration *time.Duration
1398+
var executionDuration *int64
13991399
if closeTime != nil {
1400-
executionDuration = new(closeTime.Sub(executionTime))
1400+
executionDuration = new(closeTime.Sub(executionTime).Nanoseconds())
14011401
}
14021402
return sqlplugin.VisibilityRow{
14031403
NamespaceID: namespaceID.String(),

common/persistence/sql/sqlplugin/visibility.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type (
3939
CloseTime *time.Time
4040
HistoryLength *int64
4141
HistorySizeBytes *int64
42-
ExecutionDuration *time.Duration
42+
ExecutionDuration *int64
4343
StateTransitionCount *int64
4444
Memo []byte
4545
Encoding string

common/persistence/visibility/store/sql/visibility_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (s *VisibilityStore) RecordWorkflowExecutionClosed(
136136
row.CloseTime = &request.CloseTime
137137
row.HistoryLength = &request.HistoryLength
138138
row.HistorySizeBytes = &request.HistorySizeBytes
139-
row.ExecutionDuration = &request.ExecutionDuration
139+
row.ExecutionDuration = new(request.ExecutionDuration.Nanoseconds())
140140
row.StateTransitionCount = &request.StateTransitionCount
141141

142142
result, err := s.sqlStore.DB.ReplaceIntoVisibility(ctx, row)
@@ -852,7 +852,7 @@ func (s *VisibilityStore) rowToInfo(
852852
info.CloseTime = *row.CloseTime
853853
}
854854
if row.ExecutionDuration != nil {
855-
info.ExecutionDuration = *row.ExecutionDuration
855+
info.ExecutionDuration = time.Duration(*row.ExecutionDuration)
856856
}
857857
if row.HistoryLength != nil {
858858
info.HistoryLength = *row.HistoryLength

0 commit comments

Comments
 (0)