-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for sharding based on metric name (#3170)
- Loading branch information
1 parent
914a813
commit 77c6089
Showing
3 changed files
with
183 additions
and
29 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package kinesis | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/influxdata/telegraf/testutil" | ||
uuid "github.com/satori/go.uuid" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPartitionKey(t *testing.T) { | ||
|
||
assert := assert.New(t) | ||
testPoint := testutil.TestMetric(1) | ||
|
||
k := KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "static", | ||
Key: "-", | ||
}, | ||
} | ||
assert.Equal("-", k.getPartitionKey(testPoint), "PartitionKey should be '-'") | ||
|
||
k = KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "tag", | ||
Key: "tag1", | ||
}, | ||
} | ||
assert.Equal(testPoint.Tags()["tag1"], k.getPartitionKey(testPoint), "PartitionKey should be value of 'tag1'") | ||
|
||
k = KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "tag", | ||
Key: "doesnotexist", | ||
}, | ||
} | ||
assert.Equal("", k.getPartitionKey(testPoint), "PartitionKey should be value of ''") | ||
|
||
k = KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "not supported", | ||
}, | ||
} | ||
assert.Equal("", k.getPartitionKey(testPoint), "PartitionKey should be value of ''") | ||
|
||
k = KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "measurement", | ||
}, | ||
} | ||
assert.Equal(testPoint.Name(), k.getPartitionKey(testPoint), "PartitionKey should be value of measurement name") | ||
|
||
k = KinesisOutput{ | ||
Partition: &Partition{ | ||
Method: "random", | ||
}, | ||
} | ||
partitionKey := k.getPartitionKey(testPoint) | ||
u, err := uuid.FromString(partitionKey) | ||
assert.Nil(err, "Issue parsing UUID") | ||
assert.Equal(uint(4), u.Version(), "PartitionKey should be UUIDv4") | ||
|
||
k = KinesisOutput{ | ||
PartitionKey: "-", | ||
} | ||
assert.Equal("-", k.getPartitionKey(testPoint), "PartitionKey should be '-'") | ||
|
||
k = KinesisOutput{ | ||
RandomPartitionKey: true, | ||
} | ||
partitionKey = k.getPartitionKey(testPoint) | ||
u, err = uuid.FromString(partitionKey) | ||
assert.Nil(err, "Issue parsing UUID") | ||
assert.Equal(uint(4), u.Version(), "PartitionKey should be UUIDv4") | ||
|
||
} |