Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slo): Update Terraform provider to include option to set min Failures #1660

Merged
merged 22 commits into from
Jul 7, 2024

Conversation

Leo-DiCara
Copy link
Contributor

@Leo-DiCara Leo-DiCara commented Jun 26, 2024

We recently have merged new functionality which has updated the SLO CRD. This update brings the terraform provider in line with the new capabilities.

-Doc Update
-New Test for advanced Options

Part of https://github.com/grafana/slo/issues/2070

@Leo-DiCara Leo-DiCara requested review from a team as code owners June 26, 2024 21:03
Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

Copy link
Contributor

@ellisda ellisda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good (though I'm not a good reviewer here). a couple of style questions to align with existing code

internal/resources/slo/data_source_slo.go Outdated Show resolved Hide resolved
internal/resources/slo/resource_slo.go Show resolved Hide resolved
Comment on lines 573 to 574
if failures := tfAlerting["advanced_options"]; failures != nil {
lf := failures.([]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if failures := tfAlerting["advanced_options"]; failures != nil {
lf := failures.([]interface{})
if advancedOptions, ok := tfAlerting["advanced_options"].([]interface{}); ok {

it seems that the blocks above this all follow the same pattern with type assertion on the "if" line. Can we not follow that pattern here? Note: the suggestion is using []interface{} not []int (type depends on whether you take suggestion above)

if failures := tfAlerting["advanced_options"]; failures != nil {
lf := failures.([]interface{})
if len(lf) > 0 {
lf2 := lf[0].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this will panic if the runtime value of lf[0] fails the type assertion.

Don't you need to use the lf2, ok := lf[0].(map[string]interface{}) version and check ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting point. Yeah I should fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually do this exact same thing for the alerting struct as a whole, the terraform can panic if it doesn't match the expected format. Think I should switch that too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if it's easy. If we can handle more gracefully than panic, we should.

where else are we doing it though? The only uncheecked type assertions I see in this function are on line 574 and 576

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually misunderstood. the alerting struct handles it all gracefully. I've replicated it now here.

Copy link
Contributor

@elainevuong elainevuong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job - LGTM!

@Leo-DiCara Leo-DiCara requested a review from julienduchesne July 2, 2024 20:14
Copy link
Member

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -150,6 +160,30 @@ func testAlertingExists(expectation bool, rn string, slo *slo.SloV00Slo) resourc
}
}

func testAdvancedOptionsExists(expectation bool, rn string, slo *slo.SloV00Slo) resource.TestCheckFunc {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I guess this works but this could be tested without an additional test function. An import test would've tested that things are written correctly too (it wipes the state and checks that all attributes would be set the same on an import)

@julienduchesne julienduchesne merged commit 7e0ceeb into main Jul 7, 2024
27 checks passed
@julienduchesne julienduchesne deleted the ld/slo_terraform_minFailures branch July 7, 2024 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants