Skip to content

Commit

Permalink
fix: Sink asset labels to Compass (#475)
Browse files Browse the repository at this point in the history
Labels were not being sent to Compass if no labels were specified in the
sink configuration for Compass.
  • Loading branch information
sudo-suhas authored Feb 24, 2023
1 parent a79fdde commit c1e6b27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
28 changes: 14 additions & 14 deletions plugins/sinks/compass/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,27 @@ func (s *Sink) buildOwners(asset *v1beta2.Asset) (owners []Owner) {
return
}

func (s *Sink) buildLabels(asset *v1beta2.Asset) (labels map[string]string, err error) {
if s.config.Labels == nil {
return
func (s *Sink) buildLabels(asset *v1beta2.Asset) (map[string]string, error) {
total := len(s.config.Labels) + len(asset.Labels)
if total == 0 {
return nil, nil
}

labels = asset.GetLabels()
if labels == nil {
labels = make(map[string]string)
labels := make(map[string]string, total)
for k, v := range asset.Labels {
labels[k] = v
}

for key, template := range s.config.Labels {
var value string
value, err = s.buildLabelValue(template, asset)
value, err := s.buildLabelValue(template, asset)
if err != nil {
err = errors.Wrapf(err, "could not find \"%s\"", template)
return
return nil, errors.Wrapf(err, "could not find %q", template)
}

labels[key] = value
}

return
return labels, nil
}

func (s *Sink) buildLabelValue(template string, asset *v1beta2.Asset) (value string, err error) {
Expand All @@ -271,12 +271,12 @@ func (s *Sink) getLabelValueFromProperties(field1 string, field2 string, asset *
attr := utils.GetAttributes(asset)
v, ok := attr[field2]
if !ok {
err = fmt.Errorf("could not find \"%s\" field on attributes", field2)
err = fmt.Errorf("could not find %q field on attributes", field2)
return
}
value, ok = v.(string)
if !ok {
err = fmt.Errorf("\"%s\" field is not a string", field2)
err = fmt.Errorf("%q field is not a string", field2)
return
}
return
Expand All @@ -289,7 +289,7 @@ func (s *Sink) getLabelValueFromProperties(field1 string, field2 string, asset *
var ok bool
value, ok = labels[field2]
if !ok {
err = fmt.Errorf("could not find \"%s\" from labels", field2)
err = fmt.Errorf("could not find %q from labels", field2)
return
}

Expand Down
13 changes: 10 additions & 3 deletions plugins/sinks/compass/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/anypb"

testUtils "github.com/odpf/meteor/test/utils"
"github.com/odpf/meteor/utils"

"github.com/odpf/meteor/models"
v1beta2 "github.com/odpf/meteor/models/odpf/assets/v1beta2"
"github.com/odpf/meteor/plugins"
"github.com/odpf/meteor/plugins/sinks/compass"
testUtils "github.com/odpf/meteor/test/utils"
"github.com/odpf/meteor/utils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -213,6 +212,10 @@ func TestSink(t *testing.T) {
},
},
}),
Labels: map[string]string{
"labelA": "valueLabelA",
"labelB": "valueLabelB",
},
},
config: map[string]interface{}{
"host": host,
Expand All @@ -236,6 +239,10 @@ func TestSink(t *testing.T) {
},
},
},
Labels: map[string]string{
"labelA": "valueLabelA",
"labelB": "valueLabelB",
},
},
},
},
Expand Down

0 comments on commit c1e6b27

Please sign in to comment.