-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting properties metadata for EventHubs target (closes #99)
- Loading branch information
1 parent
72e13ec
commit 11b67ab
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// PROPRIETARY AND CONFIDENTIAL | ||
// | ||
// Unauthorized copying of this file via any medium is strictly prohibited. | ||
// | ||
// Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved. | ||
|
||
package transform | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/snowplow-devops/stream-replicator/pkg/models" | ||
) | ||
|
||
// NewSpEnrichedAddMetadataFunction returns a TransformationFunction which adds metadata to a message from a field within a Snowplow enriched event | ||
func NewSpEnrichedAddMetadataFunction(key, field string) TransformationFunction { | ||
return func(message *models.Message, intermediateState interface{}) (*models.Message, *models.Message, *models.Message, interface{}) { | ||
// Evaluate intermediateState to parsedEvent | ||
parsedMessage, parseErr := IntermediateAsSpEnrichedParsed(intermediateState, message) | ||
if parseErr != nil { | ||
message.SetError(parseErr) | ||
return nil, nil, message, nil | ||
} | ||
|
||
value, err := parsedMessage.GetValue(field) | ||
if err != nil { | ||
message.SetError(err) | ||
return nil, nil, message, nil | ||
} | ||
if message.Metadata == nil { | ||
message.Metadata = map[string]interface{}{ | ||
key: fmt.Sprintf("%v", value), | ||
} | ||
} else { | ||
message.Metadata[key] = fmt.Sprintf("%v", value) | ||
} | ||
return message, nil, nil, parsedMessage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// PROPRIETARY AND CONFIDENTIAL | ||
// | ||
// Unauthorized copying of this file via any medium is strictly prohibited. | ||
// | ||
// Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved. | ||
|
||
package transform | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/snowplow-devops/stream-replicator/pkg/models" | ||
) | ||
|
||
func TestNewSpEnrichedAddMetadata(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
var messageGood = models.Message{ | ||
Data: snowplowTsv3, | ||
PartitionKey: "some-key", | ||
} | ||
|
||
var messageBad = models.Message{ | ||
Data: nonSnowplowString, | ||
PartitionKey: "some-key4", | ||
} | ||
|
||
aidAddMetadata := NewSpEnrichedAddMetadataFunction("test-key", "app_id") | ||
|
||
res, _, fail, intermediate := aidAddMetadata(&messageGood, nil) | ||
|
||
assert.Equal("test-data3", res.Metadata["test-key"]) | ||
assert.Equal(spTsv3Parsed, intermediate) | ||
assert.Nil(fail) | ||
|
||
res, _, fail, intermediate = aidAddMetadata(&messageBad, nil) | ||
|
||
assert.Nil(res) | ||
assert.Nil(intermediate) | ||
assert.NotNil(fail) | ||
assert.NotNil(fail.GetError()) | ||
if fail.GetError() != nil { | ||
assert.Equal("Cannot parse tsv event - wrong number of fields provided: 4", fail.GetError().Error()) | ||
} | ||
|
||
ctstampAddMetadata := NewSpEnrichedAddMetadataFunction("test-key", "collector_tstamp") | ||
|
||
tstampRes, _, fail, intermediate := ctstampAddMetadata(&messageGood, nil) | ||
|
||
assert.Equal("2019-05-10 14:40:29.576 +0000 UTC", tstampRes.Metadata["test-key"]) | ||
assert.Equal(spTsv3Parsed, intermediate) | ||
assert.Nil(fail) | ||
|
||
pgurlportAddMetadata := NewSpEnrichedAddMetadataFunction("test-key", "page_urlport") | ||
|
||
intRes, _, fail, intermediate := pgurlportAddMetadata(&messageGood, nil) | ||
|
||
assert.Equal("80", intRes.Metadata["test-key"]) | ||
assert.Equal(spTsv3Parsed, intermediate) | ||
assert.Nil(fail) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters