Skip to content

Commit 5740b7e

Browse files
(Backport) Fix SLO client (#1716)
v2 of #1697
1 parent 55cc616 commit 5740b7e

File tree

6 files changed

+54
-54
lines changed

6 files changed

+54
-54
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240322153219-42c6a1d2bcab
1313
github.com/grafana/grafana-openapi-client-go v0.0.0-20240430202104-3ad0f7e4ee52
1414
github.com/grafana/machine-learning-go-client v0.5.0
15-
github.com/grafana/slo-openapi-client/go v0.0.0-20240112175006-de02e75b9d73
15+
github.com/grafana/slo-openapi-client/go v0.0.0-20240717162314-26344962b4c5
1616
github.com/grafana/synthetic-monitoring-agent v0.24.1
1717
github.com/grafana/synthetic-monitoring-api-go-client v0.8.0
1818
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ github.com/grafana/grafana-openapi-client-go v0.0.0-20240430202104-3ad0f7e4ee52
106106
github.com/grafana/grafana-openapi-client-go v0.0.0-20240430202104-3ad0f7e4ee52/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI=
107107
github.com/grafana/machine-learning-go-client v0.5.0 h1:Q1K+MPSy8vfMm2jsk3WQ7O77cGr2fM5hxwtPSoPc5NU=
108108
github.com/grafana/machine-learning-go-client v0.5.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
109-
github.com/grafana/slo-openapi-client/go v0.0.0-20240112175006-de02e75b9d73 h1:E5vAeB5q1H3BVeNhtd1dI8RubucJdPwpx/ElNtKD3ls=
110-
github.com/grafana/slo-openapi-client/go v0.0.0-20240112175006-de02e75b9d73/go.mod h1:EvM3pcxqS+avXd0G8VMyo/kITr9QsN1CwZTNgYtQ9lI=
109+
github.com/grafana/slo-openapi-client/go v0.0.0-20240717162314-26344962b4c5 h1:qUb8ZPVC/QQDh8uCH9ZObZnsdT9S7iX3qe3q73XLj/o=
110+
github.com/grafana/slo-openapi-client/go v0.0.0-20240717162314-26344962b4c5/go.mod h1:HgbbeH2gFfCk2XZCrCly39DB13WkwWyQ+Ww+HTxePCs=
111111
github.com/grafana/synthetic-monitoring-agent v0.24.1 h1:BVruIcSLM5EpNtN5Z8ApdkoVSoFuUoR1YLC1pu44Lng=
112112
github.com/grafana/synthetic-monitoring-agent v0.24.1/go.mod h1:izlTwdDryrndATx2rSAtyjplvccPdIg+Zm331+Oy9hU=
113113
github.com/grafana/synthetic-monitoring-api-go-client v0.8.0 h1:Tm4MtwwYmPNInGfnj66l6j6KOshMkNV4emIVKJdlXMg=

internal/resources/slo/data_source_slo.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func datasourceSloRead(ctx context.Context, d *schema.ResourceData, client *slo.
6868
return diags
6969
}
7070

71-
func convertDatasourceSlo(slo slo.Slo) map[string]interface{} {
71+
func convertDatasourceSlo(slo slo.SloV00Slo) map[string]interface{} {
7272
ret := make(map[string]interface{})
7373

7474
ret["uuid"] = slo.Uuid
@@ -91,7 +91,7 @@ func convertDatasourceSlo(slo slo.Slo) map[string]interface{} {
9191
return ret
9292
}
9393

94-
func unpackQuery(apiquery slo.Query) []map[string]interface{} {
94+
func unpackQuery(apiquery slo.SloV00Query) []map[string]interface{} {
9595
retQuery := []map[string]interface{}{}
9696

9797
if apiquery.Type == QueryTypeFreeform {
@@ -124,7 +124,7 @@ func unpackQuery(apiquery slo.Query) []map[string]interface{} {
124124
return retQuery
125125
}
126126

127-
func unpackObjectives(objectives []slo.Objective) []map[string]interface{} {
127+
func unpackObjectives(objectives []slo.SloV00Objective) []map[string]interface{} {
128128
retObjectives := []map[string]interface{}{}
129129

130130
for _, objective := range objectives {
@@ -140,22 +140,22 @@ func unpackObjectives(objectives []slo.Objective) []map[string]interface{} {
140140
func unpackLabels(labelsInterface interface{}) []map[string]interface{} {
141141
retLabels := []map[string]interface{}{}
142142

143-
var labels []slo.Label
143+
var labels []slo.SloV00Label
144144
switch v := labelsInterface.(type) {
145-
case *[]slo.Label:
145+
case *[]slo.SloV00Label:
146146
labels = *v
147-
case []slo.Label:
147+
case []slo.SloV00Label:
148148
labels = v
149149
case []interface{}:
150150
for _, labelInterface := range v {
151151
switch v := labelInterface.(type) {
152152
case map[string]interface{}:
153-
label := slo.Label{
153+
label := slo.SloV00Label{
154154
Key: v["key"].(string),
155155
Value: v["value"].(string),
156156
}
157157
labels = append(labels, label)
158-
case slo.Label:
158+
case slo.SloV00Label:
159159
labels = append(labels, v)
160160
}
161161
}
@@ -170,7 +170,7 @@ func unpackLabels(labelsInterface interface{}) []map[string]interface{} {
170170
return retLabels
171171
}
172172

173-
func unpackAlerting(alertData *slo.Alerting) []map[string]interface{} {
173+
func unpackAlerting(alertData *slo.SloV00Alerting) []map[string]interface{} {
174174
retAlertData := []map[string]interface{}{}
175175

176176
if alertData == nil {
@@ -193,7 +193,7 @@ func unpackAlerting(alertData *slo.Alerting) []map[string]interface{} {
193193
return retAlertData
194194
}
195195

196-
func unpackAlertingMetadata(metaData slo.AlertingMetadata) []map[string]interface{} {
196+
func unpackAlertingMetadata(metaData slo.SloV00AlertingMetadata) []map[string]interface{} {
197197
retAlertMetaData := []map[string]interface{}{}
198198
labelsAnnotsStruct := make(map[string]interface{})
199199

@@ -211,7 +211,7 @@ func unpackAlertingMetadata(metaData slo.AlertingMetadata) []map[string]interfac
211211
return retAlertMetaData
212212
}
213213

214-
func unpackDestinationDatasource(destinationDatasource *slo.DestinationDatasource) []map[string]interface{} {
214+
func unpackDestinationDatasource(destinationDatasource *slo.SloV00DestinationDatasource) []map[string]interface{} {
215215
retDestinationDatasources := []map[string]interface{}{}
216216

217217
retDestinationDatasource := make(map[string]interface{})

internal/resources/slo/data_source_slo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestAccDataSourceSlo(t *testing.T) {
1414

1515
randomName := acctest.RandomWithPrefix("SLO Terraform Testing")
1616

17-
var slo slo.Slo
17+
var slo slo.SloV00Slo
1818
resource.ParallelTest(t, resource.TestCase{
1919
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2020
CheckDestroy: testAccSloCheckDestroy(&slo),

internal/resources/slo/resource_slo.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func resourceSloCreate(ctx context.Context, d *schema.ResourceData, client *slo.
275275
return diags
276276
}
277277

278-
req := client.DefaultAPI.V1SloPost(ctx).Slo(sloModel)
278+
req := client.DefaultAPI.V1SloPost(ctx).SloV00Slo(sloModel)
279279
response, _, err := req.Execute()
280280

281281
if err != nil {
@@ -320,7 +320,7 @@ func resourceSloUpdate(ctx context.Context, d *schema.ResourceData, client *slo.
320320
return diags
321321
}
322322

323-
req := client.DefaultAPI.V1SloIdPut(ctx, sloID).Slo(slo)
323+
req := client.DefaultAPI.V1SloIdPut(ctx, sloID).SloV00Slo(slo)
324324
if _, err := req.Execute(); err != nil {
325325
return apiError("Unable to Update SLO - API", err)
326326
}
@@ -340,19 +340,19 @@ func resourceSloDelete(ctx context.Context, d *schema.ResourceData, client *slo.
340340

341341
// Fetches all the Properties defined on the Terraform SLO State Object and converts it
342342
// to a Slo so that it can be converted to JSON and sent to the API
343-
func packSloResource(d *schema.ResourceData) (slo.Slo, error) {
343+
func packSloResource(d *schema.ResourceData) (slo.SloV00Slo, error) {
344344
var (
345-
tfalerting slo.Alerting
346-
tflabels []slo.Label
347-
tfdestinationdatasource slo.DestinationDatasource
345+
tfalerting slo.SloV00Alerting
346+
tflabels []slo.SloV00Label
347+
tfdestinationdatasource slo.SloV00DestinationDatasource
348348
)
349349

350350
tfname := d.Get("name").(string)
351351
tfdescription := d.Get("description").(string)
352352
query := d.Get("query").([]interface{})[0].(map[string]interface{})
353353
tfquery, err := packQuery(query)
354354
if err != nil {
355-
return slo.Slo{}, err
355+
return slo.SloV00Slo{}, err
356356
}
357357

358358
objectives := d.Get("objectives").([]interface{})
@@ -363,7 +363,7 @@ func packSloResource(d *schema.ResourceData) (slo.Slo, error) {
363363
tflabels = packLabels(labels)
364364
}
365365

366-
slo := slo.Slo{
366+
slo := slo.SloV00Slo{
367367
Uuid: d.Id(),
368368
Name: tfname,
369369
Description: tfdescription,
@@ -402,8 +402,8 @@ func packSloResource(d *schema.ResourceData) (slo.Slo, error) {
402402
return slo, nil
403403
}
404404

405-
func packDestinationDatasource(destinationdatasource map[string]interface{}) (slo.DestinationDatasource, error) {
406-
packedDestinationDatasource := slo.DestinationDatasource{}
405+
func packDestinationDatasource(destinationdatasource map[string]interface{}) (slo.SloV00DestinationDatasource, error) {
406+
packedDestinationDatasource := slo.SloV00DestinationDatasource{}
407407

408408
if destinationdatasource["uid"].(string) != "" {
409409
datasourceUID := destinationdatasource["uid"].(string)
@@ -413,13 +413,13 @@ func packDestinationDatasource(destinationdatasource map[string]interface{}) (sl
413413
return packedDestinationDatasource, nil
414414
}
415415

416-
func packQuery(query map[string]interface{}) (slo.Query, error) {
416+
func packQuery(query map[string]interface{}) (slo.SloV00Query, error) {
417417
if query["type"] == "freeform" {
418418
freeformquery := query["freeform"].([]interface{})[0].(map[string]interface{})
419419
querystring := freeformquery["query"].(string)
420420

421-
sloQuery := slo.Query{
422-
Freeform: &slo.FreeformQuery{Query: querystring},
421+
sloQuery := slo.SloV00Query{
422+
Freeform: &slo.SloV00FreeformQuery{Query: querystring},
423423
Type: QueryTypeFreeform,
424424
}
425425

@@ -442,12 +442,12 @@ func packQuery(query map[string]interface{}) (slo.Query, error) {
442442
labels = append(labels, groupByLabels[ind].(string))
443443
}
444444

445-
sloQuery := slo.Query{
446-
Ratio: &slo.RatioQuery{
447-
SuccessMetric: slo.MetricDef{
445+
sloQuery := slo.SloV00Query{
446+
Ratio: &slo.SloV00RatioQuery{
447+
SuccessMetric: slo.SloV00MetricDef{
448448
PrometheusMetric: successMetric,
449449
},
450-
TotalMetric: slo.MetricDef{
450+
TotalMetric: slo.SloV00MetricDef{
451451
PrometheusMetric: totalMetric,
452452
},
453453
GroupByLabels: labels,
@@ -458,15 +458,15 @@ func packQuery(query map[string]interface{}) (slo.Query, error) {
458458
return sloQuery, nil
459459
}
460460

461-
return slo.Query{}, fmt.Errorf("%s query type not implemented", query["type"])
461+
return slo.SloV00Query{}, fmt.Errorf("%s query type not implemented", query["type"])
462462
}
463463

464-
func packObjectives(tfobjectives []interface{}) []slo.Objective {
465-
objectives := []slo.Objective{}
464+
func packObjectives(tfobjectives []interface{}) []slo.SloV00Objective {
465+
objectives := []slo.SloV00Objective{}
466466

467467
for ind := range tfobjectives {
468468
tfobjective := tfobjectives[ind].(map[string]interface{})
469-
objective := slo.Objective{
469+
objective := slo.SloV00Objective{
470470
Value: tfobjective["value"].(float64),
471471
Window: tfobjective["window"].(string),
472472
}
@@ -476,12 +476,12 @@ func packObjectives(tfobjectives []interface{}) []slo.Objective {
476476
return objectives
477477
}
478478

479-
func packLabels(tfLabels []interface{}) []slo.Label {
480-
labelSlice := []slo.Label{}
479+
func packLabels(tfLabels []interface{}) []slo.SloV00Label {
480+
labelSlice := []slo.SloV00Label{}
481481

482482
for ind := range tfLabels {
483483
currLabel := tfLabels[ind].(map[string]interface{})
484-
curr := slo.Label{
484+
curr := slo.SloV00Label{
485485
Key: currLabel["key"].(string),
486486
Value: currLabel["value"].(string),
487487
}
@@ -492,11 +492,11 @@ func packLabels(tfLabels []interface{}) []slo.Label {
492492
return labelSlice
493493
}
494494

495-
func packAlerting(tfAlerting map[string]interface{}) slo.Alerting {
496-
var tfAnnots []slo.Label
497-
var tfLabels []slo.Label
498-
var tfFastBurn slo.AlertingMetadata
499-
var tfSlowBurn slo.AlertingMetadata
495+
func packAlerting(tfAlerting map[string]interface{}) slo.SloV00Alerting {
496+
var tfAnnots []slo.SloV00Label
497+
var tfLabels []slo.SloV00Label
498+
var tfFastBurn slo.SloV00AlertingMetadata
499+
var tfSlowBurn slo.SloV00AlertingMetadata
500500

501501
annots, ok := tfAlerting["annotation"].([]interface{})
502502
if ok {
@@ -518,7 +518,7 @@ func packAlerting(tfAlerting map[string]interface{}) slo.Alerting {
518518
tfSlowBurn = packAlertMetadata(slowBurn)
519519
}
520520

521-
alerting := slo.Alerting{
521+
alerting := slo.SloV00Alerting{
522522
Annotations: tfAnnots,
523523
Labels: tfLabels,
524524
FastBurn: &tfFastBurn,
@@ -528,9 +528,9 @@ func packAlerting(tfAlerting map[string]interface{}) slo.Alerting {
528528
return alerting
529529
}
530530

531-
func packAlertMetadata(metadata []interface{}) slo.AlertingMetadata {
532-
var tflabels []slo.Label
533-
var tfannots []slo.Label
531+
func packAlertMetadata(metadata []interface{}) slo.SloV00AlertingMetadata {
532+
var tflabels []slo.SloV00Label
533+
var tfannots []slo.SloV00Label
534534

535535
if len(metadata) > 0 {
536536
meta, ok := metadata[0].(map[string]interface{})
@@ -547,15 +547,15 @@ func packAlertMetadata(metadata []interface{}) slo.AlertingMetadata {
547547
}
548548
}
549549

550-
apiMetadata := slo.AlertingMetadata{
550+
apiMetadata := slo.SloV00AlertingMetadata{
551551
Labels: tflabels,
552552
Annotations: tfannots,
553553
}
554554

555555
return apiMetadata
556556
}
557557

558-
func setTerraformState(d *schema.ResourceData, slo slo.Slo) {
558+
func setTerraformState(d *schema.ResourceData, slo slo.SloV00Slo) {
559559
d.Set("name", slo.Name)
560560
d.Set("description", slo.Description)
561561

internal/resources/slo/resource_slo_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestAccResourceSlo(t *testing.T) {
1919

2020
randomName := acctest.RandomWithPrefix("SLO Terraform Testing")
2121

22-
var slo slo.Slo
22+
var slo slo.SloV00Slo
2323
resource.ParallelTest(t, resource.TestCase{
2424
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2525
// Implicitly tests destroy
@@ -96,7 +96,7 @@ func TestAccResourceSlo(t *testing.T) {
9696
})
9797
}
9898

99-
func testAccSloCheckExists(rn string, slo *slo.Slo) resource.TestCheckFunc {
99+
func testAccSloCheckExists(rn string, slo *slo.SloV00Slo) resource.TestCheckFunc {
100100
return func(s *terraform.State) error {
101101
rs, ok := s.RootModule().Resources[rn]
102102
if !ok {
@@ -121,7 +121,7 @@ func testAccSloCheckExists(rn string, slo *slo.Slo) resource.TestCheckFunc {
121121
}
122122
}
123123

124-
func testAlertingExists(expectation bool, rn string, slo *slo.Slo) resource.TestCheckFunc {
124+
func testAlertingExists(expectation bool, rn string, slo *slo.SloV00Slo) resource.TestCheckFunc {
125125
return func(s *terraform.State) error {
126126
rs := s.RootModule().Resources[rn]
127127
client := testutils.Provider.Meta().(*common.Client).SLOClient
@@ -145,7 +145,7 @@ func testAlertingExists(expectation bool, rn string, slo *slo.Slo) resource.Test
145145
}
146146
}
147147

148-
func testAccSloCheckDestroy(slo *slo.Slo) resource.TestCheckFunc {
148+
func testAccSloCheckDestroy(slo *slo.SloV00Slo) resource.TestCheckFunc {
149149
return func(s *terraform.State) error {
150150
client := testutils.Provider.Meta().(*common.Client).SLOClient
151151
req := client.DefaultAPI.V1SloIdGet(context.Background(), slo.Uuid)

0 commit comments

Comments
 (0)