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

SLO: Implements SLO Datasource and SLO Resource #890

Closed
wants to merge 55 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
23ba3d3
slo: Support SLO Datasource Read Functionality
elainevuong Mar 29, 2023
b9e8d63
slo: Support SLO Resource Create Functionality
elainevuong Mar 31, 2023
64b90ce
slo: Adds a resourceSloRead method to the SLO Resource Create Functio…
elainevuong Apr 3, 2023
3f5a8fb
Modify README
elainevuong Apr 3, 2023
e2ceedc
slo: Support SLO Resource Delete Functionality
elainevuong Apr 3, 2023
1af04a0
slo: Support SLO Resource Update Functionality
elainevuong Apr 4, 2023
0453983
slo: Support SLO Resource Import Functionality
elainevuong Apr 4, 2023
f4d7f01
slo: Update Testing READMEs, implement SLO Datasource HG Functionality
elainevuong Apr 12, 2023
6b399bc
slo: Implement SLO Resource CREATE and READ HG Functionality and Test…
elainevuong Apr 12, 2023
abc322e
slo: Implement SLO Resource UPDATE HG Functionality and Testing READMEs
elainevuong Apr 12, 2023
639bd4b
slo: Implement SLO Resource DESTROY HG Functionality and Testing READMEs
elainevuong Apr 12, 2023
e3cae37
slo: Implement SLO Resource IMPORT HG Functionality and Update Testin…
elainevuong Apr 12, 2023
51ee8af
Modify Grafana Client for the ListSLOs functionality for the Datasour…
elainevuong Apr 18, 2023
ec907b3
Modify Grafana Client and Terraform Provider for the GetSLO and Creat…
elainevuong Apr 18, 2023
16e94a9
Modify Grafana Client and Terraform Provider for the DeleteSLO functi…
elainevuong Apr 18, 2023
924fee8
Modify Grafana Client and Terraform Provider for the UpdateSLO functi…
elainevuong Apr 18, 2023
98c6ec3
Testing - Checking Initial Resource Attributes and Attribute Sets
elainevuong Apr 18, 2023
1c4e53a
Updates READMEs for testing
elainevuong Apr 19, 2023
067d2b9
Updated to replace the specific branch on the Grafana API Golang Client
elainevuong Apr 19, 2023
aa6c7c9
Adding Testing Functions to check for Slo existence and Slo destroy
elainevuong Apr 20, 2023
10cd20c
Updated the Grafana API Wrapper Update Method on UpdateSlo
elainevuong Apr 20, 2023
8159de5
Modify UUID Naming in GAPI
elainevuong Apr 20, 2023
a059c87
Merge branch 'master' into elainevuong/slo
elainevuong Apr 20, 2023
3fa6c78
Update Linting Comments
elainevuong Apr 20, 2023
1ce6f8e
Merge branch 'elainevuong/slo' of https://github.com/grafana/terrafor…
elainevuong Apr 20, 2023
c556886
Tests Passing for SLO Resources
elainevuong Apr 24, 2023
7c4838e
Update Variable Naming and Branch Reference in go.mod
elainevuong Apr 24, 2023
0f45dec
Added Update Test for SLO Resources
elainevuong Apr 24, 2023
0266403
Adding Checks for Empty SLOs for Datasource ListSlos Read
elainevuong Apr 24, 2023
a7f7970
Adds checks for nil alertData, fastBurn/slowBurn and tests
elainevuong Apr 24, 2023
87852c4
Added Tests for Invalid Queries and Invalid Objectives
elainevuong Apr 24, 2023
d95d024
Updating Tests
elainevuong Apr 24, 2023
461da7f
Adding Error Messages and Datasource SLO Tests
elainevuong Apr 25, 2023
c42efe9
Modifies GAPI Branch Reference
elainevuong Apr 25, 2023
59b24ed
Updating Docs and Descriptions on Resources
elainevuong Apr 26, 2023
c1af1d3
Merge branch 'master' into elainevuong/slo
elainevuong Apr 26, 2023
b1603f8
Updating Docs and Description on SLO Datasource
elainevuong Apr 26, 2023
5f6d81b
Update Formatting
elainevuong Apr 26, 2023
91c0b75
Revert Drone Changes
elainevuong Apr 26, 2023
f79086f
Formatting
elainevuong Apr 26, 2023
995f953
Updates GAPI Branch
elainevuong Apr 27, 2023
fd06f45
Merge branch 'master' into elainevuong/slo
elainevuong Apr 27, 2023
d681701
Add Instructions for Testing SLO Resources
elainevuong Apr 27, 2023
1fbfb63
Merge branch 'elainevuong/slo' of https://github.com/grafana/terrafor…
elainevuong Apr 27, 2023
1e37f1e
Update the Schema for the Query to match the API Types
elainevuong May 1, 2023
88c72ee
Query Labels Packed
elainevuong May 1, 2023
27f3502
Update Error Handling for Query Types Not Yet Implemented
elainevuong May 1, 2023
f625f39
Updating Datasource and Resource Fields on HCL Schema
elainevuong May 1, 2023
dd7fcfe
Updating Testing Files
elainevuong May 1, 2023
555bbea
Regenerate Documentation
elainevuong May 1, 2023
47503a2
Terraform FMT and Modifying Tests
elainevuong May 1, 2023
e2a136c
Updated Docs and Tests
elainevuong May 1, 2023
5fe1b0e
Correct Test Query
elainevuong May 1, 2023
2af66cc
Updating Unpack Functionality for modified Query Type
elainevuong May 1, 2023
6623c58
Updating Resources
elainevuong May 1, 2023
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
30 changes: 19 additions & 11 deletions internal/resources/slo/resource_slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,7 @@ func packSloResource(d *schema.ResourceData) gapi.Slo {
tfname := d.Get("name").(string)
tfdescription := d.Get("description").(string)

// query := d.Get("query").(string)
// tfquery := packQuery(query)

query := d.Get("query").([]interface{}) // type assertion
query := d.Get("query").([]interface{})
queryElements := query[0].(map[string]interface{})
tfquery := packQuery(queryElements)

Expand Down Expand Up @@ -492,16 +489,16 @@ func packSloResource(d *schema.ResourceData) gapi.Slo {
func packQuery(tfquery map[string]interface{}) gapi.Query {
var query gapi.Query

querytype := tfquery["query_type"].(string)
// querythresholdstruct := tfquery["threshold"].([]interface{})
// querylabelsstruct := tfquery["group_by_labels"].([]interface{})
queryType := tfquery["query_type"].(string)
// queryThresholdStruct := tfquery["threshold"].([]interface{})
queryLabelsStruct := tfquery["group_by_labels"].([]interface{})

switch querytype {
switch queryType {
case "freeform":
freeformQuery := tfquery["freeform_query"].(string)
query = gapi.Query{
FreeformQuery: generateFreeformQuery(freeformQuery),
// GroupByLabels: generateQueryLabels(querylabelsstruct),
FreeformQuery: packFreeformQuery(freeformQuery),
GroupByLabels: packQueryLabels(queryLabelsStruct),
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think we could use GroupByLabels with the FreeFormQuery... wouldn't that imply that we'd be modifying the FreeFormQuery to add some additional aggregation / grouping?

Do you have an example where this is needed

}
return query

Expand Down Expand Up @@ -535,7 +532,18 @@ func packQuery(tfquery map[string]interface{}) gapi.Query {
}
}

func generateFreeformQuery(query string) gapi.FreeformQuery {
func packQueryLabels(tfquerylabels []interface{}) []string {
var retQueryLabels []string

for _, label := range tfquerylabels {
strLabel := label.(string)
retQueryLabels = append(retQueryLabels, strLabel)

}
return retQueryLabels
}

func packFreeformQuery(query string) gapi.FreeformQuery {
return gapi.FreeformQuery{
Query: query,
}
Expand Down