Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.25'
cache-dependency-path: go.sum

- name: Install pcap
Expand Down
2 changes: 1 addition & 1 deletion .mk/proto.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define PROTOC_GEN
go install github.com/golang/protobuf/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
protoc -I. -Iflow/layers --go_out $$GOPATH/src $1
endef

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 as builder
FROM ubuntu:24.04 AS builder
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update \
&& apt-get -y install build-essential git-core golang npm openvswitch-common libpcap0.8 libpcap0.8-dev libxml2-dev protobuf-compiler libprotobuf-dev libvirt-dev curl \
Expand All @@ -8,7 +8,7 @@ COPY . .
ARG GOPATH=/go
RUN make build

FROM ubuntu:22.04 as skydive
FROM ubuntu:24.04 AS skydive
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update \
&& apt-get -y install golang npm openvswitch-common libpcap0.8 libvirt0 \
Expand Down
2 changes: 1 addition & 1 deletion config/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/casbin/casbin/log"
"github.com/casbin/casbin/model"
"github.com/casbin/casbin/persist"
etcd "go.etcd.io/etcd/client/v2"
etcd "go.etcd.io/etcd/client/v3"

"github.com/skydive-project/skydive/graffiti/logging"
"github.com/skydive-project/skydive/graffiti/rbac"
Expand Down
2 changes: 1 addition & 1 deletion flow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package flow

import (
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/skydive-project/skydive/config"
"github.com/skydive-project/skydive/graffiti/filters"
Expand Down
2 changes: 1 addition & 1 deletion flow/flow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

488 changes: 174 additions & 314 deletions flow/layers/dns.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion flow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package flow

import (
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/skydive-project/skydive/graffiti/logging"
ws "github.com/skydive-project/skydive/graffiti/websocket"
Expand Down
595 changes: 359 additions & 236 deletions go.mod

Large diffs are not rendered by default.

2,440 changes: 1,832 additions & 608 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion graffiti/api/rest/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

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

etcdclient "github.com/skydive-project/skydive/graffiti/etcd/client"
"github.com/skydive-project/skydive/graffiti/logging"
Expand Down
50 changes: 28 additions & 22 deletions graffiti/etcd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package client

import (
"context"
"crypto/tls"
"fmt"
"strconv"
"time"

etcd "go.etcd.io/etcd/client/v2"
etcd "go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/skydive-project/skydive/graffiti/logging"
)
Expand Down Expand Up @@ -60,10 +63,9 @@ type MasterElectionService interface {

// Client describes a ETCD configuration client
type Client struct {
id string
client *etcd.Client
KeysAPI etcd.KeysAPI
logger logging.Logger
c *etcd.Client
id string
logger logging.Logger
}

// Opts describes the options of an etcd client
Expand All @@ -75,16 +77,19 @@ type Opts struct {

// GetInt64 returns an int64 value from the configuration key
func (client *Client) GetInt64(key string) (int64, error) {
resp, err := client.KeysAPI.Get(context.Background(), key, nil)
resp, err := client.c.Get(context.Background(), key)
if err != nil {
return 0, err
}
return strconv.ParseInt(resp.Node.Value, 10, 64)
if len(resp.Kvs) != 1 {
return 0, fmt.Errorf("bad response key %s len Kvs %d", key, len(resp.Kvs))
}
return strconv.ParseInt(string(resp.Kvs[0].Value), 10, 64)
}

// SetInt64 set an int64 value to the configuration key
func (client *Client) SetInt64(key string, value int64) error {
_, err := client.KeysAPI.Set(context.Background(), key, strconv.FormatInt(value, 10), nil)
_, err := client.c.Put(context.Background(), key, strconv.FormatInt(value, 10), nil)
return err
}

Expand All @@ -103,11 +108,7 @@ func (client *Client) Start() {

// Stop the client
func (client *Client) Stop() {
if tr, ok := etcd.DefaultTransport.(interface {
CloseIdleConnections()
}); ok {
tr.CloseIdleConnections()
}
client.c.Close()
}

// NewElection creates a new ETCD master elector
Expand All @@ -129,23 +130,28 @@ func NewClient(id string, opts Opts) (*Client, error) {
opts.Logger = logging.GetLogger()
}

tlsConfig := &tls.Config{
InsecureSkipVerify: false, // Set to true only for testing with self-signed certs
}

dialOptions := []grpc.DialOption{
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
}

cfg := etcd.Config{
Endpoints: opts.Servers,
Transport: etcd.DefaultTransport,
HeaderTimeoutPerRequest: opts.Timeout,
Endpoints: opts.Servers,
DialOptions: dialOptions,
DialTimeout: opts.Timeout,
}

client, err := etcd.New(cfg)
if err != nil {
return nil, fmt.Errorf("Failed to connect to etcd: %s", err)
}

kapi := etcd.NewKeysAPI(client)

return &Client{
id: id,
client: &client,
KeysAPI: kapi,
logger: opts.Logger,
c: client,
id: id,
logger: opts.Logger,
}, nil
}
68 changes: 45 additions & 23 deletions graffiti/etcd/client/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/safchain/insanelock"
etcd "go.etcd.io/etcd/client/v2"
etcd "go.etcd.io/etcd/client/v3"
"golang.org/x/net/context"

"github.com/skydive-project/skydive/graffiti/logging"
Expand All @@ -36,15 +36,15 @@ const (
// MasterElector describes an ETCD master elector
type MasterElector struct {
insanelock.RWMutex
EtcdKeyAPI etcd.KeysAPI
HolderID string
path string
listeners []MasterElectionListener
cancel context.CancelFunc
master bool
state service.State
wg sync.WaitGroup
logger logging.Logger
Client *etcd.Client
HolderID string
path string
listeners []MasterElectionListener
cancel context.CancelFunc
master bool
state service.State
wg sync.WaitGroup
logger logging.Logger
}

// TTL time to live
Expand All @@ -58,18 +58,25 @@ func (le *MasterElector) holdLock(quit chan bool) {
tick := time.NewTicker(timeout / 2)
defer tick.Stop()

setOptions := &etcd.SetOptions{
TTL: timeout,
PrevExist: etcd.PrevExist,
PrevValue: le.HolderID,
leaseResp, err := le.Client.Grant(context.Background(), int64(timeout.Seconds()))
if err != nil {
panic(err)
}

ch := tick.C

for {
select {
case <-ch:
if _, err := le.EtcdKeyAPI.Set(context.Background(), le.path, le.HolderID, setOptions); err != nil {
if _, err := le.Client.Txn(context.Background()).
If(
etcd.Compare(etcd.Value(le.path), "=", le.HolderID), // PrevValue
etcd.Compare(etcd.CreateRevision(le.path), ">", 0), // PrevExist (key must exist)
).
Then(
etcd.OpPut(le.path, le.HolderID, etcd.WithLease(leaseResp.ID)), // Set the key with the lease (TTL)
).
Commit(); err != nil {
return
}
case <-quit:
Expand All @@ -90,17 +97,32 @@ func (le *MasterElector) IsMaster() bool {
// election is done
func (le *MasterElector) start(first chan struct{}) {
// delete previous Lock
le.EtcdKeyAPI.Delete(context.Background(), le.path, &etcd.DeleteOptions{PrevValue: le.HolderID})

if _, err := le.Client.Txn(context.Background()).
If(
etcd.Compare(etcd.Value(le.path), "=", le.HolderID),
).
Then(
etcd.OpDelete(le.path),
).
Commit(); err != nil {
panic(err)
}
quit := make(chan bool)

// try to get the lock
setOptions := &etcd.SetOptions{
TTL: timeout,
PrevExist: etcd.PrevNoExist,
leaseResp, err := le.Client.Grant(context.Background(), int64(timeout.Seconds()))
if err != nil {
panic(err)
}

if _, err := le.EtcdKeyAPI.Set(context.Background(), le.path, le.HolderID, setOptions); err == nil {
if _, err := le.Client.Txn(context.Background()).
If(
etcd.Compare(etcd.CreateRevision(le.path), "=", 0), // Key does NOT exist
).
Then(
etcd.OpPut(le.path, le.HolderID, etcd.WithLease(leaseResp.ID)), // Set with lease (TTL)
).
Commit(); err != nil {

le.logger.Infof("starting as the master for %s: %s", le.path, le.HolderID)

le.Lock()
Expand All @@ -124,7 +146,7 @@ func (le *MasterElector) start(first chan struct{}) {
}

// now watch for changes
watcher := le.EtcdKeyAPI.Watcher(le.path, &etcd.WatcherOptions{})
watcher := le.Client.Watch(le.path, &etcd.WatcherOptions{})

ctx, cancel := context.WithCancel(context.Background())
le.cancel = cancel
Expand Down
3 changes: 1 addition & 2 deletions graffiti/etcd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"

"go.etcd.io/etcd/client/pkg/v3/types"
client "go.etcd.io/etcd/client/v2"
client "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/osutil"
"go.etcd.io/etcd/server/v3/embed"

Expand Down Expand Up @@ -72,7 +72,6 @@ func NewEmbeddedServer(opts EmbeddedServerOpts) (*EmbeddedServer, error) {
cfg := embed.NewConfig()
cfg.Name = opts.Name
cfg.Dir = opts.DataDir
cfg.EnableV2 = true
cfg.ClusterState = embed.ClusterStateFlagNew
cfg.MaxWalFiles = opts.MaxWalFiles
cfg.MaxSnapFiles = opts.MaxSnapFiles
Expand Down
Loading
Loading