Skip to content

Commit 2303f73

Browse files
feat(serverless): add support for get-logs (#2919)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent 5b91b23 commit 2303f73

File tree

9 files changed

+137
-44
lines changed

9 files changed

+137
-44
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List your container logs.
4+
5+
USAGE:
6+
scw container container get-logs <container-id ...> [arg=value ...]
7+
8+
ARGS:
9+
container-id
10+
[order-by] (timestamp_desc | timestamp_asc)
11+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
12+
13+
FLAGS:
14+
-h, --help help for get-logs
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-container-container-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AVAILABLE COMMANDS:
1010
delete Delete a container
1111
deploy Deploy a container
1212
get Get a container
13+
get-logs List your container logs
1314
list List all your containers
1415
update Update an existing container
1516

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List your application logs.
4+
5+
USAGE:
6+
scw function function get-logs <function-id ...> [arg=value ...]
7+
8+
ARGS:
9+
function-id
10+
[order-by] (timestamp_desc | timestamp_asc)
11+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
12+
13+
FLAGS:
14+
-h, --help help for get-logs
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-function-function-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ AVAILABLE COMMANDS:
1111
deploy Deploy a function
1212
get Get a function
1313
get-download-url Get a download URL of a function
14+
get-logs List your application logs
1415
get-upload-url Get an upload URL of a function
1516
list List all your functions
1617
update Update an existing function

cmd/scw/testdata/test-all-usage-function-usage.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ AVAILABLE COMMANDS:
99
cron Cron management commands
1010
domain Domain management commands
1111
function Function management commands
12-
logs Logs management commands
1312
namespace Function namespace management commands
1413
runtime Runtime management commands
1514
token Token management commands

docs/commands/container.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Containers API.
77
- [Delete a container](#delete-a-container)
88
- [Deploy a container](#deploy-a-container)
99
- [Get a container](#get-a-container)
10+
- [List your container logs](#list-your-container-logs)
1011
- [List all your containers](#list-all-your-containers)
1112
- [Update an existing container](#update-an-existing-container)
1213
- [Cron management commands](#cron-management-commands)
@@ -134,6 +135,27 @@ scw container container get <container-id ...> [arg=value ...]
134135

135136

136137

138+
### List your container logs
139+
140+
List your container logs.
141+
142+
**Usage:**
143+
144+
```
145+
scw container container get-logs <container-id ...> [arg=value ...]
146+
```
147+
148+
149+
**Args:**
150+
151+
| Name | | Description |
152+
|------|---|-------------|
153+
| container-id | Required | |
154+
| order-by | One of: `timestamp_desc`, `timestamp_asc` | |
155+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
156+
157+
158+
137159
### List all your containers
138160

139161
List all your containers.

docs/commands/function.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ Functions API.
1919
- [Deploy a function](#deploy-a-function)
2020
- [Get a function](#get-a-function)
2121
- [Get a download URL of a function](#get-a-download-url-of-a-function)
22+
- [List your application logs](#list-your-application-logs)
2223
- [Get an upload URL of a function](#get-an-upload-url-of-a-function)
2324
- [List all your functions](#list-all-your-functions)
2425
- [Update an existing function](#update-an-existing-function)
25-
- [Logs management commands](#logs-management-commands)
26-
- [List your application logs](#list-your-application-logs)
2726
- [Function namespace management commands](#function-namespace-management-commands)
2827
- [Create a new namespace](#create-a-new-namespace)
2928
- [Delete an existing namespace](#delete-an-existing-namespace)
@@ -358,6 +357,27 @@ scw function function get-download-url <function-id ...> [arg=value ...]
358357

359358

360359

360+
### List your application logs
361+
362+
List your application logs.
363+
364+
**Usage:**
365+
366+
```
367+
scw function function get-logs <function-id ...> [arg=value ...]
368+
```
369+
370+
371+
**Args:**
372+
373+
| Name | | Description |
374+
|------|---|-------------|
375+
| function-id | Required | |
376+
| order-by | One of: `timestamp_desc`, `timestamp_asc` | |
377+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
378+
379+
380+
361381
### Get an upload URL of a function
362382

363383
Get an upload URL of a function associated with the given id.
@@ -437,32 +457,6 @@ scw function function update <function-id ...> [arg=value ...]
437457

438458

439459

440-
## Logs management commands
441-
442-
Logs management commands.
443-
444-
445-
### List your application logs
446-
447-
List your application logs.
448-
449-
**Usage:**
450-
451-
```
452-
scw function logs list [arg=value ...]
453-
```
454-
455-
456-
**Args:**
457-
458-
| Name | | Description |
459-
|------|---|-------------|
460-
| function-id | Required | |
461-
| order-by | One of: `timestamp_desc`, `timestamp_asc` | |
462-
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
463-
464-
465-
466460
## Function namespace management commands
467461

468462
Function namespace management commands.

internal/namespaces/container/v1beta1/container_cli.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func GetGeneratedCommands() *core.Commands {
4141
containerCronCreate(),
4242
containerCronUpdate(),
4343
containerCronDelete(),
44+
containerContainerGetLogs(),
4445
containerDomainList(),
4546
containerDomainGet(),
4647
containerDomainCreate(),
@@ -941,6 +942,51 @@ func containerCronDelete() *core.Command {
941942
}
942943
}
943944

945+
func containerContainerGetLogs() *core.Command {
946+
return &core.Command{
947+
Short: `List your container logs`,
948+
Long: `List your container logs.`,
949+
Namespace: "container",
950+
Resource: "container",
951+
Verb: "get-logs",
952+
// Deprecated: false,
953+
ArgsType: reflect.TypeOf(container.ListLogsRequest{}),
954+
ArgSpecs: core.ArgSpecs{
955+
{
956+
Name: "container-id",
957+
Required: true,
958+
Deprecated: false,
959+
Positional: true,
960+
},
961+
{
962+
Name: "order-by",
963+
Required: false,
964+
Deprecated: false,
965+
Positional: false,
966+
EnumValues: []string{"timestamp_desc", "timestamp_asc"},
967+
},
968+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw, scw.Region(core.AllLocalities)),
969+
},
970+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
971+
request := args.(*container.ListLogsRequest)
972+
973+
client := core.ExtractClient(ctx)
974+
api := container.NewAPI(client)
975+
opts := []scw.RequestOption{scw.WithAllPages()}
976+
if request.Region == scw.Region(core.AllLocalities) {
977+
opts = append(opts, scw.WithRegions(api.Regions()...))
978+
request.Region = ""
979+
}
980+
resp, err := api.ListLogs(request, opts...)
981+
if err != nil {
982+
return nil, err
983+
}
984+
return resp.Logs, nil
985+
986+
},
987+
}
988+
}
989+
944990
func containerDomainList() *core.Command {
945991
return &core.Command{
946992
Short: `List all domain name bindings`,

internal/namespaces/function/v1beta1/function_cli.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func GetGeneratedCommands() *core.Commands {
2424
functionFunction(),
2525
functionCron(),
2626
functionRuntime(),
27-
functionLogs(),
2827
functionDomain(),
2928
functionToken(),
3029
functionNamespaceList(),
@@ -46,7 +45,7 @@ func GetGeneratedCommands() *core.Commands {
4645
functionCronCreate(),
4746
functionCronUpdate(),
4847
functionCronDelete(),
49-
functionLogsList(),
48+
functionFunctionGetLogs(),
5049
functionDomainList(),
5150
functionDomainGet(),
5251
functionDomainCreate(),
@@ -101,15 +100,6 @@ func functionRuntime() *core.Command {
101100
}
102101
}
103102

104-
func functionLogs() *core.Command {
105-
return &core.Command{
106-
Short: `Logs management commands`,
107-
Long: `Logs management commands.`,
108-
Namespace: "function",
109-
Resource: "logs",
110-
}
111-
}
112-
113103
func functionDomain() *core.Command {
114104
return &core.Command{
115105
Short: `Domain management commands`,
@@ -1063,21 +1053,21 @@ func functionCronDelete() *core.Command {
10631053
}
10641054
}
10651055

1066-
func functionLogsList() *core.Command {
1056+
func functionFunctionGetLogs() *core.Command {
10671057
return &core.Command{
10681058
Short: `List your application logs`,
10691059
Long: `List your application logs.`,
10701060
Namespace: "function",
1071-
Resource: "logs",
1072-
Verb: "list",
1061+
Resource: "function",
1062+
Verb: "get-logs",
10731063
// Deprecated: false,
10741064
ArgsType: reflect.TypeOf(function.ListLogsRequest{}),
10751065
ArgSpecs: core.ArgSpecs{
10761066
{
10771067
Name: "function-id",
10781068
Required: true,
10791069
Deprecated: false,
1080-
Positional: false,
1070+
Positional: true,
10811071
},
10821072
{
10831073
Name: "order-by",

0 commit comments

Comments
 (0)