Skip to content

Commit

Permalink
feat(kds): add user-agent with useful version info
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 <[email protected]>
  • Loading branch information
lahabana committed Sep 26, 2023
1 parent 8b3a140 commit 978b6b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 1 addition & 8 deletions app/kumactl/pkg/client/api_server_client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package client

import (
"fmt"
"net/http"
"net/url"
"runtime"
"time"

"github.com/pkg/errors"
Expand All @@ -16,12 +14,7 @@ import (

func ApiServerClient(coordinates *config_proto.ControlPlaneCoordinates_ApiServer, timeout time.Duration) (util_http.Client, error) {
headers := map[string]string{
"User-Agent": fmt.Sprintf("kumactl/%s (%s; %s; %s/%s)",
kuma_version.Build.Version,
runtime.GOOS,
runtime.GOARCH,
kuma_version.Build.Product,
kuma_version.Build.GitCommit[:7]),
"User-Agent": kuma_version.Build.UserAgent("kumactl"),
}
baseURL, err := url.Parse(coordinates.Url)
if err != nil {
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 @@ -25,6 +25,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 muxClientLog = core.Log.WithName("kds-mux-client")
Expand Down Expand Up @@ -63,7 +64,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
11 changes: 11 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 @@ -41,6 +42,16 @@ func (b BuildInfo) FormatDetailedProductInfo() string {
)
}

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

func init() {
Expand Down

0 comments on commit 978b6b5

Please sign in to comment.