Skip to content

Commit

Permalink
Merge pull request #2446 from lebauce/sator-uuid
Browse files Browse the repository at this point in the history
Move to github.com/satori/go.uuid for uuid generation
  • Loading branch information
lebauce authored Apr 8, 2024
2 parents 0faf654 + 1a50ff8 commit bfd8cdf
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ require (
github.com/newtools/ebpf v0.0.0-20190820102627-8b7eaed02eb9
github.com/nimbess/nimbess-agent v0.0.0-20190919205041-4e6f317ac4fd
github.com/nlewo/contrail-introspect-cli v0.0.0-20181003135217-0407b60f2edd
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/olivere/elastic/v7 v7.0.32
github.com/ovn-org/libovsdb v0.4.0
github.com/pierrec/xxHash v0.1.5
Expand All @@ -49,6 +48,7 @@ require (
github.com/robertkrimen/otto v0.3.0
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/sirupsen/logrus v1.9.3
github.com/skydive-project/dede v0.0.0-20200217172954-b1b74a5bb856
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1655,8 +1655,6 @@ github.com/nlewo/contrail-introspect-cli v0.0.0-20181003135217-0407b60f2edd/go.m
github.com/nplanel/ebpf v0.0.0-20190918123742-99947faabce5 h1:4hj49CpBEvoXH4XDmOskKfPnS/0XD7ypIjMD0fETF1Q=
github.com/nplanel/ebpf v0.0.0-20190918123742-99947faabce5/go.mod h1:H74E4gvXfcsOzgaoPSOuQVoKsWQrg2Xbx6+WybLKvyA=
github.com/nsqio/go-nsq v1.0.7/go.mod h1:XP5zaUs3pqf+Q71EqUJs3HYfBIqfK6G83WQMdNN+Ito=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down Expand Up @@ -1835,6 +1833,8 @@ github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8 h1:2c1EFnZHIPCW8q
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3 h1:Y6aFMpbXYw8XtaVS/dT2VSjElvv5yr5eaLPRtErn/HE=
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3/go.mod h1:BOnNgK32KZwrgJ9kI/YH4E/B/De0i+dguUxD/SXabRQ=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/segmentio/kafka-go v0.2.1/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
Expand Down
4 changes: 2 additions & 2 deletions graffiti/api/rest/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync/atomic"
"time"

uuid "github.com/nu7hatch/gouuid"
uuid "github.com/satori/go.uuid"
etcd "go.etcd.io/etcd/client/v2"

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

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

data, err := json.Marshal(&resource)
Expand Down
2 changes: 1 addition & 1 deletion graffiti/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ require (
github.com/mitchellh/hashstructure v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/olivere/elastic/v7 v7.0.32
github.com/peterh/liner v1.2.2
github.com/pierrec/xxHash v0.1.5
github.com/pkg/errors v0.9.1
github.com/pmylund/go-cache v2.1.0+incompatible
github.com/robertkrimen/otto v0.3.0
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3
github.com/satori/go.uuid v1.2.0
github.com/skydive-project/go-debouncer v1.0.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions graffiti/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E=
github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down Expand Up @@ -180,6 +178,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3 h1:Y6aFMpbXYw8XtaVS/dT2VSjElvv5yr5eaLPRtErn/HE=
github.com/safchain/insanelock v0.0.0-20200217234559-cfbf166e05b3/go.mod h1:BOnNgK32KZwrgJ9kI/YH4E/B/De0i+dguUxD/SXabRQ=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
11 changes: 4 additions & 7 deletions graffiti/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"reflect"
"strings"

uuid "github.com/nu7hatch/gouuid"
"github.com/safchain/insanelock"
uuid "github.com/satori/go.uuid"

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

u, _ := uuid.NewV4()
return Identifier(u.String())
return Identifier(uuid.NewV4().String())
}

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

if i == "" {
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(p.ID+c.ID))
i = Identifier(u.String())
i = Identifier(uuid.NewV5(uuid.NamespaceOID, string(p.ID+c.ID)).String())
}

return CreateEdge(i, p, c, m, t, hostname, g.origin)
Expand Down
7 changes: 2 additions & 5 deletions graffiti/storage/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (

"github.com/hashicorp/go-multierror"
version "github.com/hashicorp/go-version"
uuid "github.com/nu7hatch/gouuid"
elastic "github.com/olivere/elastic/v7"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"

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

u5, err := uuid.NewV5(uuid.NamespaceOID, []byte(strings.Join(names, ",")))
if err != nil {
return nil, err
}
u5 := uuid.NewV5(uuid.NamespaceOID, strings.Join(names, ","))

client := &Client{
Config: cfg,
Expand Down
5 changes: 2 additions & 3 deletions graffiti/websocket/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
auth "github.com/abbot/go-http-auth"
proto "github.com/gogo/protobuf/proto"
"github.com/gorilla/websocket"
uuid "github.com/nu7hatch/gouuid"
"github.com/safchain/insanelock"
uuid "github.com/satori/go.uuid"

"github.com/skydive-project/skydive/graffiti/logging"
)
Expand Down Expand Up @@ -198,8 +198,7 @@ func NewStructMessage(ns string, tp string, v interface{}, uuids ...string) *Str
if len(uuids) != 0 {
u = uuids[0]
} else {
v4, _ := uuid.NewV4()
u = v4.String()
u = uuid.NewV4().String()
}

msg := &StructMessage{
Expand Down
4 changes: 2 additions & 2 deletions topology/probes/fabric/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"strings"

uuid "github.com/nu7hatch/gouuid"
uuid "github.com/satori/go.uuid"

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

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

if node := fb.Graph.GetNode(id); node != nil {
Expand Down
17 changes: 4 additions & 13 deletions topology/probes/ovsdb/ofctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"time"

"github.com/avast/retry-go"
uuid "github.com/nu7hatch/gouuid"
uuid "github.com/satori/go.uuid"

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

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

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

func makeFilter(rule *RawRule) string {
Expand Down
10 changes: 5 additions & 5 deletions topology/tid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package topology

import (
uuid "github.com/nu7hatch/gouuid"
uuid "github.com/satori/go.uuid"
"github.com/skydive-project/skydive/graffiti/graph"
"github.com/skydive-project/skydive/graffiti/logging"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func (t *TIDMapper) setTID(parent, child *graph.Node) {

if tid, _ := parent.GetFieldString("TID"); tid != "" {
tid = tid + key + tp
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
u := uuid.NewV5(uuid.NamespaceOID, tid)
t.Graph.AddMetadata(child, "TID", u.String())
}
}
Expand All @@ -77,22 +77,22 @@ func (t *TIDMapper) onNodeEvent(n *graph.Node) {
switch tp {
case "host":
if name, err := n.GetFieldString("Name"); err == nil {
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(name))
u := uuid.NewV5(uuid.NamespaceOID, name)
t.hostID = graph.Identifier(u.String())
t.Graph.AddMetadata(n, "TID", u.String())
}
case "netns":
if path, _ := n.GetFieldString("Path"); path != "" {
tid := string(t.hostID) + path + tp
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
u := uuid.NewV5(uuid.NamespaceOID, tid)
t.Graph.AddMetadata(n, "TID", u.String())
}
case "ovsbridge", "ovsport":
if u, _ := n.GetFieldString("UUID"); u != "" {

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

u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(tid))
u := uuid.NewV5(uuid.NamespaceOID, tid)
t.Graph.AddMetadata(n, "TID", u.String())
}
default:
Expand Down
4 changes: 2 additions & 2 deletions topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"time"

uuid "github.com/nu7hatch/gouuid"
uuid "github.com/satori/go.uuid"
"github.com/skydive-project/skydive/graffiti/graph"
"github.com/skydive-project/skydive/graffiti/logging"
"github.com/skydive-project/skydive/netns"
Expand Down Expand Up @@ -152,7 +152,7 @@ func NewLink(g *graph.Graph, node1 *graph.Node, node2 *graph.Node, relationType
m[k] = v
}

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

0 comments on commit bfd8cdf

Please sign in to comment.