Skip to content

Commit

Permalink
Integration tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdenomy committed Oct 31, 2024
1 parent acce5ae commit 3cde876
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
14 changes: 13 additions & 1 deletion pkg/commands/logging/grafanacloudlogs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/commands/logging/grafanacloudlogs/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: [email protected]
Account name: [email protected]
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: [email protected]
Account name: [email protected]
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) {
Expand All @@ -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"),
Token: fastly.ToPointer("testtoken"),
URL: fastly.ToPointer("https://test123.grafana.net"),
Index: fastly.ToPointer("{\"label\": \"value\"}"),
}, nil
}

Expand All @@ -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"

Expand All @@ -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("[email protected]"),
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"),
Token: fastly.ToPointer("testtoken"),
URL: fastly.ToPointer("https://test123.grafana.net"),
Index: fastly.ToPointer("{\"label\": \"value\"}"),
}, nil
}

Expand Down
24 changes: 13 additions & 11 deletions pkg/commands/logging/grafanacloudlogs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3cde876

Please sign in to comment.