Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pubsub): add support for ingestion platform logging settings #10969

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion pubsub/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ type TopicConfigToUpdate struct {
// data source into this topic.
//
// When changing this value, the entire data source settings object must be applied,
// rather than just the differences.
// rather than just the differences. This includes the source and logging settings.
//
// Use the zero value &IngestionDataSourceSettings{} to remove the ingestion settings from the topic.
IngestionDataSourceSettings *IngestionDataSourceSettings
Expand Down Expand Up @@ -429,6 +429,8 @@ func messageStoragePolicyToProto(msp *MessageStoragePolicy) *pb.MessageStoragePo
// IngestionDataSourceSettings enables ingestion from a data source into this topic.
type IngestionDataSourceSettings struct {
Source IngestionDataSource

PlatformLogsSettings *PlatformLogsSettings
}

// IngestionDataSource is the kind of ingestion source to be used.
Expand Down Expand Up @@ -624,6 +626,13 @@ func protoToIngestionDataSourceSettings(pbs *pb.IngestionDataSourceSettings) *In
MatchGlob: cs.GetMatchGlob(),
}
}

if pbs.PlatformLogsSettings != nil {
s.PlatformLogsSettings = &PlatformLogsSettings{
Severity: PlatformLogsSeverity(pbs.PlatformLogsSettings.Severity),
}
}

return s
}

Expand All @@ -636,6 +645,11 @@ func (i *IngestionDataSourceSettings) toProto() *pb.IngestionDataSourceSettings
return nil
}
pbs := &pb.IngestionDataSourceSettings{}
if i.PlatformLogsSettings != nil {
pbs.PlatformLogsSettings = &pb.PlatformLogsSettings{
Severity: pb.PlatformLogsSettings_Severity(i.PlatformLogsSettings.Severity),
}
}
if out := i.Source; out != nil {
if k, ok := out.(*IngestionDataSourceAWSKinesis); ok {
pbs.Source = &pb.IngestionDataSourceSettings_AwsKinesis_{
Expand Down Expand Up @@ -694,6 +708,29 @@ func (i *IngestionDataSourceSettings) toProto() *pb.IngestionDataSourceSettings
return pbs
}

// PlatformLogsSettings configures logging produced by Pub/Sub.
type PlatformLogsSettings struct {
Severity PlatformLogsSeverity
}

// PlatformLogsSeverity are the severity levels of Platform Logs.
type PlatformLogsSeverity int32

const (
// PlatformLogsSeverityUnspecified is the default value. Logs level is unspecified. Logs will be disabled.
PlatformLogsSeverityUnspecified PlatformLogsSeverity = iota
// PlatformLogsSeverityDisabled means logs will be disabled.
PlatformLogsSeverityDisabled
// PlatformLogsSeverityDebug means debug logs and higher-severity logs will be written.
PlatformLogsSeverityDebug
// PlatformLogsSeverityInfo means info logs and higher-severity logs will be written.
PlatformLogsSeverityInfo
// PlatformLogsSeverityWarning means warning logs and higher-severity logs will be written.
PlatformLogsSeverityWarning
// PlatformLogsSeverityError means only error logs will be written.
PlatformLogsSeverityError
)

// Config returns the TopicConfig for the topic.
func (t *Topic) Config(ctx context.Context) (TopicConfig, error) {
pbt, err := t.c.pubc.GetTopic(ctx, &pb.GetTopicRequest{Topic: t.name})
Expand Down
12 changes: 12 additions & 0 deletions pubsub/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func TestTopic_IngestionKinesis(t *testing.T) {
AWSRoleARN: "fake-aws-role-arn",
GCPServiceAccount: "fake-gcp-sa",
},
PlatformLogsSettings: &PlatformLogsSettings{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Users are allowed to set Platform Logs settings on Kinesis ingestion topics but we don't actually do any platform logging for Kinesis ingestion. Fine with keeping it or removing it.

Severity: PlatformLogsSeverityWarning,
},
},
}

Expand All @@ -145,6 +148,9 @@ func TestTopic_IngestionKinesis(t *testing.T) {
AWSRoleARN: "aws-role-arn-2",
GCPServiceAccount: "gcp-service-account-2",
},
PlatformLogsSettings: &PlatformLogsSettings{
Severity: PlatformLogsSeverityInfo,
},
}
config2, err := topic.Update(ctx, TopicConfigToUpdate{IngestionDataSourceSettings: settings})
if err != nil {
Expand Down Expand Up @@ -181,6 +187,9 @@ func TestTopic_IngestionCloudStorage(t *testing.T) {
MinimumObjectCreateTime: time.Now().Add(-time.Hour),
MatchGlob: "**.txt",
},
PlatformLogsSettings: &PlatformLogsSettings{
Severity: PlatformLogsSeverityDisabled,
},
},
}

Expand All @@ -204,6 +213,9 @@ func TestTopic_IngestionCloudStorage(t *testing.T) {
MinimumObjectCreateTime: time.Now().Add(-2 * time.Hour),
MatchGlob: "**.txt",
},
PlatformLogsSettings: &PlatformLogsSettings{
Severity: PlatformLogsSeverityError,
},
}
config2, err := topic.Update(ctx, TopicConfigToUpdate{IngestionDataSourceSettings: settings})
if err != nil {
Expand Down
Loading