Skip to content

Commit d3ffe1e

Browse files
committed
sql,eventpb: log structured event for REFRESH MATERIALIZED VIEW
Release note (ops change): A structured event is now logged in the SQL_SCHEMA channgel when the REFRESH MATERIALIZED VIEW statement is executed.
1 parent b48712f commit d3ffe1e

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

docs/generated/eventlog.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,29 @@ initiated schema change rollback has completed.
18711871
| `DescriptorID` | | no |
18721872

18731873

1874+
#### Common fields
1875+
1876+
| Field | Description | Sensitive |
1877+
|--|--|--|
1878+
| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | no |
1879+
| `EventType` | The type of the event. | no |
1880+
| `Statement` | A normalized copy of the SQL statement that triggered the event. The statement string contains a mix of sensitive and non-sensitive details (it is redactable). | partially |
1881+
| `Tag` | The statement tag. This is separate from the statement string, since the statement string can contain sensitive information. The tag is guaranteed not to. | no |
1882+
| `User` | The user account that triggered the event. The special usernames `root` and `node` are not considered sensitive. | depends |
1883+
| `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | no |
1884+
| `ApplicationName` | The application name for the session where the event was emitted. This is included in the event to ease filtering of logging output by application. | no |
1885+
| `PlaceholderValues` | The mapping of SQL placeholders to their values, for prepared statements. | yes |
1886+
1887+
### `refresh_materialized_view`
1888+
1889+
An event of type `refresh_materialized_view` is recorded when a materialized view is refreshed.
1890+
1891+
1892+
| Field | Description | Sensitive |
1893+
|--|--|--|
1894+
| `ViewName` | The name of the materialized view being refreshed. | no |
1895+
1896+
18741897
#### Common fields
18751898

18761899
| Field | Description | Sensitive |

pkg/sql/refresh_materialized_view.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice"
1616
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
1717
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
18+
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
1819
)
1920

2021
type refreshMaterializedViewNode struct {
@@ -120,6 +121,15 @@ func (n *refreshMaterializedViewNode) startExec(params runParams) error {
120121
}
121122
desc.AddMaterializedViewRefreshMutation(refreshProto)
122123

124+
// Log the refresh materialized view event.
125+
if err := params.p.logEvent(params.ctx,
126+
desc.ID,
127+
&eventpb.RefreshMaterializedView{
128+
ViewName: params.p.ResolvedName(n.n.Name).FQString(),
129+
}); err != nil {
130+
return err
131+
}
132+
123133
return params.p.writeSchemaChange(
124134
params.ctx,
125135
desc,

pkg/util/log/eventpb/ddl_events.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,11 @@ message DropPolicy {
643643
string policy_name = 4 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""];
644644
}
645645

646+
// RefreshMaterializedView is recorded when a materialized view is refreshed.
647+
message RefreshMaterializedView {
648+
CommonEventDetails common = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true];
649+
CommonSQLEventDetails sql = 2 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true];
650+
// The name of the materialized view being refreshed.
651+
string view_name = 3 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""];
652+
}
653+

pkg/util/log/eventpb/eventlog_channels_generated.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/log/eventpb/json_encode_generated.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)