Skip to content

Commit

Permalink
Namespace router outputs (#158)
Browse files Browse the repository at this point in the history
* Namespace router outputs

* Update changelog
  • Loading branch information
camdencheek authored Oct 7, 2020
1 parent 188e8cb commit 1db5ac4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.12.4] - 2020-10-07
### Fixed
- Router outputs were not namespaced correctly

## [0.12.3] - 2020-10-07
### Fixed
- (De)serialization of JSON for plugin config structs
Expand Down
1 change: 1 addition & 0 deletions operator/builtin/input/k8sevent/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
Expand Down
6 changes: 3 additions & 3 deletions operator/builtin/transformer/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type RouterOperatorRouteConfig struct {
}

// Build will build a router operator from the supplied configuration
func (c RouterOperatorConfig) Build(context operator.BuildContext) (operator.Operator, error) {
basicOperator, err := c.BasicConfig.Build(context)
func (c RouterOperatorConfig) Build(bc operator.BuildContext) (operator.Operator, error) {
basicOperator, err := c.BasicConfig.Build(bc)
if err != nil {
return nil, err
}
Expand All @@ -58,7 +58,7 @@ func (c RouterOperatorConfig) Build(context operator.BuildContext) (operator.Ope
route := RouterOperatorRoute{
Labeler: labeler,
Expression: compiled,
OutputIDs: routeConfig.OutputIDs,
OutputIDs: routeConfig.OutputIDs.WithNamespace(bc),
}
routes = append(routes, &route)
}
Expand Down
4 changes: 2 additions & 2 deletions operator/builtin/transformer/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ func TestRouterOperator(t *testing.T) {
results := map[string]int{}
var labels map[string]string

mock1 := testutil.NewMockOperator("output1")
mock1 := testutil.NewMockOperator("$.output1")
mock1.On("Process", mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
results["output1"] = results["output1"] + 1
if entry, ok := args[1].(*entry.Entry); ok {
labels = entry.Labels
}
})
mock2 := testutil.NewMockOperator("output2")
mock2 := testutil.NewMockOperator("$.output2")
mock2.On("Process", mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
results["output2"] = results["output2"] + 1
if entry, ok := args[1].(*entry.Entry); ok {
Expand Down
14 changes: 9 additions & 5 deletions operator/helper/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ func (c WriterConfig) Build(bc operator.BuildContext) (WriterOperator, error) {
}

// Namespace all the output IDs
namespacedIDs := make([]string, 0, len(c.OutputIDs))
for _, id := range c.OutputIDs {
namespacedIDs = append(namespacedIDs, bc.PrependNamespace(id))
}

namespacedIDs := c.OutputIDs.WithNamespace(bc)
if len(namespacedIDs) == 0 {
namespacedIDs = bc.DefaultOutputIDs
}
Expand Down Expand Up @@ -108,6 +104,14 @@ func (w *WriterOperator) findOperator(operators []operator.Operator, operatorID
// OutputIDs is a collection of operator IDs used as outputs.
type OutputIDs []string

func (o OutputIDs) WithNamespace(bc operator.BuildContext) OutputIDs {
namespacedIDs := make([]string, 0, len(o))
for _, id := range o {
namespacedIDs = append(namespacedIDs, bc.PrependNamespace(id))
}
return namespacedIDs
}

// UnmarshalJSON will unmarshal a string or array of strings to OutputIDs.
func (o *OutputIDs) UnmarshalJSON(bytes []byte) error {
var value interface{}
Expand Down

0 comments on commit 1db5ac4

Please sign in to comment.