Skip to content

Commit

Permalink
LS-30243: Exclude heatmap display type from updating default latency_… (
Browse files Browse the repository at this point in the history
#88)

* LS-30243: Exclude heatmap display type from updating default latency_percentiles

* LS-30243: Bump version to 1.61.1
Update example references to version
Update comment for clarity

* LS-30243: Add tests
Correct NPE panic

* LS-30243: Reject partial lists for heatmap requests
Address nits

* LS-30243: Optimize sequence
  • Loading branch information
Dolphinsgrin authored Jun 14, 2022
1 parent 4be6ee7 commit c039330
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.61.0
1.61.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {
required_providers {
lightstep = {
source = "lightstep/lightstep"
version = "1.60.2"
version = "1.61.1"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ terraform {
required_providers {
lightstep = {
source = "lightstep/lightstep"
version = "~> 1.60.7"
version = "~> 1.61.1"
}
}
required_version = "~> 1.1.0"
Expand Down
20 changes: 11 additions & 9 deletions lightstep/resource_metric_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,22 @@ func buildSpansGroupByKeys(keysIn []interface{}) []string {
return keys
}

func buildLatencyPercentiles(lats []interface{}) []float64 {
var latencies []float64

// default
func buildLatencyPercentiles(lats []interface{}, display string) []float64 {
if display == "heatmap" {
return []float64{}
}
// default (heatmap queries don't compute percentiles)
if len(lats) == 0 {
return []float64{50, 95, 99, 99.9}
}

latencies := make([]float64, 0, len(lats))
for _, l := range lats {
latencies = append(latencies, l.(float64))
}
return latencies
}

func buildSpansQuery(spansQuery interface{}) client.SpansQuery {
func buildSpansQuery(spansQuery interface{}, display string) client.SpansQuery {
var sq client.SpansQuery
if spansQuery == nil || len(spansQuery.([]interface{})) == 0 {
return sq
Expand All @@ -514,7 +515,7 @@ func buildSpansQuery(spansQuery interface{}) client.SpansQuery {
sq.Operator = s["operator"].(string)

if sq.Operator == "latency" {
sq.LatencyPercentiles = buildLatencyPercentiles(s["latency_percentiles"].([]interface{}))
sq.LatencyPercentiles = buildLatencyPercentiles(s["latency_percentiles"].([]interface{}), display)
}
if groupByKeys, ok := s["group_by_keys"].([]interface{}); ok && len(groupByKeys) > 0 {
sq.GroupByKeys = buildSpansGroupByKeys(s["group_by_keys"].([]interface{}))
Expand Down Expand Up @@ -554,12 +555,13 @@ func buildQueries(queriesIn []interface{}, includeSpansQuery bool) ([]client.Met
if err != nil {
return nil, err
}
display := query["display"].(string)
newQuery := client.MetricQueryWithAttributes{
Name: query["query_name"].(string),
Type: "spans_single",
Hidden: query["hidden"].(bool),
Display: query["display"].(string),
SpansQuery: buildSpansQuery(spansQuery),
Display: display,
SpansQuery: buildSpansQuery(spansQuery, display),
}
newQueries = append(newQueries, newQuery)
continue
Expand Down
73 changes: 71 additions & 2 deletions lightstep/resource_metric_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lightstep
import (
"context"
"fmt"
"reflect"
"regexp"
"testing"

Expand Down Expand Up @@ -363,8 +364,8 @@ func testAccCheckMetricConditionExists(resourceName string, condition *client.Me
return fmt.Errorf("ID is not set")
}

client := testAccProvider.Meta().(*client.Client)
cond, err := client.GetMetricCondition(context.Background(), test_project, tfCondition.Primary.ID)
providerClient := testAccProvider.Meta().(*client.Client)
cond, err := providerClient.GetMetricCondition(context.Background(), test_project, tfCondition.Primary.ID)
if err != nil {
return err
}
Expand Down Expand Up @@ -784,3 +785,71 @@ func TestValidateGroupBy(t *testing.T) {
}
}
}

func Test_buildLatencyPercentiles(t *testing.T) {
type args struct {
lats []interface{}
display string
}
tests := []struct {
name string
args args
want []float64
}{
{
name: "Full List Provided; Expect Full List",
args: args{
lats: []interface{}{float64(50), float64(95), float64(99), 99.9},
display: "line",
},
want: []float64{50, 95, 99, 99.9},
},
{
name: "Partial List Provided; Expect Partial List",
args: args{
lats: []interface{}{float64(50), float64(95)},
display: "line",
},
want: []float64{50, 95},
},
{
name: "No List Provided; Expect Full List",
args: args{
lats: []interface{}{},
display: "line",
},
want: []float64{50, 95, 99, 99.9},
},
{
name: "Heatmap: Full List Provided; Expect No List",
args: args{
lats: []interface{}{float64(50), float64(95), float64(99), 99.9},
display: "heatmap",
},
want: []float64{},
},
{
name: "Heatmap: Partial List Provided; Expect No List",
args: args{
lats: []interface{}{float64(50), float64(95)},
display: "heatmap",
},
want: []float64{},
},
{
name: "Heatmap: No List Provided; Expect No List",
args: args{
lats: []interface{}{},
display: "heatmap",
},
want: []float64{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := buildLatencyPercentiles(tt.args.lats, tt.args.display); !reflect.DeepEqual(got, tt.want) {
t.Errorf("buildLatencyPercentiles() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit c039330

Please sign in to comment.