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

Adds MessageType field to GCS Updates #113

Merged
merged 1 commit into from
Jun 4, 2020
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
3 changes: 3 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ COMMANDS
--timestamp-format=TIMESTAMP-FORMAT
strftime specified timestamp formatting
(default "%Y-%m-%dT%H:%M:%S.000")
--message-type=MESSAGE-TYPE
How the message should be formatted. One of:
classic (default), loggly, logplex or blank
--placement=PLACEMENT Where in the generated VCL the logging call
should be placed, overriding any format_version
default. Can be none or waf_debug
Expand Down
6 changes: 6 additions & 0 deletions pkg/logging/gcs/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestCreateGCSInput(t *testing.T) {
FormatVersion: 2,
GzipLevel: 2,
Format: `%h %l %u %t "%r" %>s %b`,
MessageType: "classic",
ResponseCondition: "Prevent default logging",
TimestampFormat: "%Y-%m-%dT%H:%M:%S.000",
Placement: "none",
Expand Down Expand Up @@ -93,6 +94,7 @@ func TestUpdateGCSInput(t *testing.T) {
Format: `%h %l %u %t "%r" %>s %b`,
ResponseCondition: "Prevent default logging",
TimestampFormat: "%Y-%m-%dT%H:%M:%S.000",
MessageType: "classic",
Placement: "none",
},
},
Expand All @@ -116,6 +118,7 @@ func TestUpdateGCSInput(t *testing.T) {
ResponseCondition: "new7",
TimestampFormat: "new8",
Placement: "new9",
MessageType: "new10",
},
},
{
Expand Down Expand Up @@ -160,6 +163,7 @@ func createCommandAll() *CreateCommand {
Format: common.OptionalString{Optional: common.Optional{Valid: true}, Value: `%h %l %u %t "%r" %>s %b`},
FormatVersion: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 2},
TimestampFormat: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "%Y-%m-%dT%H:%M:%S.000"},
MessageType: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "classic"},
ResponseCondition: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "Prevent default logging"},
Placement: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "none"},
}
Expand Down Expand Up @@ -198,6 +202,7 @@ func updateCommandAll() *UpdateCommand {
ResponseCondition: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new7"},
TimestampFormat: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new8"},
Placement: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new9"},
MessageType: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new10"},
}
}

Expand All @@ -220,6 +225,7 @@ func getGCSOK(i *fastly.GetGCSInput) (*fastly.GCS, error) {
GzipLevel: 2,
Format: `%h %l %u %t "%r" %>s %b`,
FormatVersion: 2,
MessageType: "classic",
ResponseCondition: "Prevent default logging",
TimestampFormat: "%Y-%m-%dT%H:%M:%S.000",
Placement: "none",
Expand Down
9 changes: 7 additions & 2 deletions pkg/logging/gcs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ type UpdateCommand struct {
Format common.OptionalString
ResponseCondition common.OptionalString
TimestampFormat common.OptionalString
MessageType common.OptionalString
Placement common.OptionalString

// TODO (@mccurdyc): Add supported MessageType field once exposed for Updates (already exists for Creates).
}

// NewUpdateCommand returns a usable command registered under the parent.
Expand All @@ -60,6 +59,7 @@ func NewUpdateCommand(parent common.Registerer, globals *config.Data) *UpdateCom
c.CmdClause.Flag("format", "Apache style log formatting").Action(c.Format.Set).StringVar(&c.Format.Value)
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value)
c.CmdClause.Flag("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.TimestampFormat.Set).StringVar(&c.TimestampFormat.Value)
c.CmdClause.Flag("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.MessageType.Set).StringVar(&c.MessageType.Value)
c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value)

return &c
Expand Down Expand Up @@ -94,6 +94,7 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateGCSInput, error) {
FormatVersion: gcs.FormatVersion,
GzipLevel: gcs.GzipLevel,
Format: gcs.Format,
MessageType: gcs.MessageType,
ResponseCondition: gcs.ResponseCondition,
TimestampFormat: gcs.TimestampFormat,
Placement: gcs.Placement,
Expand Down Expand Up @@ -144,6 +145,10 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateGCSInput, error) {
input.TimestampFormat = c.TimestampFormat.Value
}

if c.MessageType.Valid {
input.MessageType = c.MessageType.Value
}

if c.Placement.Valid {
input.Placement = c.Placement.Value
}
Expand Down