Use github.com/gofrs/uuid 2.1.0 (#6636)

This commit is contained in:
Daniel Nelson 2019-11-07 17:39:19 -08:00 committed by GitHub
parent 6014a26467
commit 6cbaf890d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 19 deletions

16
Gopkg.lock generated
View File

@ -505,6 +505,14 @@
revision = "5ccd90ef52e1e632236f7326478d4faa74f99438" revision = "5ccd90ef52e1e632236f7326478d4faa74f99438"
version = "v0.2.3" version = "v0.2.3"
[[projects]]
digest = "1:181fe10dcb708edd7c68c5781928b6657612771f81dd1773287386b6982c94e2"
name = "github.com/gofrs/uuid"
packages = ["."]
pruneopts = ""
revision = "3a54a6416087bae7aa0ac32dd79fe1bf87bc99e4"
version = "v2.1.0"
[[projects]] [[projects]]
digest = "1:6e73003ecd35f4487a5e88270d3ca0a81bc80dc88053ac7e4dcfec5fba30d918" digest = "1:6e73003ecd35f4487a5e88270d3ca0a81bc80dc88053ac7e4dcfec5fba30d918"
name = "github.com/gogo/protobuf" name = "github.com/gogo/protobuf"
@ -715,7 +723,7 @@
revision = "7c63b0a71ef8300adc255344d275e10e5c3a71ec" revision = "7c63b0a71ef8300adc255344d275e10e5c3a71ec"
[[projects]] [[projects]]
digest = "1:a7998e19ebb78fdd341cdaf3825fded9030ae27af9c70d298c05d88744e16a0b" digest = "1:e248df365cb87001738e8c9368a6a27c504328047b196d89687c1ca918279a82"
name = "github.com/jackc/pgx" name = "github.com/jackc/pgx"
packages = [ packages = [
".", ".",
@ -727,8 +735,8 @@
"stdlib", "stdlib",
] ]
pruneopts = "" pruneopts = ""
revision = "8faa4453fc7051d1076053f8854077753ab912f2" revision = "c73e7d75061bb42b0282945710f344cfe1113d10"
version = "v3.4.0" version = "v3.6.0"
[[projects]] [[projects]]
digest = "1:d45477e90c25c8c6d7d4237281167aa56079382fc042db4b44a8328071649bfa" digest = "1:d45477e90c25c8c6d7d4237281167aa56079382fc042db4b44a8328071649bfa"
@ -1731,6 +1739,7 @@
"github.com/go-redis/redis", "github.com/go-redis/redis",
"github.com/go-sql-driver/mysql", "github.com/go-sql-driver/mysql",
"github.com/gobwas/glob", "github.com/gobwas/glob",
"github.com/gofrs/uuid",
"github.com/golang/protobuf/proto", "github.com/golang/protobuf/proto",
"github.com/golang/protobuf/ptypes/duration", "github.com/golang/protobuf/ptypes/duration",
"github.com/golang/protobuf/ptypes/empty", "github.com/golang/protobuf/ptypes/empty",
@ -1772,7 +1781,6 @@
"github.com/prometheus/client_golang/prometheus/promhttp", "github.com/prometheus/client_golang/prometheus/promhttp",
"github.com/prometheus/client_model/go", "github.com/prometheus/client_model/go",
"github.com/prometheus/common/expfmt", "github.com/prometheus/common/expfmt",
"github.com/satori/go.uuid",
"github.com/shirou/gopsutil/cpu", "github.com/shirou/gopsutil/cpu",
"github.com/shirou/gopsutil/disk", "github.com/shirou/gopsutil/disk",
"github.com/shirou/gopsutil/host", "github.com/shirou/gopsutil/host",

View File

@ -139,8 +139,8 @@
branch = "master" branch = "master"
[[constraint]] [[constraint]]
name = "github.com/satori/go.uuid" name = "github.com/gofrs/uuid"
version = "1.2.0" version = "2.0.0"
[[constraint]] [[constraint]]
name = "github.com/shirou/gopsutil" name = "github.com/shirou/gopsutil"

View File

@ -41,6 +41,7 @@ following works:
- github.com/go-redis/redis [BSD 2-Clause "Simplified" License](https://github.com/go-redis/redis/blob/master/LICENSE) - github.com/go-redis/redis [BSD 2-Clause "Simplified" License](https://github.com/go-redis/redis/blob/master/LICENSE)
- github.com/go-sql-driver/mysql [Mozilla Public License 2.0](https://github.com/go-sql-driver/mysql/blob/master/LICENSE) - github.com/go-sql-driver/mysql [Mozilla Public License 2.0](https://github.com/go-sql-driver/mysql/blob/master/LICENSE)
- github.com/gobwas/glob [MIT License](https://github.com/gobwas/glob/blob/master/LICENSE) - github.com/gobwas/glob [MIT License](https://github.com/gobwas/glob/blob/master/LICENSE)
- github.com/gofrs/uuid [MIT License](https://github.com/gofrs/uuid/blob/master/LICENSE)
- github.com/gogo/protobuf [BSD 3-Clause Clear License](https://github.com/gogo/protobuf/blob/master/LICENSE) - github.com/gogo/protobuf [BSD 3-Clause Clear License](https://github.com/gogo/protobuf/blob/master/LICENSE)
- github.com/golang/mock [Apache License 2.0](https://github.com/golang/mock/blob/master/LICENSE) - github.com/golang/mock [Apache License 2.0](https://github.com/golang/mock/blob/master/LICENSE)
- github.com/golang/protobuf [BSD 3-Clause "New" or "Revised" License](https://github.com/golang/protobuf/blob/master/LICENSE) - github.com/golang/protobuf [BSD 3-Clause "New" or "Revised" License](https://github.com/golang/protobuf/blob/master/LICENSE)
@ -99,7 +100,6 @@ following works:
- github.com/prometheus/procfs [Apache License 2.0](https://github.com/prometheus/procfs/blob/master/LICENSE) - github.com/prometheus/procfs [Apache License 2.0](https://github.com/prometheus/procfs/blob/master/LICENSE)
- github.com/rcrowley/go-metrics [MIT License](https://github.com/rcrowley/go-metrics/blob/master/LICENSE) - github.com/rcrowley/go-metrics [MIT License](https://github.com/rcrowley/go-metrics/blob/master/LICENSE)
- github.com/samuel/go-zookeeper [BSD 3-Clause Clear License](https://github.com/samuel/go-zookeeper/blob/master/LICENSE) - github.com/samuel/go-zookeeper [BSD 3-Clause Clear License](https://github.com/samuel/go-zookeeper/blob/master/LICENSE)
- github.com/satori/go.uuid [MIT License](https://github.com/satori/go.uuid/blob/master/LICENSE)
- github.com/shirou/gopsutil [BSD 3-Clause Clear License](https://github.com/shirou/gopsutil/blob/master/LICENSE) - github.com/shirou/gopsutil [BSD 3-Clause Clear License](https://github.com/shirou/gopsutil/blob/master/LICENSE)
- github.com/shirou/w32 [BSD 3-Clause Clear License](https://github.com/shirou/w32/blob/master/LICENSE) - github.com/shirou/w32 [BSD 3-Clause Clear License](https://github.com/shirou/w32/blob/master/LICENSE)
- github.com/Shopify/sarama [MIT License](https://github.com/Shopify/sarama/blob/master/LICENSE) - github.com/Shopify/sarama [MIT License](https://github.com/Shopify/sarama/blob/master/LICENSE)

View File

@ -7,11 +7,11 @@ import (
"strings" "strings"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"github.com/gofrs/uuid"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
tlsint "github.com/influxdata/telegraf/internal/tls" tlsint "github.com/influxdata/telegraf/internal/tls"
"github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/outputs"
"github.com/influxdata/telegraf/plugins/serializers" "github.com/influxdata/telegraf/plugins/serializers"
uuid "github.com/satori/go.uuid"
) )
var ValidTopicSuffixMethods = []string{ var ValidTopicSuffixMethods = []string{
@ -292,20 +292,23 @@ func (k *Kafka) Description() string {
return "Configuration for the Kafka server to send metrics to" return "Configuration for the Kafka server to send metrics to"
} }
func (k *Kafka) routingKey(metric telegraf.Metric) string { func (k *Kafka) routingKey(metric telegraf.Metric) (string, error) {
if k.RoutingTag != "" { if k.RoutingTag != "" {
key, ok := metric.GetTag(k.RoutingTag) key, ok := metric.GetTag(k.RoutingTag)
if ok { if ok {
return key return key, nil
} }
} }
if k.RoutingKey == "random" { if k.RoutingKey == "random" {
u := uuid.NewV4() u, err := uuid.NewV4()
return u.String() if err != nil {
return "", err
}
return u.String(), nil
} }
return k.RoutingKey return k.RoutingKey, nil
} }
func (k *Kafka) Write(metrics []telegraf.Metric) error { func (k *Kafka) Write(metrics []telegraf.Metric) error {
@ -321,7 +324,12 @@ func (k *Kafka) Write(metrics []telegraf.Metric) error {
Topic: k.GetTopicName(metric), Topic: k.GetTopicName(metric),
Value: sarama.ByteEncoder(buf), Value: sarama.ByteEncoder(buf),
} }
key := k.routingKey(metric)
key, err := k.routingKey(metric)
if err != nil {
return fmt.Errorf("could not generate routing key: %v", err)
}
if key != "" { if key != "" {
m.Key = sarama.StringEncoder(key) m.Key = sarama.StringEncoder(key)
} }

View File

@ -150,7 +150,8 @@ func TestRoutingKey(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
key := tt.kafka.routingKey(tt.metric) key, err := tt.kafka.routingKey(tt.metric)
require.NoError(t, err)
tt.check(t, key) tt.check(t, key)
}) })
} }

View File

@ -6,11 +6,11 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kinesis" "github.com/aws/aws-sdk-go/service/kinesis"
"github.com/gofrs/uuid"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
internalaws "github.com/influxdata/telegraf/internal/config/aws" internalaws "github.com/influxdata/telegraf/internal/config/aws"
"github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/outputs"
"github.com/influxdata/telegraf/plugins/serializers" "github.com/influxdata/telegraf/plugins/serializers"
"github.com/satori/go.uuid"
) )
type ( type (
@ -183,7 +183,10 @@ func (k *KinesisOutput) getPartitionKey(metric telegraf.Metric) string {
case "static": case "static":
return k.Partition.Key return k.Partition.Key
case "random": case "random":
u := uuid.NewV4() u, err := uuid.NewV4()
if err != nil {
return k.Partition.Default
}
return u.String() return u.String()
case "measurement": case "measurement":
return metric.Name() return metric.Name()
@ -200,7 +203,10 @@ func (k *KinesisOutput) getPartitionKey(metric telegraf.Metric) string {
} }
} }
if k.RandomPartitionKey { if k.RandomPartitionKey {
u := uuid.NewV4() u, err := uuid.NewV4()
if err != nil {
return k.Partition.Default
}
return u.String() return u.String()
} }
return k.PartitionKey return k.PartitionKey

View File

@ -3,8 +3,8 @@ package kinesis
import ( import (
"testing" "testing"
"github.com/gofrs/uuid"
"github.com/influxdata/telegraf/testutil" "github.com/influxdata/telegraf/testutil"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )