From bbbfb9dffce5bdf9faeeb83f50e510980869dbaf Mon Sep 17 00:00:00 2001 From: Mike Denomy Date: Thu, 31 Oct 2024 16:14:54 -0400 Subject: [PATCH] Integration tests passing --- .../logging/grafanacloudlogs/create.go | 14 ++++- .../logging/grafanacloudlogs/describe.go | 5 +- .../grafanacloud_logs_integration_test.go | 52 ++++++++++--------- pkg/commands/logging/grafanacloudlogs/list.go | 24 +++++---- 4 files changed, 57 insertions(+), 38 deletions(-) diff --git a/pkg/commands/logging/grafanacloudlogs/create.go b/pkg/commands/logging/grafanacloudlogs/create.go index 3b671bb0e..53f85929c 100644 --- a/pkg/commands/logging/grafanacloudlogs/create.go +++ b/pkg/commands/logging/grafanacloudlogs/create.go @@ -54,6 +54,18 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman Dst: &c.ServiceVersion.Value, Required: true, }) + c.RegisterFlag(argparser.StringFlagOpts{ + Name: argparser.FlagServiceIDName, + Description: argparser.FlagServiceIDDesc, + Dst: &g.Manifest.Flag.ServiceID, + Short: 's', + }) + c.RegisterFlag(argparser.StringFlagOpts{ + Action: c.ServiceName.Set, + Name: argparser.FlagServiceName, + Description: argparser.FlagServiceNameDesc, + Dst: &c.ServiceName.Value, + }) // Optional. c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{ @@ -69,7 +81,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman c.CmdClause.Flag("index", `The stream identifier`).Action(c.Index.Set).StringVar(&c.Index.Value) c.CmdClause.Flag("url", "The URL of your Grafana instance").Action(c.URL.Set).StringVar(&c.URL.Value) c.CmdClause.Flag("user", "Your Grafana User ID.").Action(c.User.Set).StringVar(&c.User.Value) - c.CmdClause.Flag("auth-token", "The API key from your Datadog account").Action(c.Token.Set).StringVar(&c.Token.Value) + c.CmdClause.Flag("auth-token", "Your Grafana Access Policy Token").Action(c.Token.Set).StringVar(&c.Token.Value) return &c } diff --git a/pkg/commands/logging/grafanacloudlogs/describe.go b/pkg/commands/logging/grafanacloudlogs/describe.go index f9f816085..08a7002fe 100644 --- a/pkg/commands/logging/grafanacloudlogs/describe.go +++ b/pkg/commands/logging/grafanacloudlogs/describe.go @@ -98,8 +98,11 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { "Name": fastly.ToValue(o.Name), "Placement": fastly.ToValue(o.Placement), "Response condition": fastly.ToValue(o.ResponseCondition), - "User": fastly.ToValue(o.User), "Version": fastly.ToValue(o.ServiceVersion), + "User": fastly.ToValue(o.User), + "URL": fastly.ToValue(o.URL), + "Token": fastly.ToValue(o.Token), + "Index": fastly.ToValue(o.Index), } if !c.Globals.Verbose() { lines["Service ID"] = fastly.ToValue(o.ServiceID) diff --git a/pkg/commands/logging/grafanacloudlogs/grafanacloud_logs_integration_test.go b/pkg/commands/logging/grafanacloudlogs/grafanacloud_logs_integration_test.go index 72376b0e8..a90e95a03 100644 --- a/pkg/commands/logging/grafanacloudlogs/grafanacloud_logs_integration_test.go +++ b/pkg/commands/logging/grafanacloudlogs/grafanacloud_logs_integration_test.go @@ -23,7 +23,7 @@ func TestGrafanaCloudLogsCreate(t *testing.T) { wantOutput string }{ { - args: args("logging grafanacloudlogs create --service-id 123 --version 1 --name log --user 123456 --url https://test123.grafana.net --token testtoken --index `{\"label\": \"value\" }` --autoclone"), + args: args("logging grafanacloudlogs create --service-id 123 --version 1 --name log --user 123456 --url https://test123.grafana.net --auth-token testtoken --index `{\"label\": \"value\" }` --autoclone"), api: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), @@ -32,7 +32,7 @@ func TestGrafanaCloudLogsCreate(t *testing.T) { wantOutput: "Created Grafana Cloud Logs logging endpoint log (service 123 version 4)", }, { - args: args("logging grafanacloudlogs create --service-id 123 --version 1 --name log --url https://test123.grafana.net --token testtoken --index `{\"label\": \"value\" }` --autoclone"), + args: args("logging grafanacloudlogs create --service-id 123 --version 1 --name log --url https://test123.grafana.net --auth-token testtoken --index `{\"label\": \"value\" }` --autoclone"), api: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), @@ -203,7 +203,7 @@ func TestGrafanaCloudLogsUpdate(t *testing.T) { CloneVersionFn: testutil.CloneVersionResult(4), UpdateGrafanaCloudLogsFn: updateGrafanaCloudLogsOK, }, - wantOutput: "Updated grafanacloudlogs logging endpoint log (service 123 version 4)", + wantOutput: "Updated Grafana Cloud Logs logging endpoint log (service 123 version 4)", }, } for testcaseIdx := range scenarios { @@ -333,42 +333,32 @@ Fastly API token provided via config file (profile: user) Service ID (via --service-id): 123 Version: 1 - GCS 1/2 + GrafanaCloudLogs 1/2 Service ID: 123 Version: 1 Name: logs - Bucket: my-logs - User: foo@example.com - Account name: me@fastly.com - Secret key: -----BEGIN RSA PRIVATE KEY-----foo - Path: logs/ - Period: 3600 - GZip level: 0 Format: %h %l %u %t "%r" %>s %b Format version: 2 Response condition: Prevent default logging Message type: classic - Timestamp format: %Y-%m-%dT%H:%M:%S.000 Placement: none - Compression codec: zstd - GCS 2/2 + User: 123456 + URL: https://test123.grafana.net + Token: testtoken + Index: {"label": "value"} + GrafanaCloudLogs 2/2 Service ID: 123 Version: 1 Name: analytics - Bucket: analytics - User: foo@example.com - Account name: me@fastly.com - Secret key: -----BEGIN RSA PRIVATE KEY-----foo - Path: logs/ - Period: 86400 - GZip level: 0 Format: %h %l %u %t "%r" %>s %b Format version: 2 Response condition: Prevent default logging Message type: classic - Timestamp format: %Y-%m-%dT%H:%M:%S.000 Placement: none - Compression codec: zstd + User: 123456 + URL: https://test123.grafana.net + Token: testtoken + Index: {"label": "value"} `) + "\n\n" func getGrafanaCloudLogsOK(i *fastly.GetGrafanaCloudLogsInput) (*fastly.GrafanaCloudLogs, error) { @@ -380,7 +370,11 @@ func getGrafanaCloudLogsOK(i *fastly.GetGrafanaCloudLogsInput) (*fastly.GrafanaC FormatVersion: fastly.ToPointer(2), MessageType: fastly.ToPointer("classic"), ResponseCondition: fastly.ToPointer("Prevent default logging"), - Placement: fastly.ToPointer("zstd"), + Placement: fastly.ToPointer("none"), + User: fastly.ToPointer("123456"), + URL: fastly.ToPointer("https://test123.grafana.net"), + Token: fastly.ToPointer("testtoken"), + Index: fastly.ToPointer("{\"label\": \"value\"}"), }, nil } @@ -391,10 +385,15 @@ func getGrafanaCloudLogsError(_ *fastly.GetGrafanaCloudLogsInput) (*fastly.Grafa var describeGrafanaCloudLogsOutput = "\n" + strings.TrimSpace(` Format: %h %l %u %t "%r" %>s %b Format version: 2 +Index: {"label": "value"} Message type: classic Name: logs Placement: none Response condition: Prevent default logging +Service ID: 123 +Token: testtoken +URL: https://test123.grafana.net +User: 123456 Version: 1 `) + "\n" @@ -403,12 +402,15 @@ func updateGrafanaCloudLogsOK(i *fastly.UpdateGrafanaCloudLogsInput) (*fastly.Gr ServiceID: fastly.ToPointer(i.ServiceID), ServiceVersion: fastly.ToPointer(i.ServiceVersion), Name: fastly.ToPointer("log"), - User: fastly.ToPointer("foo@example.com"), Format: fastly.ToPointer(`%h %l %u %t "%r" %>s %b`), FormatVersion: fastly.ToPointer(2), ResponseCondition: fastly.ToPointer("Prevent default logging"), MessageType: fastly.ToPointer("classic"), Placement: fastly.ToPointer("none"), + User: fastly.ToPointer("123456"), + URL: fastly.ToPointer("https://test123.grafana.net"), + Token: fastly.ToPointer("testtoken"), + Index: fastly.ToPointer("{\"label\": \"value\"}"), }, nil } diff --git a/pkg/commands/logging/grafanacloudlogs/list.go b/pkg/commands/logging/grafanacloudlogs/list.go index 425db9198..65bba93b4 100644 --- a/pkg/commands/logging/grafanacloudlogs/list.go +++ b/pkg/commands/logging/grafanacloudlogs/list.go @@ -106,18 +106,20 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion) - for i, gcs := range o { + for i, grafanacloudlogs := range o { fmt.Fprintf(out, "\tGrafanaCloudLogs %d/%d\n", i+1, len(o)) - fmt.Fprintf(out, "\t\tService ID: %s\n", fastly.ToValue(gcs.ServiceID)) - fmt.Fprintf(out, "\t\tVersion: %d\n", fastly.ToValue(gcs.ServiceVersion)) - fmt.Fprintf(out, "\t\tName: %s\n", fastly.ToValue(gcs.Name)) - - fmt.Fprintf(out, "\t\tUser: %s\n", fastly.ToValue(gcs.User)) - fmt.Fprintf(out, "\t\tFormat: %s\n", fastly.ToValue(gcs.Format)) - fmt.Fprintf(out, "\t\tFormat version: %d\n", fastly.ToValue(gcs.FormatVersion)) - fmt.Fprintf(out, "\t\tResponse condition: %s\n", fastly.ToValue(gcs.ResponseCondition)) - fmt.Fprintf(out, "\t\tMessage type: %s\n", fastly.ToValue(gcs.MessageType)) - fmt.Fprintf(out, "\t\tPlacement: %s\n", fastly.ToValue(gcs.Placement)) + fmt.Fprintf(out, "\t\tService ID: %s\n", fastly.ToValue(grafanacloudlogs.ServiceID)) + fmt.Fprintf(out, "\t\tVersion: %d\n", fastly.ToValue(grafanacloudlogs.ServiceVersion)) + fmt.Fprintf(out, "\t\tName: %s\n", fastly.ToValue(grafanacloudlogs.Name)) + fmt.Fprintf(out, "\t\tFormat: %s\n", fastly.ToValue(grafanacloudlogs.Format)) + fmt.Fprintf(out, "\t\tFormat version: %d\n", fastly.ToValue(grafanacloudlogs.FormatVersion)) + fmt.Fprintf(out, "\t\tResponse condition: %s\n", fastly.ToValue(grafanacloudlogs.ResponseCondition)) + fmt.Fprintf(out, "\t\tMessage type: %s\n", fastly.ToValue(grafanacloudlogs.MessageType)) + fmt.Fprintf(out, "\t\tPlacement: %s\n", fastly.ToValue(grafanacloudlogs.Placement)) + fmt.Fprintf(out, "\t\tUser: %s\n", fastly.ToValue(grafanacloudlogs.User)) + fmt.Fprintf(out, "\t\tURL: %s\n", fastly.ToValue(grafanacloudlogs.URL)) + fmt.Fprintf(out, "\t\tToken: %s\n", fastly.ToValue(grafanacloudlogs.Token)) + fmt.Fprintf(out, "\t\tIndex: %s\n", fastly.ToValue(grafanacloudlogs.Index)) } fmt.Fprintln(out)