Skip to content

Commit

Permalink
feat(kds): add user-agent with useful version info (#7886)
Browse files Browse the repository at this point in the history
This is useful to debug KDS problems with access log on gateways

Signed-off-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
lahabana authored and kumahq[bot] committed Sep 27, 2023
1 parent 0e869f1 commit 126915f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/kumactl/pkg/client/api_server_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import (
)

func ApiServerClient(coordinates *config_proto.ControlPlaneCoordinates_ApiServer, timeout time.Duration) (util_http.Client, error) {
<<<<<<< HEAD
headers := make(map[string]string)
=======
headers := map[string]string{
"User-Agent": kuma_version.Build.UserAgent("kumactl"),
}
>>>>>>> 01b999035 (feat(kds): add user-agent with useful version info (#7886))
baseURL, err := url.Parse(coordinates.Url)
if err != nil {
return nil, errors.Wrapf(err, "Failed to parse API Server URL")
Expand Down
3 changes: 2 additions & 1 deletion pkg/kds/mux/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/kumahq/kuma/pkg/core/runtime/component"
"github.com/kumahq/kuma/pkg/kds/service"
"github.com/kumahq/kuma/pkg/metrics"
"github.com/kumahq/kuma/pkg/version"
)

var (
Expand Down Expand Up @@ -66,7 +67,7 @@ func (c *client) Start(stop <-chan struct{}) (errs error) {
return err
}
dialOpts := c.metrics.GRPCClientInterceptors()
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(
dialOpts = append(dialOpts, grpc.WithUserAgent(version.Build.UserAgent("kds")), grpc.WithDefaultCallOptions(
grpc.MaxCallSendMsgSize(int(c.config.MaxMsgSize)),
grpc.MaxCallRecvMsgSize(int(c.config.MaxMsgSize))),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Expand Down
15 changes: 15 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package version

import (
"fmt"
"runtime"
"strings"
)

Expand Down Expand Up @@ -34,9 +35,23 @@ func FormatDetailedProductInfo() string {
)
}

<<<<<<< HEAD
var (
Build BuildInfo
)
=======
func (b BuildInfo) UserAgent(component string) string {
return fmt.Sprintf("%s/%s (%s; %s; %s/%s)",
component,
b.Version,
runtime.GOOS,
runtime.GOARCH,
b.Product,
b.GitCommit[:7])
}

var Build BuildInfo
>>>>>>> 01b999035 (feat(kds): add user-agent with useful version info (#7886))

func init() {
Build = BuildInfo{
Expand Down

0 comments on commit 126915f

Please sign in to comment.