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

chore: compression property #22

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions go/stream/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
mapKeySourceType = "sourceType"
mapKeyWebhookFailureReason = "webhookFailureReason"
mapKeyStage = "stage"
mapKeyCompression = "compression"
)

type Message struct {
Expand All @@ -47,6 +48,7 @@ type MessageProperties struct {
SourceType string `json:"sourceType,omitempty"` // optional
WebhookFailureReason string `json:"webhookFailureReason,omitempty"` // optional
Stage string `json:"stage,omitempty"` // optional
Compression string `json:"compression,omitempty"` // optional
}

// FromMapProperties converts a property map to MessageProperties.
Expand All @@ -71,6 +73,7 @@ func FromMapProperties(properties map[string]string) (MessageProperties, error)
SourceType: properties[mapKeySourceType],
WebhookFailureReason: properties[mapKeyWebhookFailureReason],
Stage: properties[mapKeyStage],
Compression: properties[mapKeyCompression],
}, nil
}

Expand All @@ -88,6 +91,7 @@ func ToMapProperties(properties MessageProperties) map[string]string {
mapKeySourceJobRunID: properties.SourceJobRunID,
mapKeySourceTaskRunID: properties.SourceTaskRunID,
mapKeyTraceID: properties.TraceID,
mapKeyCompression: properties.Compression,
}
if properties.Stage == StageWebhook {
m[mapKeySourceType] = properties.SourceType
Expand Down
12 changes: 10 additions & 2 deletions go/stream/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestMessage(t *testing.T) {
"sourceJobRunID": "sourceJobRunID",
"sourceTaskRunID": "sourceTaskRunID",
"traceID": "traceID",
"compression": "some-serialized-compression-settings",
}

msg, err := stream.FromMapProperties(input)
Expand All @@ -41,6 +42,7 @@ func TestMessage(t *testing.T) {
SourceJobRunID: "sourceJobRunID",
SourceTaskRunID: "sourceTaskRunID",
TraceID: "traceID",
Compression: "some-serialized-compression-settings",
}, msg)

propertiesOut := stream.ToMapProperties(msg)
Expand Down Expand Up @@ -71,6 +73,7 @@ func TestMessage(t *testing.T) {
"sourceType": "sourceType",
"webhookFailureReason": "webhookFailureReason",
"stage": stream.StageWebhook,
"compression": "some-serialized-compression-settings",
}

msg, err := stream.FromMapProperties(input)
Expand All @@ -91,6 +94,7 @@ func TestMessage(t *testing.T) {
SourceType: "sourceType",
WebhookFailureReason: "webhookFailureReason",
Stage: stream.StageWebhook,
Compression: "some-serialized-compression-settings",
}, msg)

propertiesOut := stream.ToMapProperties(msg)
Expand All @@ -111,7 +115,8 @@ func TestMessage(t *testing.T) {
"requestIP": "10.29.13.20",
"sourceJobRunID": "sourceJobRunID",
"sourceTaskRunID": "sourceTaskRunID",
"traceID": "traceID"
"traceID": "traceID",
"compression": "some-serialized-compression-settings"
},
"payload": {
"key": "value",
Expand All @@ -138,6 +143,7 @@ func TestMessage(t *testing.T) {
SourceJobRunID: "sourceJobRunID",
SourceTaskRunID: "sourceTaskRunID",
TraceID: "traceID",
Compression: "some-serialized-compression-settings",
},
Payload: json.RawMessage(`{
"key": "value",
Expand Down Expand Up @@ -170,7 +176,8 @@ func TestMessage(t *testing.T) {
"traceID": "traceID",
"sourceType": "sourceType",
"webhookFailureReason": "webhookFailureReason",
"stage": "webhook"
"stage": "webhook",
"compression": "some-serialized-compression-settings"
},
"payload": {
"key": "value",
Expand Down Expand Up @@ -199,6 +206,7 @@ func TestMessage(t *testing.T) {
TraceID: "traceID", SourceType: "sourceType",
WebhookFailureReason: "webhookFailureReason",
Stage: stream.StageWebhook,
Compression: "some-serialized-compression-settings",
},
Payload: json.RawMessage(`{
"key": "value",
Expand Down
Loading