Skip to content

Commit

Permalink
Merge pull request #72 from K-Phoen/stackdriver-group-by
Browse files Browse the repository at this point in the history
Stackdriver group by
  • Loading branch information
K-Phoen authored Jun 17, 2020
2 parents 345af32 + 9c3e3ee commit 971b164
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions decoder/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type StackdriverTarget struct {
Legend string `yaml:",omitempty"`
Ref string `yaml:",omitempty"`
Hidden bool `yaml:",omitempty"`
GroupBy []string `yaml:",omitempty"`
}

type StackdriverFilters struct {
Expand Down Expand Up @@ -93,6 +94,10 @@ func (t StackdriverTarget) toOptions() ([]stackdriver.Option, error) {
opts = append(opts, stackdriver.Filter(filters...))
}

if len(t.GroupBy) != 0 {
opts = append(opts, stackdriver.GroupBys(t.GroupBy...))
}

if t.Aggregation != "" {
opt, err := t.aggregation()
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions decoder/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,12 @@ func TestStackdriverHiddenTarget(t *testing.T) {
req.NoError(err)
req.True(target.Builder.Hide)
}

func TestStackdriverGroupBy(t *testing.T) {
req := require.New(t)

target, err := StackdriverTarget{Type: "delta", GroupBy: []string{"field", "other"}}.toTarget()

req.NoError(err)
req.ElementsMatch(target.Builder.GroupBys, []string{"field", "other"})
}
7 changes: 7 additions & 0 deletions target/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ func Filter(filters ...FilterOption) Option {
}
}
}

// GroupBys defines a list of fields to group the query by.
func GroupBys(groupBys ...string) Option {
return func(stackdriver *Stackdriver) {
stackdriver.Builder.GroupBys = groupBys
}
}
8 changes: 8 additions & 0 deletions target/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,11 @@ func TestFiltersCanBeConfigured(t *testing.T) {
})
}
}

func TestTargetSupportsGroupBys(t *testing.T) {
req := require.New(t)

target := stackdriver.Delta("", stackdriver.GroupBys("field", "other"))

req.ElementsMatch(target.Builder.GroupBys, []string{"field", "other"})
}

0 comments on commit 971b164

Please sign in to comment.