Skip to content

Commit

Permalink
Upgrade to bbolt
Browse files Browse the repository at this point in the history
  • Loading branch information
directionless committed Feb 20, 2021
1 parent 39eb243 commit 775d03f
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions cmd/grpc.ext/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"time"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/env"
"github.com/kolide/kit/logutil"
Expand Down Expand Up @@ -84,7 +84,7 @@ func main() {
LoggingInterval: loggingInterval,
}

db, err := bolt.Open(filepath.Join(rootDirectory, "launcher.db"), 0600, nil)
db, err := bbolt.Open(filepath.Join(rootDirectory, "launcher.db"), 0600, nil)
if err != nil {
logutil.Fatal(logger, "err", errors.Wrap(err, "open local store"), "stack", fmt.Sprintf("%+v", err))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/launcher/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package main
import (
"context"

"github.com/boltdb/bolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/actor"
"github.com/kolide/launcher/pkg/control"
"github.com/kolide/launcher/pkg/launcher"
"github.com/pkg/errors"
"go.etcd.io/bbolt"
)

func createControl(ctx context.Context, db *bolt.DB, logger log.Logger, opts *launcher.Options) (*actor.Actor, error) {
func createControl(ctx context.Context, db *bbolt.DB, logger log.Logger, opts *launcher.Options) (*actor.Actor, error) {
level.Debug(logger).Log("msg", "creating control client")

controlOpts := []control.Option{
Expand Down
4 changes: 2 additions & 2 deletions cmd/launcher/control_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package main
import (
"context"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/actor"
Expand All @@ -14,7 +14,7 @@ import (

// createControl creates a no-op actor, as the control server isn't
// yet supported on windows.
func createControl(ctx context.Context, db *bolt.DB, logger log.Logger, opts *launcher.Options) (*actor.Actor, error) {
func createControl(ctx context.Context, db *bbolt.DB, logger log.Logger, opts *launcher.Options) (*actor.Actor, error) {
level.Info(logger).Log("msg", "Cannot create control channel for windows, ignoring")

return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/launcher/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io/ioutil"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/actor"
Expand All @@ -24,7 +24,7 @@ import (
)

// TODO: the extension, runtime, and client are all kind of entangled here. Untangle the underlying libraries and separate into units
func createExtensionRuntime(ctx context.Context, db *bolt.DB, launcherClient service.KolideService, opts *launcher.Options) (
func createExtensionRuntime(ctx context.Context, db *bbolt.DB, launcherClient service.KolideService, opts *launcher.Options) (
run *actor.Actor,
restart func() error, // restart osqueryd runner
shutdown func() error, // shutdown osqueryd runner
Expand Down
6 changes: 3 additions & 3 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"time"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/fs"
Expand Down Expand Up @@ -80,8 +80,8 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
// this. Note that the timeout is documented as failing
// unimplemented on windows, though empirically it seems to
// work.
boltOptions := &bolt.Options{Timeout: time.Duration(30) * time.Second}
db, err := bolt.Open(filepath.Join(rootDirectory, "launcher.db"), 0600, boltOptions)
boltOptions := &bbolt.Options{Timeout: time.Duration(30) * time.Second}
db, err := bbolt.Open(filepath.Join(rootDirectory, "launcher.db"), 0600, boltOptions)
if err != nil {
return errors.Wrap(err, "open launcher db")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/launcher/query_target_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package main
import (
"context"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/actor"
"github.com/kolide/launcher/pkg/querytarget"
"google.golang.org/grpc"
)

func createQueryTargetUpdater(logger log.Logger, db *bolt.DB, grpcConn *grpc.ClientConn) *actor.Actor {
func createQueryTargetUpdater(logger log.Logger, db *bbolt.DB, grpcConn *grpc.ClientConn) *actor.Actor {
ctx, cancel := context.WithCancel(context.Background())

updater := querytarget.NewQueryTargeter(logger, db, grpcConn)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/kolide/launcher

require (
cloud.google.com/go v0.43.0 // indirect
cloud.google.com/go v0.43.0
github.com/Masterminds/semver v1.4.2
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d // indirect
Expand All @@ -11,7 +11,6 @@ require (
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/boltdb/bolt v1.3.1
github.com/bugsnag/bugsnag-go v1.3.2 // indirect
github.com/bugsnag/panicwrap v1.2.0 // indirect
github.com/cenkalti/backoff v2.0.0+incompatible // indirect
Expand Down Expand Up @@ -60,7 +59,6 @@ require (
github.com/onsi/gomega v1.4.3 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pelletier/go-toml v1.6.0
github.com/peterbourgon/ff/v3 v3.0.0
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.2 // indirect
Expand All @@ -71,6 +69,7 @@ require (
github.com/stretchr/testify v1.5.1
github.com/theupdateframework/notary v0.6.1
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9
go.etcd.io/bbolt v1.3.5
go.opencensus.io v0.22.1
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkN
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bugsnag/bugsnag-go v1.3.2 h1:8bcRylldQKQiAx9/KPu9+1iLZwgK1eN1Ib3SROSXfIY=
github.com/bugsnag/bugsnag-go v1.3.2/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/panicwrap v1.2.0 h1:OzrKrRvXis8qEvOkfcxNcYbOd2O7xXS2nnKMEMABFQA=
Expand Down Expand Up @@ -254,6 +252,8 @@ github.com/theupdateframework/notary v0.6.1 h1:7wshjstgS9x9F5LuB1L5mBI2xNMObWqjz
github.com/theupdateframework/notary v0.6.1/go.mod h1:MOfgIfmox8s7/7fduvB2xyPPMJCrjRLRizA8OFwpnKY=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
Expand Down Expand Up @@ -315,6 +315,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200803150936-fd5f0c170ac3 h1:Q8sHd8ZmZZguDQWkUYcD4pIRG5dG+euDEmNyknTRbGs=
golang.org/x/sys v0.0.0-20200803150936-fd5f0c170ac3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
6 changes: 3 additions & 3 deletions pkg/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"net/url"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/pkg/errors"
)
Expand All @@ -17,13 +17,13 @@ type Client struct {
baseURL *url.URL
cancel context.CancelFunc
client *http.Client
db *bolt.DB
db *bbolt.DB
insecure bool
disableTLS bool
logger log.Logger
}

func NewControlClient(db *bolt.DB, addr string, opts ...Option) (*Client, error) {
func NewControlClient(db *bbolt.DB, addr string, opts ...Option) (*Client, error) {
baseURL, err := url.Parse("https://" + addr)
if err != nil {
return nil, errors.Wrap(err, "parsing URL")
Expand Down
42 changes: 21 additions & 21 deletions pkg/osquery/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"time"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/google/uuid"
Expand All @@ -31,7 +31,7 @@ import (
type Extension struct {
NodeKey string
Opts ExtensionOpts
db *bolt.DB
db *bbolt.DB
serviceClient service.KolideService
enrollMutex sync.Mutex
done chan struct{}
Expand Down Expand Up @@ -117,7 +117,7 @@ type ExtensionOpts struct {
// NewExtension creates a new Extension from the provided service.KolideService
// implementation. The background routines should be started by calling
// Start().
func NewExtension(client service.KolideService, db *bolt.DB, opts ExtensionOpts) (*Extension, error) {
func NewExtension(client service.KolideService, db *bbolt.DB, opts ExtensionOpts) (*Extension, error) {
// bucketNames contains the names of buckets that should be created when the
// extension opens the DB. It should be treated as a constant.
var bucketNames = []string{configBucket, statusLogsBucket, resultLogsBucket, initialResultsBucket, ServerProvidedDataBucket}
Expand Down Expand Up @@ -148,7 +148,7 @@ func NewExtension(client service.KolideService, db *bolt.DB, opts ExtensionOpts)
}

// Create Bolt buckets as necessary
err := db.Update(func(tx *bolt.Tx) error {
err := db.Update(func(tx *bbolt.Tx) error {
for _, name := range bucketNames {
_, err := tx.CreateBucketIfNotExists([]byte(name))
if err != nil {
Expand Down Expand Up @@ -206,9 +206,9 @@ func (e *Extension) getHostIdentifier() (string, error) {

// IdentifierFromDB returns the built-in launcher identifier from the config bucket.
// The function is exported to allow for building the kolide_launcher_identifier table.
func IdentifierFromDB(db *bolt.DB) (string, error) {
func IdentifierFromDB(db *bbolt.DB) (string, error) {
var identifier string
err := db.Update(func(tx *bolt.Tx) error {
err := db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
uuidBytes := b.Get([]byte(uuidKey))
gotID, err := uuid.ParseBytes(uuidBytes)
Expand Down Expand Up @@ -239,13 +239,13 @@ func IdentifierFromDB(db *bolt.DB) (string, error) {
}

// NodeKeyFromDB returns the device node key from a local bolt DB
func NodeKeyFromDB(db *bolt.DB) (string, error) {
func NodeKeyFromDB(db *bbolt.DB) (string, error) {
if db == nil {
return "", errors.New("received a nil db")
}

var key []byte
err := db.View(func(tx *bolt.Tx) error {
err := db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
key = b.Get([]byte(nodeKeyKey))
return nil
Expand All @@ -261,13 +261,13 @@ func NodeKeyFromDB(db *bolt.DB) (string, error) {
}

// ConfigFromDB returns the device config from a local bolt DB
func ConfigFromDB(db *bolt.DB) (string, error) {
func ConfigFromDB(db *bbolt.DB) (string, error) {
if db == nil {
return "", errors.New("received a nil db")
}

var key []byte
err := db.View(func(tx *bolt.Tx) error {
err := db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
key = b.Get([]byte(configKey))
return nil
Expand Down Expand Up @@ -348,7 +348,7 @@ func (e *Extension) Enroll(ctx context.Context) (string, bool, error) {
}

// Save newly acquired node key if successful
err = e.db.Update(func(tx *bolt.Tx) error {
err = e.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
return b.Put([]byte(nodeKeyKey), []byte(keyString))
})
Expand All @@ -367,7 +367,7 @@ func (e *Extension) RequireReenroll(ctx context.Context) {
defer e.enrollMutex.Unlock()
// Clear the node key such that reenrollment is required.
e.NodeKey = ""
e.db.Update(func(tx *bolt.Tx) error {
e.db.Update(func(tx *bbolt.Tx) error {
tx.Bucket([]byte(configBucket)).Delete([]byte(nodeKeyKey))
return nil
})
Expand All @@ -386,7 +386,7 @@ func (e *Extension) GenerateConfigs(ctx context.Context) (map[string]string, err
)
// Try to use cached config
var confBytes []byte
e.db.View(func(tx *bolt.Tx) error {
e.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
confBytes = b.Get([]byte(configKey))
return nil
Expand All @@ -398,7 +398,7 @@ func (e *Extension) GenerateConfigs(ctx context.Context) (map[string]string, err
config = string(confBytes)
} else {
// Store good config
e.db.Update(func(tx *bolt.Tx) error {
e.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(configBucket))
return b.Put([]byte(configKey), []byte(config))
})
Expand Down Expand Up @@ -537,7 +537,7 @@ func (e *Extension) writeBufferedLogsForType(typ logger.LogType) error {
// Collect up logs to be sent
var logs []string
var logIDs [][]byte
err = e.db.View(func(tx *bolt.Tx) error {
err = e.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucketName))

c := b.Cursor()
Expand Down Expand Up @@ -583,7 +583,7 @@ func (e *Extension) writeBufferedLogsForType(typ logger.LogType) error {
}

// Delete logs that were successfully sent
err = e.db.Update(func(tx *bolt.Tx) error {
err = e.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucketName))
for _, k := range logIDs {
b.Delete(k)
Expand Down Expand Up @@ -634,7 +634,7 @@ func (e *Extension) purgeBufferedLogsForType(typ logger.LogType) error {
if err != nil {
return err
}
err = e.db.Update(func(tx *bolt.Tx) error {
err = e.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucketName))

logCount := b.Stats().KeyN
Expand Down Expand Up @@ -686,7 +686,7 @@ func (e *Extension) LogString(ctx context.Context, typ logger.LogType, logText s
}

// Buffer the log for sending later in a batch
err = e.db.Update(func(tx *bolt.Tx) error {
err = e.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucketName))

// Log keys are generated with the auto-incrementing sequence
Expand Down Expand Up @@ -859,7 +859,7 @@ type initialRunner struct {
enabled bool
identifier string
client Querier
db *bolt.DB
db *bbolt.DB
}

func (i *initialRunner) Execute(configBlob string, writeFn func(ctx context.Context, l logger.LogType, results []string, reeenroll bool) error) error {
Expand Down Expand Up @@ -950,7 +950,7 @@ func (i *initialRunner) Execute(configBlob string, writeFn func(ctx context.Cont

func (i *initialRunner) queriesToRun(allFromConfig []string) (map[string]struct{}, error) {
known := make(map[string]struct{})
err := i.db.View(func(tx *bolt.Tx) error {
err := i.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(initialResultsBucket))
for _, q := range allFromConfig {
knownQuery := b.Get([]byte(q))
Expand All @@ -966,7 +966,7 @@ func (i *initialRunner) queriesToRun(allFromConfig []string) (map[string]struct{
}

func (i *initialRunner) cacheRanQueries(known map[string]struct{}) error {
err := i.db.Update(func(tx *bolt.Tx) error {
err := i.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(initialResultsBucket))
for q := range known {
if err := b.Put([]byte(q), []byte(q)); err != nil {
Expand Down
Loading

0 comments on commit 775d03f

Please sign in to comment.