Skip to content
Open
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
12 changes: 8 additions & 4 deletions docs/stackit_beta_telemetry-router_instance_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ stackit beta telemetry-router instance create [flags]
Create a Telemetry Router instance with name "my-instance" and a description
$ stackit beta telemetry-router instance create --display-name "my-instance" --description "Description of the instance"

Create a Telemetry Router instance with name "my-instance" and labels
$ stackit beta telemetry-router instance create --display-name "my-instance" --labels "env=prod,team=sre"

Create a Telemetry Router instance with name "my-instance" that only routes telemetry data for HTTP GET or HEAD requests, matched at the resource level, using a filter configuration sourced from a JSON file; use "stackit beta telemetry-router instance generate-filter" to generate a starting point for "./filter.json"; available attributes are documented in https://docs.stackit.cloud/products/logging-and-monitoring/telemetry-router/basics/dataformats/
$ stackit beta telemetry-router instance create --display-name "my-instance" --filter @./filter.json
```

### Options

```
--description string Description
--display-name string Display name
--filter string Filter configuration as JSON, of the form {"attributes": [{"key": ..., "level": ..., "matcher": ..., "values": [...]}, ...]}. Can be a JSON string or a file path, if prefixed with "@" (example: @./filter.json). Run "stackit beta telemetry-router instance generate-filter" to generate a starting point.
-h, --help[=true|false] Help for "stackit beta telemetry-router instance create"
--description string Description
--display-name string Display name
--filter string Filter configuration as JSON, of the form {"attributes": [{"key": ..., "level": ..., "matcher": ..., "values": [...]}, ...]}. Can be a JSON string or a file path, if prefixed with "@" (example: @./filter.json). Run "stackit beta telemetry-router instance generate-filter" to generate a starting point.
-h, --help[=true|false] Help for "stackit beta telemetry-router instance create"
--labels stringToString Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2". (default [])
```

### Options inherited from parent commands
Expand Down
12 changes: 8 additions & 4 deletions docs/stackit_beta_telemetry-router_instance_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ stackit beta telemetry-router instance update INSTANCE_ID [flags]
Update the description of the Telemetry Router instance with ID "xxx"
$ stackit beta telemetry-router instance update xxx --description new-description

Update the labels of the Telemetry Router instance with ID "xxx"
$ stackit beta telemetry-router instance update xxx --labels "env=prod,team=sre"

Replace the filter attributes of the Telemetry Router instance with ID "xxx" with a filter configuration sourced from a JSON file so it only routes telemetry data for HTTP GET or HEAD requests, matched at the resource level; use "stackit beta telemetry-router instance generate-filter --instance-id xxx" to generate a starting point from the instance's current filter
$ stackit beta telemetry-router instance update xxx --filter @./filter.json
```

### Options

```
--description string Description
--display-name string Display name
--filter string Filter configuration as JSON, of the form {"attributes": [{"key": ..., "level": ..., "matcher": ..., "values": [...]}, ...], "disabled": ...}. Can be a JSON string or a file path, if prefixed with "@" (example: @./filter.json). Only the provided fields are updated: if "attributes" is set, it replaces any existing filter attributes on the instance; if "disabled" is set, it enables or disables the filter without changing its attributes (example: {"disabled": true}). Run "stackit beta telemetry-router instance generate-filter --instance-id <id>" to generate a starting point from the instance's current filter. Clearing all filter attributes is not supported; an empty "attributes" list leaves the existing attributes unchanged.
-h, --help[=true|false] Help for "stackit beta telemetry-router instance update"
--description string Description
--display-name string Display name
--filter string Filter configuration as JSON, of the form {"attributes": [{"key": ..., "level": ..., "matcher": ..., "values": [...]}, ...], "disabled": ...}. Can be a JSON string or a file path, if prefixed with "@" (example: @./filter.json). Only the provided fields are updated: if "attributes" is set, it replaces any existing filter attributes on the instance; if "disabled" is set, it enables or disables the filter without changing its attributes (example: {"disabled": true}). Run "stackit beta telemetry-router instance generate-filter --instance-id <id>" to generate a starting point from the instance's current filter. Clearing all filter attributes is not supported; an empty "attributes" list leaves the existing attributes unchanged.
-h, --help[=true|false] Help for "stackit beta telemetry-router instance update"
--labels stringToString Labels in key=value format, separated by commas. Replaces all existing labels. Example: --labels "key1=value1,key2=value2". (default [])
```

### Options inherited from parent commands
Expand Down
14 changes: 11 additions & 3 deletions internal/cmd/beta/telemetryrouter/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
displayNameFlag = "display-name"
descriptionFlag = "description"
filterFlag = "filter"
labelsFlag = "labels"
)

type inputModel struct {
Expand All @@ -37,6 +38,7 @@ type inputModel struct {
DisplayName string
Description *string
Filter *telemetryrouter.ConfigFilter
Labels *map[string]string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand All @@ -52,6 +54,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
examples.NewExample(
`Create a Telemetry Router instance with name "my-instance" and a description`,
`$ stackit beta telemetry-router instance create --display-name "my-instance" --description "Description of the instance"`),
examples.NewExample(
`Create a Telemetry Router instance with name "my-instance" and labels`,
`$ stackit beta telemetry-router instance create --display-name "my-instance" --labels "env=prod,team=sre"`),
examples.NewExample(
`Create a Telemetry Router instance with name "my-instance" that only routes telemetry data for HTTP GET or HEAD requests, matched at the resource level, using a filter configuration sourced from a JSON file; `+
`use "stackit beta telemetry-router instance generate-filter" to generate a starting point for "./filter.json"; `+
Expand Down Expand Up @@ -128,6 +133,7 @@ func configureFlags(cmd *cobra.Command) {
`Filter configuration as JSON, of the form {"attributes": [{"key": ..., "level": ..., "matcher": ..., "values": [...]}, ...]}. `+
`Can be a JSON string or a file path, if prefixed with "@" (example: @./filter.json). `+
`Run "stackit beta telemetry-router instance generate-filter" to generate a starting point.`)
cmd.Flags().StringToString(labelsFlag, nil, `Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2".`)

err := flags.MarkFlagsRequired(cmd, displayNameFlag)
cobra.CheckErr(err)
Expand All @@ -149,6 +155,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
DisplayName: flags.FlagToStringValue(p, cmd, displayNameFlag),
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
Filter: filter,
Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag),
}

p.DebugInputModel(model)
Expand All @@ -169,9 +176,10 @@ func parseFilter(p *print.Printer, cmd *cobra.Command) (*telemetryrouter.ConfigF
func buildRequest(ctx context.Context, model *inputModel, apiClient telemetryrouter.DefaultAPI) telemetryrouter.ApiCreateTelemetryRouterRequest {
req := apiClient.CreateTelemetryRouter(ctx, model.ProjectId, model.Region)
req = req.CreateTelemetryRouterPayload(telemetryrouter.CreateTelemetryRouterPayload{
DisplayName: model.DisplayName,
Description: model.Description,
Filter: model.Filter,
DisplayName: model.DisplayName,
Description: model.Description,
Filter: model.Filter,
ResourceLabels: model.Labels,
})

return req
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func TestParseInput(t *testing.T) {
flagValues: map[string]string{},
isValid: false,
},
{
description: "with labels",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[labelsFlag] = "env=prod,team=sre"
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
model.Labels = &map[string]string{"env": "prod", "team": "sre"}
}),
},
{
description: "no filter at all still works, Filter stays nil",
flagValues: fixtureFlagValues(),
Expand Down Expand Up @@ -246,6 +256,17 @@ func TestBuildRequest(t *testing.T) {
},
}),
},
{
description: "with labels",
model: fixtureInputModel(func(model *inputModel) {
model.Labels = &map[string]string{"env": "prod"}
}),
expectedRequest: fixtureRequest().CreateTelemetryRouterPayload(telemetryrouter.CreateTelemetryRouterPayload{
DisplayName: testDisplayName,
Description: new(testDescription),
ResourceLabels: &map[string]string{"env": "prod"},
}),
},
}

for _, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func outputResult(p *print.Printer, outputFormat string, instance *telemetryrout
table.AddSeparator()
table.AddRow("CREATION TIME", instance.CreationTime.Format(time.DateTime))

if len(instance.GetResourceLabels()) > 0 {
table.AddSeparator()
table.AddRow("LABELS", utils.JoinStringMap(instance.GetResourceLabels(), ": ", "\n"))
}

if instance.Filter != nil {
table.AddSeparator()
table.AddRow("FILTER DISABLED", utils.PtrString(instance.Filter.Disabled))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ func TestOutputResult(t *testing.T) {
}},
wantErr: false,
},
{
name: "default output with labels",
args: args{outputFormat: "default", instance: &telemetryrouter.TelemetryRouterResponse{
ResourceLabels: &map[string]string{"env": "prod", "team": "sre"},
}},
wantErr: false,
},
{
name: "json output",
args: args{outputFormat: print.JSONOutputFormat, instance: &telemetryrouter.TelemetryRouterResponse{}},
Expand Down
17 changes: 13 additions & 4 deletions internal/cmd/beta/telemetryrouter/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
displayNameFlag = "display-name"
descriptionFlag = "description"
filterFlag = "filter"
labelsFlag = "labels"
)

type inputModel struct {
Expand All @@ -37,6 +38,7 @@ type inputModel struct {
DisplayName *string
Description *string
Filter *telemetryrouter.ConfigFilterPatch
Labels *map[string]string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand All @@ -52,6 +54,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
examples.NewExample(
`Update the description of the Telemetry Router instance with ID "xxx"`,
"$ stackit beta telemetry-router instance update xxx --description new-description"),
examples.NewExample(
`Update the labels of the Telemetry Router instance with ID "xxx"`,
`$ stackit beta telemetry-router instance update xxx --labels "env=prod,team=sre"`),
examples.NewExample(
`Replace the filter attributes of the Telemetry Router instance with ID "xxx" with a filter configuration sourced from a JSON file so it only routes telemetry data for HTTP GET or HEAD requests, matched at the resource level; `+
`use "stackit beta telemetry-router instance generate-filter --instance-id xxx" to generate a starting point from the instance's current filter`,
Expand Down Expand Up @@ -131,6 +136,7 @@ func configureFlags(cmd *cobra.Command) {
`the filter without changing its attributes (example: {"disabled": true}). Run "stackit beta telemetry-router instance generate-filter --instance-id <id>" `+
`to generate a starting point from the instance's current filter. Clearing all filter attributes is not supported; `+
`an empty "attributes" list leaves the existing attributes unchanged.`)
cmd.Flags().StringToString(labelsFlag, nil, `Labels in key=value format, separated by commas. Replaces all existing labels. Example: --labels "key1=value1,key2=value2".`)
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
Expand All @@ -144,6 +150,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
displayName := flags.FlagToStringPointer(p, cmd, displayNameFlag)
description := flags.FlagToStringPointer(p, cmd, descriptionFlag)
filterValue := flags.FlagToStringPointer(p, cmd, filterFlag)
labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag)

var filter *telemetryrouter.ConfigFilterPatch
if filterValue != nil {
Expand All @@ -155,7 +162,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
filter = parsedFilter
}

if displayName == nil && description == nil && filter == nil {
if displayName == nil && description == nil && filter == nil && labels == nil {
return nil, &errors.EmptyUpdateError{}
}

Expand All @@ -165,6 +172,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
DisplayName: displayName,
Description: description,
Filter: filter,
Labels: labels,
}

p.DebugInputModel(model)
Expand All @@ -177,9 +185,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient telemetryrou

// Partial update: fields which are not set (nil) are left unchanged on API side
return req.PartialUpdateTelemetryRouterPayload(telemetryrouter.PartialUpdateTelemetryRouterPayload{
DisplayName: model.DisplayName,
Description: model.Description,
Filter: model.Filter,
DisplayName: model.DisplayName,
Description: model.Description,
Filter: model.Filter,
ResourceLabels: model.Labels,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ func TestParseInput(t *testing.T) {
Description: new("description"),
},
},
{
description: "labels only",
argValues: fixtureArgValues(),
flagValues: map[string]string{
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
labelsFlag: "env=prod,team=sre",
},
isValid: true,
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: testInstanceId,
Labels: &map[string]string{"env": "prod", "team": "sre"},
},
},
{
description: "project id missing",
argValues: fixtureArgValues(),
Expand Down Expand Up @@ -322,6 +341,17 @@ func TestBuildRequest(t *testing.T) {
},
}),
},
{
description: "with labels",
model: fixtureInputModel(func(model *inputModel) {
model.Labels = &map[string]string{"env": "prod"}
}),
expectedRequest: fixtureRequest().PartialUpdateTelemetryRouterPayload(telemetryrouter.PartialUpdateTelemetryRouterPayload{
DisplayName: new("name"),
Description: new("Example"),
ResourceLabels: &map[string]string{"env": "prod"},
}),
},
}

for _, tt := range tests {
Expand Down
Loading