Skip to content

Commit 372dd4d

Browse files
c-warrengazi-yestemirova
authored andcommitted
feat: Add domain audit table (#7376)
<!-- Describe what has changed in this PR --> **What changed?** Adds the domain_audit_log table. <!-- Tell your future self why have you made these changes --> **Why?** This is the first step of the persistence implementation for a persisted audit_log for domain changes. It will only be used for changes to the ReplicationConfig initially, replacing FailoverHistory in the domains metadata. <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** Unit tests, manual POC. <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** Something is wrong with the schema definition (or the primary key definition) and we need to modify the table later. Ideally this is caught before it gets much further than this. <!-- 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** N/A <!-- 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** N/A **Detailed Description** [In-depth description of the changes made to the schema or interfaces, specifying new fields, removed fields, or modified data structures] The domain_audit_log table has been added to the Cassandra schema. It will not exist in SQL etc. for now, and is planned to be added early next year. **Impact Analysis** - **Backward Compatibility**: [Analysis of backward compatibility] - **Forward Compatibility**: [Analysis of forward compatibility] N/A **Testing Plan** - **Unit Tests**: [Do we have unit test covering the change?] - **Persistence Tests**: [If the change is related to a data type which is persisted, do we have persistence tests covering the change?] - **Integration Tests**: [Do we have integration test covering the change?] - **Compatibility Tests**: [Have we done tests to test the backward and forward compatibility?] This should be covered by future integration & persistence tests - but is not yet. They will be added in a follow up PR. **Rollout Plan** - What is the rollout plan? - Does the order of deployment matter? No - Is it safe to rollback? Does the order of rollback matter? Yes, until applications start using it. - Is there a kill switch to mitigate the impact immediately? No. --- Signed-off-by: Gaziza Yestemirova <[email protected]>
1 parent e8a5a0e commit 372dd4d

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

schema/cassandra/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Q: How do I update existing schema ?
2424
* Create a new schema version directory under ./schema/keyspace/versioned/vx.x
2525
* Add a manifest.json
2626
* Add your changes in a cql file
27-
* Update the unit test within ./tools/cassandra/updateTask_test.go `TestDryrun` with your version x.x
27+
* Update the unit test within ./tools/common/schema/updatetask_test.go `TestReadSchemaDirFromEmbeddings` with your version x.x
2828
* Once you are done with these use the ./cadence-cassandra-tool to update the schema
2929

3030
Q: What's the format of manifest.json

schema/cassandra/cadence/schema.cql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,29 @@ CREATE TABLE cluster_config (
537537
encoding text,
538538
PRIMARY KEY (row_type, version)
539539
) WITH CLUSTERING ORDER BY (version DESC);
540+
541+
CREATE TABLE domain_audit_log (
542+
domain_id uuid,
543+
event_id uuid, -- event_id is the unique identifier for this change to the domain
544+
545+
state_before blob, -- state_before stores the domain state before the request
546+
state_before_encoding text, -- the encoding type used for state_before
547+
548+
state_after blob, -- state_after stores the domain state after the request
549+
state_after_encoding text, -- the encoding type used for state_after
550+
551+
operation_type int, -- operation_type stores the type of operation that was performed. It is deserialized as an enum and can be used to customize the serialization/deserialization strategy.
552+
553+
created_time timestamp, -- created_time the time this row was inserted
554+
last_updated_time timestamp,
555+
556+
identity text, -- the unique identifier of the user that made the change
557+
identity_type text, -- identity_type can be used to delineate between service, user, or other identities
558+
559+
comment text, -- comment can be used when manual updates or creates are performed on the database as an audit trail
560+
561+
PRIMARY KEY ((domain_id, operation_type), created_time, event_id)
562+
) WITH CLUSTERING ORDER BY (created_time DESC, event_id ASC)
563+
AND COMPACTION = {
564+
'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'
565+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE TABLE domain_audit_log (
2+
domain_id uuid,
3+
event_id uuid, -- event_id is the unique identifier for this change to the domain
4+
5+
state_before blob, -- state_before stores the domain state before the request
6+
state_before_encoding text, -- the encoding type used for state_before
7+
8+
state_after blob, -- state_after stores the domain state after the request
9+
state_after_encoding text, -- the encoding type used for state_after
10+
11+
operation_type int, -- operation_type stores the type of operation that was performed. It is deserialized as an enum and can be used to customize the serialization/deserialization strategy.
12+
13+
created_time timestamp, -- created_time the time this row was inserted
14+
last_updated_time timestamp,
15+
16+
identity text, -- the unique identifier of the user that made the change
17+
identity_type text, -- identity_type can be used to delineate between service, user, or other identities
18+
19+
comment text, -- comment can be used when manual updates or creates are performed on the database as an audit trail
20+
21+
PRIMARY KEY ((domain_id, operation_type), created_time, event_id)
22+
) WITH CLUSTERING ORDER BY (created_time DESC, event_id ASC)
23+
AND COMPACTION = {
24+
'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'
25+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"CurrVersion": "0.44",
3+
"MinCompatibleVersion": "0.44",
4+
"Description": "Adding domain_audit_log table to track domain update and failover history",
5+
"SchemaUpdateCqlFiles": [
6+
"domain_audit_log.cql"
7+
]
8+
}

schema/cassandra/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package cassandra
2323
// NOTE: whenever there is a new data base schema update, plz update the following versions
2424

2525
// Version is the Cassandra database release version
26-
const Version = "0.43"
26+
const Version = "0.44"
2727

2828
// VisibilityVersion is the Cassandra visibility database release version
2929
const VisibilityVersion = "0.9"

tools/common/schema/updatetask_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (s *UpdateTaskTestSuite) TestReadSchemaDirFromEmbeddings() {
116116
s.NoError(err)
117117
ans, err := readSchemaDir(fsys, "0.30", "")
118118
s.NoError(err)
119-
s.Equal([]string{"v0.31", "v0.32", "v0.33", "v0.34", "v0.35", "v0.36", "v0.37", "v0.38", "v0.39", "v0.40", "v0.41", "v0.42", "v0.43"}, ans)
119+
s.Equal([]string{"v0.31", "v0.32", "v0.33", "v0.34", "v0.35", "v0.36", "v0.37", "v0.38", "v0.39", "v0.40", "v0.41", "v0.42", "v0.43", "v0.44"}, ans)
120120

121121
fsys, err = fs.Sub(cassandra.SchemaFS, "visibility/versioned")
122122
s.NoError(err)

0 commit comments

Comments
 (0)