Skip to content

Commit

Permalink
feat(*): support user agent
Browse files Browse the repository at this point in the history
(cherry picked from commit 937bd5bd40b5a3ba181e680b397b7b5fbfb30b1d)
  • Loading branch information
firemiles authored and dakehero committed May 31, 2024
1 parent b4ddcb3 commit 37c43f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
VERSION ?= $(shell git log -1 --date='format:%Y%m%d' --format='format:%ad').$(shell git describe --always --contains HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
DATE = $(shell date +"%Y-%m-%d_%H:%M:%S")
COMMIT = $(shell git rev-parse HEAD | head -c 8)

# Information of OS and ARCH
OS = $(shell uname -s)
Expand All @@ -21,7 +22,7 @@ IMAGE_NAME_TAG ?= $(IMAGE_NAME):$(IMAGE_TAG)
# GO FLAGS
GOPROXY ?=
GO_FLAGS=-ldflags="-s -w"
CNI_VERSION_LD_FLAG=-ldflags="-X github.com/volcengine/cello/pkg/version.Version=$(VERSION)@$(BRANCH)"
CNI_VERSION_LD_FLAG=-ldflags="-X github.com/volcengine/cello/pkg/version.Version=$(VERSION)@$(BRANCH) -X github.com/volcengine/cello/pkg/version.GitCommit=$(COMMIT)"
BUILD_INFO=-ldflags="-X main.BuildInfo=$(VERSION)@$(BRANCH)_$(DATE)"

# BUILD FLAGS
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/volcengine/cello/pkg/utils/logger"
"github.com/volcengine/cello/pkg/utils/math"
"github.com/volcengine/cello/pkg/utils/netns"
"github.com/volcengine/cello/pkg/version"
"github.com/volcengine/cello/types"
)

Expand Down Expand Up @@ -707,6 +708,8 @@ func NewKubernetesClient() (*kubernetes.Clientset, error) {
if err != nil {
return nil, fmt.Errorf("create incluster config failed: %v", err)
}
c.UserAgent = version.UserAgent()

return kubernetes.NewForConfig(c)
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/volcengine/ec2/clientwrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
apiErr "github.com/volcengine/cello/pkg/provider/volcengine/cellohelper/errors"
"github.com/volcengine/cello/pkg/provider/volcengine/credential"
"github.com/volcengine/cello/pkg/utils/logger"
"github.com/volcengine/cello/pkg/version"
)

type ClientSet struct {
Expand Down Expand Up @@ -218,7 +219,8 @@ func NewClient(region, endpoint string, credentialProvider credential.Provider)
cred := credentialProvider.Get()
return credentials.NewStaticCredentials(cred.AccessKeyId, cred.SecretAccessKey, cred.SessionToken), volcengine.String(region)
}).
WithEndpoint(volcengineutil.NewEndpoint().WithCustomerEndpoint(endpoint).GetEndpoint())
WithEndpoint(volcengineutil.NewEndpoint().WithCustomerEndpoint(endpoint).GetEndpoint()).
WithExtraUserAgent(volcengine.String(version.UserAgent()))

if logger.GetLogLevel() == "trace" {
config = config.WithLogger(volcengine.NewDefaultLogger()).
Expand Down
11 changes: 11 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@

package version

import (
"fmt"
"runtime"
)

var Version = "v1.6.2"
var ComponentName = "cello-agent"
var GitCommit = "unset"

func UserAgent() string {
return fmt.Sprintf("%s/%s (%s/%s)/%s", ComponentName, Version, runtime.GOOS, runtime.GOARCH, GitCommit)
}

0 comments on commit 37c43f6

Please sign in to comment.