Skip to content

Commit

Permalink
feat: get machineid as client uid
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaidChan committed Dec 27, 2023
1 parent 6869f4b commit 207f6eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
11 changes: 5 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/TencentBlueking/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
pbfs "github.com/TencentBlueking/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/feed-server"
sfs "github.com/TencentBlueking/bk-bcs/bcs-services/bcs-bscp/pkg/sf-share"
"github.com/denisbrodbeck/machineid"
"golang.org/x/exp/slog"

"github.com/TencentBlueKing/bscp-go/internal/cache"
Expand Down Expand Up @@ -55,20 +56,19 @@ type Client interface {
type client struct {
pairs map[string]string

Check failure on line 57 in client/client.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/TencentBlueKing/bscp-go) (gci)
opts options
fingerPrint sfs.FingerPrint
watcher *watcher
upstream upstream.Upstream
}

// New return a bscp client instance
func New(opts ...Option) (Client, error) {
clientOpt := &options{}
fp, err := sfs.GetFingerPrint()
mid, err := machineid.ID()
if err != nil {
return nil, fmt.Errorf("get instance fingerprint failed, err: %s", err.Error())
return nil, fmt.Errorf("get instance fingerprint(machineid) failed, err: %s", err.Error())
}
logger.Info("instance fingerprint", slog.String("fingerprint", fp.Encode()))
clientOpt.fingerprint = fp.Encode()
logger.Info("instance fingerprint(machineid)", slog.String("fingerprint", mid))
clientOpt.fingerprint = mid
clientOpt.uid = clientOpt.fingerprint
for _, opt := range opts {
if e := opt(clientOpt); e != nil {
Expand Down Expand Up @@ -103,7 +103,6 @@ func New(opts ...Option) (Client, error) {
}
c := &client{
opts: *clientOpt,

Check failure on line 105 in client/client.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/TencentBlueKing/bscp-go) (gci)
fingerPrint: fp,
upstream: u,
pairs: pairs,
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230912015319-acb7495967f5
github.com/TencentBlueking/bk-bcs/bcs-services/bcs-bscp v0.0.0-20231226133937-7be33dc8c268
github.com/denisbrodbeck/machineid v1.0.1
github.com/dustin/go-humanize v1.0.1
github.com/fsnotify/fsnotify v1.7.0
github.com/olekukonko/tablewriter v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down

0 comments on commit 207f6eb

Please sign in to comment.