Skip to content

Commit bfd8cdf

Browse files
authored
Merge pull request #2446 from lebauce/sator-uuid
Move to github.com/satori/go.uuid for uuid generation
2 parents 0faf654 + 1a50ff8 commit bfd8cdf

File tree

12 files changed

+29
-45
lines changed

12 files changed

+29
-45
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ require (
4040
github.com/newtools/ebpf v0.0.0-20190820102627-8b7eaed02eb9
4141
github.com/nimbess/nimbess-agent v0.0.0-20190919205041-4e6f317ac4fd
4242
github.com/nlewo/contrail-introspect-cli v0.0.0-20181003135217-0407b60f2edd
43-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
4443
github.com/olivere/elastic/v7 v7.0.32
4544
github.com/ovn-org/libovsdb v0.4.0
4645
github.com/pierrec/xxHash v0.1.5
@@ -49,6 +48,7 @@ require (
4948
github.com/robertkrimen/otto v0.3.0
5049
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8
5150
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3
51+
github.com/satori/go.uuid v1.2.0
5252
github.com/shirou/gopsutil v2.18.12+incompatible
5353
github.com/sirupsen/logrus v1.9.3
5454
github.com/skydive-project/dede v0.0.0-20200217172954-b1b74a5bb856

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1655,8 +1655,6 @@ github.com/nlewo/contrail-introspect-cli v0.0.0-20181003135217-0407b60f2edd/go.m
16551655
github.com/nplanel/ebpf v0.0.0-20190918123742-99947faabce5 h1:4hj49CpBEvoXH4XDmOskKfPnS/0XD7ypIjMD0fETF1Q=
16561656
github.com/nplanel/ebpf v0.0.0-20190918123742-99947faabce5/go.mod h1:H74E4gvXfcsOzgaoPSOuQVoKsWQrg2Xbx6+WybLKvyA=
16571657
github.com/nsqio/go-nsq v1.0.7/go.mod h1:XP5zaUs3pqf+Q71EqUJs3HYfBIqfK6G83WQMdNN+Ito=
1658-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
1659-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
16601658
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
16611659
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
16621660
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
@@ -1835,6 +1833,8 @@ github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8 h1:2c1EFnZHIPCW8q
18351833
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
18361834
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3 h1:Y6aFMpbXYw8XtaVS/dT2VSjElvv5yr5eaLPRtErn/HE=
18371835
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3/go.mod h1:BOnNgK32KZwrgJ9kI/YH4E/B/De0i+dguUxD/SXabRQ=
1836+
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
1837+
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
18381838
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
18391839
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
18401840
github.com/segmentio/kafka-go v0.2.1/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=

graffiti/api/rest/kv.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"sync/atomic"
2727
"time"
2828

29-
uuid "github.com/nu7hatch/gouuid"
29+
uuid "github.com/satori/go.uuid"
3030
etcd "go.etcd.io/etcd/client/v2"
3131

3232
etcdclient "github.com/skydive-project/skydive/graffiti/etcd/client"
@@ -105,7 +105,7 @@ func (h *BasicAPIHandler) Get(id string) (Resource, bool) {
105105

106106
// Create a new resource in Etcd
107107
func (h *BasicAPIHandler) Create(resource Resource, createOpts *CreateOptions) error {
108-
id, _ := uuid.NewV4()
108+
id := uuid.NewV4()
109109
resource.SetID(id.String())
110110

111111
data, err := json.Marshal(&resource)

graffiti/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ require (
2424
github.com/mitchellh/hashstructure v1.1.0
2525
github.com/mitchellh/mapstructure v1.5.0
2626
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
27-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
2827
github.com/olivere/elastic/v7 v7.0.32
2928
github.com/peterh/liner v1.2.2
3029
github.com/pierrec/xxHash v0.1.5
3130
github.com/pkg/errors v0.9.1
3231
github.com/pmylund/go-cache v2.1.0+incompatible
3332
github.com/robertkrimen/otto v0.3.0
3433
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3
34+
github.com/satori/go.uuid v1.2.0
3535
github.com/skydive-project/go-debouncer v1.0.0
3636
github.com/spf13/cast v1.6.0
3737
github.com/spf13/cobra v1.8.0

graffiti/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
144144
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
145145
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
146146
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
147-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
148-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
149147
github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E=
150148
github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k=
151149
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
@@ -180,6 +178,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
180178
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
181179
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3 h1:Y6aFMpbXYw8XtaVS/dT2VSjElvv5yr5eaLPRtErn/HE=
182180
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3/go.mod h1:BOnNgK32KZwrgJ9kI/YH4E/B/De0i+dguUxD/SXabRQ=
181+
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
182+
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
183183
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
184184
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
185185
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=

graffiti/graph/graph.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"reflect"
2424
"strings"
2525

26-
uuid "github.com/nu7hatch/gouuid"
2726
"github.com/safchain/insanelock"
27+
uuid "github.com/satori/go.uuid"
2828

2929
"github.com/skydive-project/skydive/graffiti/filters"
3030
"github.com/skydive-project/skydive/graffiti/getter"
@@ -347,12 +347,10 @@ func NewEventHandler(maxEvents int) *EventHandler {
347347
// GenID helper generate a node Identifier
348348
func GenID(s ...string) Identifier {
349349
if len(s) > 0 {
350-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(strings.Join(s, "/")))
351-
return Identifier(u.String())
350+
return Identifier(uuid.NewV5(uuid.NamespaceOID, strings.Join(s, "/")).String())
352351
}
353352

354-
u, _ := uuid.NewV4()
355-
return Identifier(u.String())
353+
return Identifier(uuid.NewV4().String())
356354
}
357355

358356
func (e *graphElement) GetFieldBool(field string) (_ bool, err error) {
@@ -1299,8 +1297,7 @@ func (g *Graph) CreateEdge(i Identifier, p *Node, c *Node, m Metadata, t Time, h
12991297
}
13001298

13011299
if i == "" {
1302-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(p.ID+c.ID))
1303-
i = Identifier(u.String())
1300+
i = Identifier(uuid.NewV5(uuid.NamespaceOID, string(p.ID+c.ID)).String())
13041301
}
13051302

13061303
return CreateEdge(i, p, c, m, t, hostname, g.origin)

graffiti/storage/elasticsearch/client.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import (
3232

3333
"github.com/hashicorp/go-multierror"
3434
version "github.com/hashicorp/go-version"
35-
uuid "github.com/nu7hatch/gouuid"
3635
elastic "github.com/olivere/elastic/v7"
3736
"github.com/pkg/errors"
37+
uuid "github.com/satori/go.uuid"
3838

3939
etcd "github.com/skydive-project/skydive/graffiti/etcd/client"
4040
"github.com/skydive-project/skydive/graffiti/filters"
@@ -645,10 +645,7 @@ func NewClient(indices []Index, cfg Config, electionService etcd.MasterElectionS
645645
}
646646
sort.Strings(names)
647647

648-
u5, err := uuid.NewV5(uuid.NamespaceOID, []byte(strings.Join(names, ",")))
649-
if err != nil {
650-
return nil, err
651-
}
648+
u5 := uuid.NewV5(uuid.NamespaceOID, strings.Join(names, ","))
652649

653650
client := &Client{
654651
Config: cfg,

graffiti/websocket/message.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
auth "github.com/abbot/go-http-auth"
2828
proto "github.com/gogo/protobuf/proto"
2929
"github.com/gorilla/websocket"
30-
uuid "github.com/nu7hatch/gouuid"
3130
"github.com/safchain/insanelock"
31+
uuid "github.com/satori/go.uuid"
3232

3333
"github.com/skydive-project/skydive/graffiti/logging"
3434
)
@@ -198,8 +198,7 @@ func NewStructMessage(ns string, tp string, v interface{}, uuids ...string) *Str
198198
if len(uuids) != 0 {
199199
u = uuids[0]
200200
} else {
201-
v4, _ := uuid.NewV4()
202-
u = v4.String()
201+
u = uuid.NewV4().String()
203202
}
204203

205204
msg := &StructMessage{

topology/probes/fabric/fabric.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"fmt"
2323
"strings"
2424

25-
uuid "github.com/nu7hatch/gouuid"
25+
uuid "github.com/satori/go.uuid"
2626

2727
"github.com/skydive-project/skydive/config"
2828
"github.com/skydive-project/skydive/graffiti/graph"
@@ -123,7 +123,7 @@ func (fb *Probe) getOrCreateFabricNodeFromDef(nodeDef string) (*graph.Node, erro
123123
metadata["Type"] = "device"
124124
}
125125

126-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte("fabric"+nodeName))
126+
u := uuid.NewV5(uuid.NamespaceOID, "fabric"+nodeName)
127127
id := graph.Identifier(u.String())
128128

129129
if node := fb.Graph.GetNode(id); node != nil {

topology/probes/ovsdb/ofctl.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"time"
3636

3737
"github.com/avast/retry-go"
38-
uuid "github.com/nu7hatch/gouuid"
38+
uuid "github.com/satori/go.uuid"
3939

4040
"github.com/skydive-project/skydive/config"
4141
"github.com/skydive-project/skydive/graffiti/graph"
@@ -194,29 +194,20 @@ func (probe *OfctlProbe) parseEvent(line string) (Event, error) {
194194
// prefix is a unique string per bridge using bridge and host names.
195195
func fillRawUUID(rule *RawRule, prefix string) {
196196
id := prefix + rule.Filter + "-" + strconv.Itoa(rule.Table)
197-
u, err := uuid.NewV5(uuid.NamespaceOID, []byte(id))
198-
if err == nil {
199-
rule.UUID = u.String()
200-
}
197+
rule.UUID = uuid.NewV5(uuid.NamespaceOID, id).String()
201198
}
202199

203200
// fillRawUUID Generates a unique UUID for the rule
204201
// prefix is a unique string per bridge using bridge and host names.
205202
func fillUUID(rule *jsonof.JSONRule, prefix string) {
206203
id := prefix + rule.RawFilter + "-" + strconv.Itoa(rule.Table) + "-" + strconv.Itoa(rule.Priority)
207-
u, err := uuid.NewV5(uuid.NamespaceOID, []byte(id))
208-
if err == nil {
209-
rule.UUID = u.String()
210-
}
204+
rule.UUID = uuid.NewV5(uuid.NamespaceOID, id).String()
211205
}
212206

213207
// Generate a unique UUID for the group
214208
func fillGroupUUID(group *jsonof.JSONGroup, prefix string) {
215209
id := prefix + "-" + strconv.Itoa(int(group.GroupID))
216-
u, err := uuid.NewV5(uuid.NamespaceOID, []byte(id))
217-
if err == nil {
218-
group.UUID = u.String()
219-
}
210+
group.UUID = uuid.NewV5(uuid.NamespaceOID, id).String()
220211
}
221212

222213
func makeFilter(rule *RawRule) string {

topology/tid.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package topology
1919

2020
import (
21-
uuid "github.com/nu7hatch/gouuid"
21+
uuid "github.com/satori/go.uuid"
2222
"github.com/skydive-project/skydive/graffiti/graph"
2323
"github.com/skydive-project/skydive/graffiti/logging"
2424
)
@@ -63,7 +63,7 @@ func (t *TIDMapper) setTID(parent, child *graph.Node) {
6363

6464
if tid, _ := parent.GetFieldString("TID"); tid != "" {
6565
tid = tid + key + tp
66-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
66+
u := uuid.NewV5(uuid.NamespaceOID, tid)
6767
t.Graph.AddMetadata(child, "TID", u.String())
6868
}
6969
}
@@ -77,22 +77,22 @@ func (t *TIDMapper) onNodeEvent(n *graph.Node) {
7777
switch tp {
7878
case "host":
7979
if name, err := n.GetFieldString("Name"); err == nil {
80-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(name))
80+
u := uuid.NewV5(uuid.NamespaceOID, name)
8181
t.hostID = graph.Identifier(u.String())
8282
t.Graph.AddMetadata(n, "TID", u.String())
8383
}
8484
case "netns":
8585
if path, _ := n.GetFieldString("Path"); path != "" {
8686
tid := string(t.hostID) + path + tp
87-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
87+
u := uuid.NewV5(uuid.NamespaceOID, tid)
8888
t.Graph.AddMetadata(n, "TID", u.String())
8989
}
9090
case "ovsbridge", "ovsport":
9191
if u, _ := n.GetFieldString("UUID"); u != "" {
9292

9393
tid := string(t.hostID) + u + tp
9494

95-
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
95+
u := uuid.NewV5(uuid.NamespaceOID, tid)
9696
t.Graph.AddMetadata(n, "TID", u.String())
9797
}
9898
default:

topology/topology.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24-
uuid "github.com/nu7hatch/gouuid"
24+
uuid "github.com/satori/go.uuid"
2525
"github.com/skydive-project/skydive/graffiti/graph"
2626
"github.com/skydive-project/skydive/graffiti/logging"
2727
"github.com/skydive-project/skydive/netns"
@@ -152,7 +152,7 @@ func NewLink(g *graph.Graph, node1 *graph.Node, node2 *graph.Node, relationType
152152
m[k] = v
153153
}
154154

155-
id, _ := uuid.NewV5(uuid.NamespaceOID, []byte(node1.ID+node2.ID+graph.Identifier(relationType)))
155+
id := uuid.NewV5(uuid.NamespaceOID, string(node1.ID+node2.ID+graph.Identifier(relationType)))
156156
edge := g.CreateEdge(graph.Identifier(id.String()), node1, node2, m, graph.Time(time.Now()))
157157
if edge == nil {
158158
return nil, fmt.Errorf("Failed to create edge with id %s", id.String())

0 commit comments

Comments
 (0)