Skip to content

Commit

Permalink
feature(cli): adding support for the all flag when listing resources (#…
Browse files Browse the repository at this point in the history
…2501)

* feature(cli): adding support for the all flag when listing resources

* fixing unit tests
  • Loading branch information
xoscar authored May 10, 2023
1 parent 759a323 commit ea3c7f1
Show file tree
Hide file tree
Showing 28 changed files with 1,544 additions and 14 deletions.
18 changes: 18 additions & 0 deletions api/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ components:
type: string
error:
type: string
ConfigurationResourceList:
type: object
properties:
count:
type: integer
items:
type: array
items:
$ref: "#/components/schemas/ConfigurationResource"
ConfigurationResource:
type: object
description: "Represents a configuration structured into the Resources format."
Expand Down Expand Up @@ -64,6 +73,15 @@ components:
description: "Flag telling if a user allow Tracetest to send analytics about its usage."
required:
- analyticsEnabled
PollingProfileList:
type: object
properties:
count:
type: integer
items:
type: array
items:
$ref: "#/components/schemas/PollingProfile"
PollingProfile:
type: object
description: "Represents a polling profile structured into the Resources format."
Expand Down
24 changes: 23 additions & 1 deletion api/dataStores.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
openapi: 3.0.0
components:
schemas:
DataStoreList:
type: object
properties:
count:
type: integer
items:
type: array
items:
$ref: "#/components/schemas/DataStoreResource"
DataStoreResource:
type: object
description: "Represents a data store structured into the Resources format."
Expand Down Expand Up @@ -158,7 +167,20 @@ components:
type: string
SupportedDataStores:
type: string
enum: [jaeger, opensearch, tempo, signalfx, otlp, elasticapm, newrelic, lightstep, datadog, awsxray, honeycomb]
enum:
[
jaeger,
opensearch,
tempo,
signalfx,
otlp,
elasticapm,
newrelic,
lightstep,
datadog,
awsxray,
honeycomb,
]
SupportedClients:
type: string
enum: [http, grpc]
75 changes: 74 additions & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,30 @@ paths:
application/json:
schema:
$ref: "./config.yaml#/components/schemas/TestConnectionResponse"
/configs:
get:
tags:
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/take"
- $ref: "./parameters.yaml#/components/parameters/skip"
- $ref: "./parameters.yaml#/components/parameters/switchableResourceSortBy"
- $ref: "./parameters.yaml#/components/parameters/sortDirection"
summary: "List Tracetest configuration"
description: "List Tracetest configuration"
operationId: listConfiguration
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./config.yaml#/components/schemas/ConfigurationResourceList"
text/yaml:
schema:
$ref: "./config.yaml#/components/schemas/ConfigurationResourceList"
500:
description: "problem getting the configuration list"
/configs/{configId}:
get:
tags:
Expand Down Expand Up @@ -762,7 +786,31 @@ paths:
$ref: "./config.yaml#/components/schemas/ConfigurationResource"
500:
description: "problem updating configuration"


/pollingprofiles:
get:
tags:
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/take"
- $ref: "./parameters.yaml#/components/parameters/skip"
- $ref: "./parameters.yaml#/components/parameters/switchableResourceSortBy"
- $ref: "./parameters.yaml#/components/parameters/sortDirection"
summary: "List Polling Profile Configuration"
description: "List Polling Profile configuration"
operationId: listPollingProfile
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./config.yaml#/components/schemas/PollingProfileList"
text/yaml:
schema:
$ref: "./config.yaml#/components/schemas/PollingProfileList"
500:
description: "problem getting the polling profile list"
# Polling Profile
/pollingprofiles/{pollingProfileId}:
get:
Expand Down Expand Up @@ -953,6 +1001,31 @@ paths:
500:
description: "problem deleting a demo"

/datastores:
get:
tags:
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/take"
- $ref: "./parameters.yaml#/components/parameters/skip"
- $ref: "./parameters.yaml#/components/parameters/switchableResourceSortBy"
- $ref: "./parameters.yaml#/components/parameters/sortDirection"
summary: "List Data Store"
description: "List Data Store"
operationId: listDataStore
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./dataStores.yaml#/components/schemas/DataStoreList"
text/yaml:
schema:
$ref: "./dataStores.yaml#/components/schemas/DataStoreList"
500:
description: "problem getting the data store list"

# Data Stores
/datastores/{dataStoreId}:
get:
Expand Down
3 changes: 1 addition & 2 deletions cli/actions/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package actions

import (
"context"
"fmt"

"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
Expand Down Expand Up @@ -52,7 +51,7 @@ func (config configActions) Get(ctx context.Context, ID string) (*file.File, err
}

func (config configActions) List(ctx context.Context, listArgs utils.ListArgs) (*file.File, error) {
return nil, fmt.Errorf("Config does not support listing. Try `tracetest get config` instead")
return config.resourceClient.List(ctx, listArgs)
}

func (config configActions) Delete(ctx context.Context, ID string) (string, error) {
Expand Down
3 changes: 1 addition & 2 deletions cli/actions/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package actions

import (
"context"
"fmt"

"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
Expand Down Expand Up @@ -51,7 +50,7 @@ func (d *dataStoreActions) Apply(ctx context.Context, fileContent file.File) (re
}

func (d *dataStoreActions) List(ctx context.Context, args utils.ListArgs) (*file.File, error) {
return nil, fmt.Errorf("DataStore does not support listing. Try `tracetest get datastore`")
return d.resourceClient.List(ctx, args)
}

func (d *dataStoreActions) Get(ctx context.Context, id string) (*file.File, error) {
Expand Down
2 changes: 1 addition & 1 deletion cli/actions/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (polling pollingActions) Apply(ctx context.Context, fileContent file.File)
}

func (polling pollingActions) List(ctx context.Context, listArgs utils.ListArgs) (*file.File, error) {
return nil, ErrNotSupportedResourceAction
return polling.resourceClient.List(ctx, listArgs)
}

func (polling pollingActions) Delete(ctx context.Context, ID string) (string, error) {
Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/list_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
listSkip int32
listSortBy string
listSortDirection string
listAll bool
)

var listCmd = &cobra.Command{
Expand Down Expand Up @@ -47,6 +48,7 @@ var listCmd = &cobra.Command{
Skip: listSkip,
SortDirection: listSortDirection,
SortBy: listSortBy,
All: listAll,
}

resource, err := resourceActions.List(ctx, listArgs)
Expand Down Expand Up @@ -76,6 +78,7 @@ func init() {
listCmd.Flags().Int32Var(&listSkip, "skip", 0, "Skip number")
listCmd.Flags().StringVar(&listSortBy, "sortBy", "", "Sort by")
listCmd.Flags().StringVar(&listSortDirection, "sortDirection", "desc", "Sort direction")
listCmd.Flags().BoolVar(&listAll, "all", false, "All")

rootCmd.AddCommand(listCmd)
}
33 changes: 31 additions & 2 deletions cli/formatters/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@ func (f ConfigFormatter) ToTable(file *file.File) (*simpletable.Header, *simplet
}

func (f ConfigFormatter) ToListTable(file *file.File) (*simpletable.Header, *simpletable.Body, error) {
return nil, nil, nil
rawConfigList, err := f.ToListStruct(file)
if err != nil {
return nil, nil, err
}

body := simpletable.Body{}
for _, rawConfig := range rawConfigList {
configResource := rawConfig.(openapi.ConfigurationResource)
row, err := f.getTableRow(configResource)
if err != nil {
return nil, nil, err
}

body.Cells = append(body.Cells, row)
}

return f.getTableHeader(), &body, nil
}

func (f ConfigFormatter) ToStruct(file *file.File) (interface{}, error) {
Expand All @@ -51,7 +67,20 @@ func (f ConfigFormatter) ToStruct(file *file.File) (interface{}, error) {
}

func (f ConfigFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
return nil, nil
var ConfigResourceList openapi.ConfigurationResourceList
nullableList := openapi.NewNullableConfigurationResourceList(&ConfigResourceList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
if err != nil {
return nil, err
}

items := make([]interface{}, len(ConfigResourceList.Items))
for i, item := range ConfigResourceList.Items {
items[i] = item
}

return items, nil
}

func (f ConfigFormatter) getTableHeader() *simpletable.Header {
Expand Down
33 changes: 31 additions & 2 deletions cli/formatters/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ func (f DatastoreFormatter) ToTable(file *file.File) (*simpletable.Header, *simp
}

func (f DatastoreFormatter) ToListTable(file *file.File) (*simpletable.Header, *simpletable.Body, error) {
return nil, nil, nil
rawList, err := f.ToListStruct(file)
if err != nil {
return nil, nil, err
}

body := simpletable.Body{}
for _, raw := range rawList {
resource := raw.(openapi.DataStoreResource)
row, err := f.getTableRow(resource)
if err != nil {
return nil, nil, err
}

body.Cells = append(body.Cells, row)
}

return f.getTableHeader(), &body, nil
}

func (f DatastoreFormatter) ToStruct(file *file.File) (interface{}, error) {
Expand All @@ -49,7 +65,20 @@ func (f DatastoreFormatter) ToStruct(file *file.File) (interface{}, error) {
}

func (f DatastoreFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
return nil, nil
var dataStoreList openapi.DataStoreList
nullableList := openapi.NewNullableDataStoreList(&dataStoreList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
if err != nil {
return nil, err
}

items := make([]interface{}, len(dataStoreList.Items))
for i, item := range dataStoreList.Items {
items[i] = item
}

return items, nil
}

func (f DatastoreFormatter) getTableHeader() *simpletable.Header {
Expand Down
33 changes: 31 additions & 2 deletions cli/formatters/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ func (f PollingFormatter) ToTable(file *file.File) (*simpletable.Header, *simple
}

func (f PollingFormatter) ToListTable(file *file.File) (*simpletable.Header, *simpletable.Body, error) {
return nil, nil, nil
rawPollingList, err := f.ToListStruct(file)
if err != nil {
return nil, nil, err
}

body := simpletable.Body{}
for _, rawPolling := range rawPollingList {
pollingResource := rawPolling.(openapi.PollingProfile)
row, err := f.getTableRow(pollingResource)
if err != nil {
return nil, nil, err
}

body.Cells = append(body.Cells, row)
}

return f.getTableHeader(), &body, nil
}

func (f PollingFormatter) ToStruct(file *file.File) (interface{}, error) {
Expand All @@ -49,7 +65,20 @@ func (f PollingFormatter) ToStruct(file *file.File) (interface{}, error) {
}

func (f PollingFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
return nil, nil
var pollingProfileList openapi.PollingProfileList
nullableList := openapi.NewNullablePollingProfileList(&pollingProfileList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
if err != nil {
return nil, err
}

items := make([]interface{}, len(pollingProfileList.Items))
for i, item := range pollingProfileList.Items {
items[i] = item
}

return items, nil
}

func (f PollingFormatter) getTableHeader() *simpletable.Header {
Expand Down
Loading

0 comments on commit ea3c7f1

Please sign in to comment.