Skip to content

Commit 90dcbc7

Browse files
feat: ttl-delete audit log entries (#7450)
<!-- Describe what has changed in this PR --> **What changed?** Adds domain-id based TTL for domain-audit log entries, since automated testing domains are fairly noisy and probably of fairly limited value beyond a short period of time. <!-- Tell your future self why have you made these changes --> **Why?** <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes** --------- Signed-off-by: David Porter <[email protected]>
1 parent 1ac5d43 commit 90dcbc7

File tree

9 files changed

+28
-1
lines changed

9 files changed

+28
-1
lines changed

common/dynamicconfig/dynamicproperties/constants.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,13 @@ const (
29612961
// Allowed filters: domainName, taskListName, taskListType
29622962
TaskIsolationPollerWindow
29632963

2964+
// DomainAuditLogTTL is the TTL for domain audit log entries
2965+
// KeyName: system.domainAuditLogTTL
2966+
// Value type: Duration
2967+
// Default value: 365 days (1 year)
2968+
// Allowed filters: DomainID
2969+
DomainAuditLogTTL
2970+
29642971
// LastDurationKey must be the last one in this const group
29652972
LastDurationKey
29662973
)
@@ -5491,6 +5498,12 @@ var DurationKeys = map[DurationKey]DynamicDuration{
54915498
Description: "TaskIsolationDuration is the time period for which we attempt to respect tasklist isolation before allowing any poller to process the task",
54925499
DefaultValue: time.Second * 2,
54935500
},
5501+
DomainAuditLogTTL: {
5502+
KeyName: "system.domainAuditLogTTL",
5503+
Filters: []Filter{DomainID},
5504+
Description: "DomainAuditLogTTL is the TTL for domain audit log entries",
5505+
DefaultValue: time.Hour * 24 * 365, // 1 year
5506+
},
54945507
}
54955508

54965509
var MapKeys = map[MapKey]DynamicMap{

common/persistence/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type (
3636
ReadNoSQLHistoryTaskFromDataBlob dynamicproperties.BoolPropertyFn
3737
ReadNoSQLShardFromDataBlob dynamicproperties.BoolPropertyFn
3838
SerializationEncoding dynamicproperties.StringPropertyFn
39+
DomainAuditLogTTL dynamicproperties.DurationPropertyFnWithDomainIDFilter
3940
}
4041
)
4142

@@ -50,5 +51,6 @@ func NewDynamicConfiguration(dc *dynamicconfig.Collection) *DynamicConfiguration
5051
ReadNoSQLHistoryTaskFromDataBlob: dc.GetBoolProperty(dynamicproperties.ReadNoSQLHistoryTaskFromDataBlob),
5152
ReadNoSQLShardFromDataBlob: dc.GetBoolProperty(dynamicproperties.ReadNoSQLShardFromDataBlob),
5253
SerializationEncoding: dc.GetStringProperty(dynamicproperties.SerializationEncoding),
54+
DomainAuditLogTTL: dc.GetDurationPropertyFilteredByDomainID(dynamicproperties.DomainAuditLogTTL),
5355
}
5456
}

common/persistence/data_store_interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ type (
887887
Identity string
888888
IdentityType string
889889
Comment string
890+
TTLSeconds int64 // TTL for the audit log entry in seconds
890891
}
891892

892893
// InternalGetDomainAuditLogsResponse is the response for GetDomainAuditLogs

common/persistence/domain_audit_manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func (m *domainAuditManagerImpl) CreateDomainAuditLog(
112112
stateAfterBlob = blob
113113
}
114114

115+
// Get TTL from dynamic config using domain ID
116+
ttlDuration := m.dc.DomainAuditLogTTL(request.DomainID)
117+
115118
return m.persistence.CreateDomainAuditLog(ctx, &InternalCreateDomainAuditLogRequest{
116119
DomainID: request.DomainID,
117120
EventID: request.EventID,
@@ -123,6 +126,7 @@ func (m *domainAuditManagerImpl) CreateDomainAuditLog(
123126
Identity: request.Identity,
124127
IdentityType: request.IdentityType,
125128
Comment: request.Comment,
129+
TTLSeconds: int64(ttlDuration.Seconds()),
126130
})
127131
}
128132

common/persistence/nosql/nosql_domain_audit_store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (m *nosqlDomainAuditStore) CreateDomainAuditLog(
6969
Identity: request.Identity,
7070
IdentityType: request.IdentityType,
7171
Comment: request.Comment,
72+
TTLSeconds: request.TTLSeconds,
7273
}
7374

7475
err := m.db.InsertDomainAuditLog(ctx, row)

common/persistence/nosql/nosqlplugin/cassandra/domain_audit_log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
templateInsertDomainAuditLogQuery = `INSERT INTO domain_audit_log (` +
3333
`domain_id, event_id, state_before, state_before_encoding, state_after, state_after_encoding, ` +
3434
`operation_type, created_time, last_updated_time, identity, identity_type, comment) ` +
35-
`VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
35+
`VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) USING TTL ?`
3636

3737
templateSelectDomainAuditLogsQuery = `SELECT ` +
3838
`event_id, domain_id, state_before, state_before_encoding, state_after, state_after_encoding, ` +
@@ -57,6 +57,7 @@ func (db *CDB) InsertDomainAuditLog(ctx context.Context, row *nosqlplugin.Domain
5757
row.Identity,
5858
row.IdentityType,
5959
row.Comment,
60+
row.TTLSeconds,
6061
).WithContext(ctx)
6162

6263
err := query.Exec()

common/persistence/nosql/nosqlplugin/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ type (
265265
Identity string
266266
IdentityType string
267267
Comment string
268+
TTLSeconds int64 // TTL for the audit log entry in seconds
268269
}
269270

270271
// DomainAuditLogFilter contains the filter criteria for querying domain audit logs

common/persistence/persistence-tests/persistenceTestBase.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func NewTestBaseWithNoSQL(t *testing.T, options *TestBaseOptions) *TestBase {
160160
ReadNoSQLHistoryTaskFromDataBlob: dynamicproperties.GetBoolPropertyFn(false),
161161
SerializationEncoding: dynamicproperties.GetStringPropertyFn(string(constants.EncodingTypeThriftRW)),
162162
ReadNoSQLShardFromDataBlob: dynamicproperties.GetBoolPropertyFn(true),
163+
DomainAuditLogTTL: func(domainID string) time.Duration { return time.Hour * 24 * 365 }, // 1 year default
163164
}
164165
params := TestBaseParams{
165166
DefaultTestCluster: testCluster,
@@ -192,6 +193,7 @@ func NewTestBaseWithSQL(t *testing.T, options *TestBaseOptions) *TestBase {
192193
ReadNoSQLHistoryTaskFromDataBlob: dynamicproperties.GetBoolPropertyFn(false),
193194
SerializationEncoding: dynamicproperties.GetStringPropertyFn(string(constants.EncodingTypeThriftRW)),
194195
ReadNoSQLShardFromDataBlob: dynamicproperties.GetBoolPropertyFn(true),
196+
DomainAuditLogTTL: func(domainID string) time.Duration { return time.Hour * 24 * 365 }, // 1 year default
195197
}
196198
params := TestBaseParams{
197199
DefaultTestCluster: testCluster,

config/dynamicconfig/development.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ system.writeVisibilityStoreName:
7171
- value: "db"
7272
system.readVisibilityStoreName:
7373
- value: "db"
74+
system.domainAuditLogTTL:
75+
- value: "15m"
7476
matching.enableClientAutoConfig:
7577
- value: true
7678
shardDistributor.MigrationMode:

0 commit comments

Comments
 (0)