Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased]

- Support multiple group by fields in SLOs ([#870](https://github.com/elastic/terraform-provider-elasticstack/pull/878))
- Use the auto-generated OAS schema from elastic/kibana for the Fleet API. ([#834](https://github.com/elastic/terraform-provider-elasticstack/issues/834))

## [0.11.11] - 2024-10-25
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/kibana_slo.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ resource "elasticstack_kibana_slo" "custom_metric" {

- `apm_availability_indicator` (Block List, Max: 1) (see [below for nested schema](#nestedblock--apm_availability_indicator))
- `apm_latency_indicator` (Block List, Max: 1) (see [below for nested schema](#nestedblock--apm_latency_indicator))
- `group_by` (String) Optional group by field to use to generate an SLO per distinct value.
- `group_by` (List of String) Optional group by fields to use to generate an SLO per distinct value.
- `histogram_custom_indicator` (Block List, Max: 1) (see [below for nested schema](#nestedblock--histogram_custom_indicator))
- `kql_custom_indicator` (Block List, Max: 1) (see [below for nested schema](#nestedblock--kql_custom_indicator))
- `metric_custom_indicator` (Block List, Max: 1) (see [below for nested schema](#nestedblock--metric_custom_indicator))
Expand Down
8 changes: 8 additions & 0 deletions generated/slo-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,14 @@ components:
$ref: '#/components/schemas/objective'
settings:
$ref: '#/components/schemas/settings'
groupBy:
description: optional group by field to use to generate an SLO per distinct value
oneOf:
- type: string
- type: array
items:
type: string
example: some.field
tags:
description: List of tags
type: array
Expand Down
2 changes: 2 additions & 0 deletions generated/slo/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,8 @@ components:
$ref: '#/components/schemas/objective'
settings:
$ref: '#/components/schemas/settings'
groupBy:
$ref: '#/components/schemas/slo_response_groupBy'
tags:
description: List of tags
items:
Expand Down
26 changes: 26 additions & 0 deletions generated/slo/docs/UpdateSloRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Name | Type | Description | Notes
**BudgetingMethod** | Pointer to [**BudgetingMethod**](BudgetingMethod.md) | | [optional]
**Objective** | Pointer to [**Objective**](Objective.md) | | [optional]
**Settings** | Pointer to [**Settings**](Settings.md) | | [optional]
**GroupBy** | Pointer to [**SloResponseGroupBy**](SloResponseGroupBy.md) | | [optional]
**Tags** | Pointer to **[]string** | List of tags | [optional]

## Methods
Expand Down Expand Up @@ -207,6 +208,31 @@ SetSettings sets Settings field to given value.

HasSettings returns a boolean if a field has been set.

### GetGroupBy

`func (o *UpdateSloRequest) GetGroupBy() SloResponseGroupBy`

GetGroupBy returns the GroupBy field if non-nil, zero value otherwise.

### GetGroupByOk

`func (o *UpdateSloRequest) GetGroupByOk() (*SloResponseGroupBy, bool)`

GetGroupByOk returns a tuple with the GroupBy field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetGroupBy

`func (o *UpdateSloRequest) SetGroupBy(v SloResponseGroupBy)`

SetGroupBy sets GroupBy field to given value.

### HasGroupBy

`func (o *UpdateSloRequest) HasGroupBy() bool`

HasGroupBy returns a boolean if a field has been set.

### GetTags

`func (o *UpdateSloRequest) GetTags() []string`
Expand Down
4 changes: 2 additions & 2 deletions generated/slo/model_slo_response_group_by.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions generated/slo/model_update_slo_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 25 additions & 5 deletions internal/clients/kibana/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func DeleteSlo(ctx context.Context, apiClient *clients.ApiClient, sloId string,
return utils.CheckHttpError(res, "Unabled to delete slo with ID "+string(sloId))
}

func UpdateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo) (*models.Slo, diag.Diagnostics) {
func UpdateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo, supportsGroupByList bool) (*models.Slo, diag.Diagnostics) {
client, err := apiClient.GetSloClient()
if err != nil {
return nil, diag.FromErr(err)
Expand All @@ -72,6 +72,7 @@ func UpdateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo)
BudgetingMethod: (*slo.BudgetingMethod)(&s.BudgetingMethod),
Objective: &s.Objective,
Settings: s.Settings,
GroupBy: transformGroupBy(s.GroupBy, supportsGroupByList),
Tags: s.Tags,
}

Expand All @@ -90,7 +91,7 @@ func UpdateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo)
return sloResponseToModel(s.SpaceID, slo), diag.Diagnostics{}
}

func CreateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo) (*models.Slo, diag.Diagnostics) {
func CreateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo, supportsGroupByList bool) (*models.Slo, diag.Diagnostics) {
client, err := apiClient.GetSloClient()
if err != nil {
return nil, diag.FromErr(err)
Expand All @@ -109,7 +110,7 @@ func CreateSlo(ctx context.Context, apiClient *clients.ApiClient, s models.Slo)
BudgetingMethod: slo.BudgetingMethod(s.BudgetingMethod),
Objective: s.Objective,
Settings: s.Settings,
GroupBy: transformGroupBy(s.GroupBy),
GroupBy: transformGroupBy(s.GroupBy, supportsGroupByList),
Tags: s.Tags,
}

Expand Down Expand Up @@ -177,14 +178,33 @@ func sloResponseToModel(spaceID string, res *slo.SloResponse) *models.Slo {
TimeWindow: res.TimeWindow,
Objective: res.Objective,
Settings: &res.Settings,
GroupBy: transformGroupByFromResponse(res.GroupBy),
Tags: res.Tags,
}
}

func transformGroupBy(groupBy *string) *slo.SloResponseGroupBy {
func transformGroupBy(groupBy []string, supportsGroupByList bool) *slo.SloResponseGroupBy {
if groupBy == nil {
return nil
}

return &slo.SloResponseGroupBy{String: groupBy}
if !supportsGroupByList && len(groupBy) > 0 {
return &slo.SloResponseGroupBy{
String: &groupBy[0],
}
}

return &slo.SloResponseGroupBy{ArrayOfString: &groupBy}
}

func transformGroupByFromResponse(groupBy slo.SloResponseGroupBy) []string {
if groupBy.String != nil {
return []string{*groupBy.String}
}

if groupBy.ArrayOfString == nil {
return nil
}

return *groupBy.ArrayOfString
}
Loading
Loading