Skip to content

Commit

Permalink
config: default to kgo dep version in ApiVersions
Browse files Browse the repository at this point in the history
We can use debug.BuildInfo to determine which kgo version the user is
using.

We differ from sarama here by using the kgo version, rather than the
main module's version. This is more accurate to the client software name
/ version. Sarama uses the name "sarama", which will make it difficult
to match the version to the running program, since the version will be
for the binary, not the sarama library.
  • Loading branch information
twmb committed Oct 4, 2021
1 parent 064db6b commit 4a76861
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/kgo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"net"
"regexp"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -358,7 +359,24 @@ func (cfg *cfg) validate() error {
return nil
}

var defaultDialer = &net.Dialer{Timeout: 10 * time.Second}
var (
defaultDialer = &net.Dialer{Timeout: 10 * time.Second}
reVersion = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9\.-]*[a-zA-Z0-9])?$`)
)

func softwareVersion() string {
info, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range info.Deps {
if dep.Path == "github.com/twmb/franz-go" {
if reVersion.MatchString(dep.Version) {
return dep.Version
}
}
}
}
return "unknown"
}

func defaultCfg() cfg {
defaultID := "kgo"
Expand All @@ -375,7 +393,7 @@ func defaultCfg() cfg {
connIdleTimeout: 20 * time.Second,

softwareName: "kgo",
softwareVersion: "0.1.0",
softwareVersion: softwareVersion(),

logger: new(nopLogger),

Expand Down Expand Up @@ -488,7 +506,7 @@ func ClientID(id string) Opt {
// It is generally not recommended to set this. As well, if you do, the name
// and version must match the following regular expression:
//
// [a-zA-Z0-9](?:[a-zA-Z0-9\\-.]*[a-zA-Z0-9])?
// [a-zA-Z0-9](?:[a-zA-Z0-9\.-]*[a-zA-Z0-9])?
//
// Note this means neither the name nor version can be empty.
func SoftwareNameAndVersion(name, version string) Opt {
Expand Down

0 comments on commit 4a76861

Please sign in to comment.