From 743c6ce2b2365676c8595b1d93eda22a6895fe9d Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Fri, 26 Aug 2022 14:42:08 -0400 Subject: [PATCH] Disable telemetry We are removing all of the telemetry code as it is not needed, and being on by default it may be contrary to CNCF policies around telemetry. * remove check function With no telemetry, there's no need for these function implementations or this syscall in this package anymore. We need to preserve the cadence of checkpoint.go to avoid disturbing any thing that would constitute a breaking change, but basically all of the underlying behavior of check can go away, since every Flux v1 version is out of date every time, we don't need any remote service or lookup to tell if an update is needed. (It's always needed) Users should follow the link to upgrade (eg. the migration guide) Signed-off-by: Kingdon Barrett Update pkg/checkpoint/checkpoint.go Signed-off-by: Kingdon Barrett Co-authored-by: Stefan Prodan --- cmd/fluxd/main.go | 6 +-- go.mod | 1 - pkg/checkpoint/checkpoint.go | 53 +++++++++++++++++------- pkg/checkpoint/checkpoint_darwin.go | 13 ------ pkg/checkpoint/checkpoint_linux_amd64.go | 23 ---------- pkg/checkpoint/checkpoint_linux_arm.go | 23 ---------- pkg/checkpoint/checkpoint_linux_arm64.go | 22 ---------- pkg/checkpoint/types.go | 31 ++++++++++++++ pkg/checkpoint/util.go | 16 +++++++ 9 files changed, 88 insertions(+), 100 deletions(-) delete mode 100644 pkg/checkpoint/checkpoint_darwin.go delete mode 100644 pkg/checkpoint/checkpoint_linux_amd64.go delete mode 100644 pkg/checkpoint/checkpoint_linux_arm.go delete mode 100644 pkg/checkpoint/checkpoint_linux_arm64.go create mode 100644 pkg/checkpoint/types.go create mode 100644 pkg/checkpoint/util.go diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 69edc69e7..bdd908396 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -640,10 +640,10 @@ func main() { // until we have failed or succeeded. updateCheckLogger := log.With(logger, "component", "checkpoint") checkpointFlags := map[string]string{ - "cluster-version": clusterVersion, - "git-configured": strconv.FormatBool(*gitURL != ""), + "cluster-version": "XXXXX", + "git-configured": "XXXXX", } - checkpoint.CheckForUpdates(product, version, checkpointFlags, updateCheckLogger) + checkpoint.CheckForUpdates(product, "XXXXX", checkpointFlags, updateCheckLogger) gitRemote := git.Remote{URL: *gitURL} gitConfig := git.Config{ diff --git a/go.mod b/go.mod index 7ec17a87b..c85c567d2 100644 --- a/go.mod +++ b/go.mod @@ -58,7 +58,6 @@ require ( github.com/stretchr/testify v1.8.0 // Latest versions of github.com/weaveworks/common are not supporterd by Flux. github.com/weaveworks/common v0.0.0-20190410110702-87611edc252e - github.com/weaveworks/go-checkpoint v0.0.0-20220223124739-fd9899e2b4f2 github.com/whilp/git-urls v1.0.0 github.com/xeipuuv/gojsonschema v1.2.0 go.mozilla.org/sops/v3 v3.7.3 diff --git a/pkg/checkpoint/checkpoint.go b/pkg/checkpoint/checkpoint.go index b4b04dc26..f3f10da67 100644 --- a/pkg/checkpoint/checkpoint.go +++ b/pkg/checkpoint/checkpoint.go @@ -4,39 +4,62 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/weaveworks/go-checkpoint" ) const ( versionCheckPeriod = 6 * time.Hour ) -func CheckForUpdates(product, version string, extra map[string]string, logger log.Logger) *checkpoint.Checker { - handleResponse := func(r *checkpoint.CheckResponse, err error) { - if err != nil { - logger.Log("err", err) - return - } - if r.Outdated { - logger.Log("msg", "update available", "latest", r.CurrentVersion, "URL", r.CurrentDownloadURL) - return - } - logger.Log("msg", "up to date", "latest", r.CurrentVersion) +func CheckForUpdates(product, version string, extra map[string]string, logger log.Logger) *checker { + handleResponse := func() { + logger.Log("msg", "Flux v1 is deprecated, please upgrade to v2", "latest", "v2", "URL", "https://fluxcd.io/docs/migration/") } flags := map[string]string{ - "kernel-version": getKernelVersion(), + "kernel-version": "XXXXX", } for k, v := range extra { flags[k] = v } - params := checkpoint.CheckParams{ + params := checkParams{ Product: product, Version: version, SignatureFile: "", Flags: flags, } - return checkpoint.CheckInterval(¶ms, versionCheckPeriod, handleResponse) + return checkInterval(¶ms, versionCheckPeriod, handleResponse) +} + +func checkInterval(p *checkParams, interval time.Duration, + cb func()) *checker { + + state := &checker{ + doneCh: make(chan struct{}), + } + + if isCheckDisabled() { + return state + } + + go func() { + cb() + + for { + after := randomStagger(interval) + state.nextCheckAtLock.Lock() + state.nextCheckAt = time.Now().Add(after) + state.nextCheckAtLock.Unlock() + + select { + case <-time.After(after): + cb() + case <-state.doneCh: + return + } + } + }() + + return state } diff --git a/pkg/checkpoint/checkpoint_darwin.go b/pkg/checkpoint/checkpoint_darwin.go deleted file mode 100644 index 726f522da..000000000 --- a/pkg/checkpoint/checkpoint_darwin.go +++ /dev/null @@ -1,13 +0,0 @@ -package checkpoint - -import ( - "syscall" -) - -func getKernelVersion() string { - v, err := syscall.Sysctl("kern.osrelease") - if err != nil { - panic(err) - } - return "darwin-" + v -} diff --git a/pkg/checkpoint/checkpoint_linux_amd64.go b/pkg/checkpoint/checkpoint_linux_amd64.go deleted file mode 100644 index 29a6cc1d3..000000000 --- a/pkg/checkpoint/checkpoint_linux_amd64.go +++ /dev/null @@ -1,23 +0,0 @@ -package checkpoint - -import ( - "syscall" -) - -func getKernelVersion() string { - var uts syscall.Utsname - syscall.Uname(&uts) - return cstringToString(uts.Release[:]) -} - -func cstringToString(c []int8) string { - s := make([]byte, len(c)) - i := 0 - for ; i < len(c); i++ { - if c[i] == 0 { - break - } - s[i] = uint8(c[i]) - } - return string(s[:i]) -} diff --git a/pkg/checkpoint/checkpoint_linux_arm.go b/pkg/checkpoint/checkpoint_linux_arm.go deleted file mode 100644 index b1c5ac37a..000000000 --- a/pkg/checkpoint/checkpoint_linux_arm.go +++ /dev/null @@ -1,23 +0,0 @@ -package checkpoint - -import ( - "syscall" -) - -func getKernelVersion() string { - var uts syscall.Utsname - syscall.Uname(&uts) - return cstringToString(uts.Release[:]) -} - -func cstringToString(c []uint8) string { - s := make([]byte, len(c)) - i := 0 - for ; i < len(c); i++ { - if c[i] == 0 { - break - } - s[i] = uint8(c[i]) - } - return string(s[:i]) -} diff --git a/pkg/checkpoint/checkpoint_linux_arm64.go b/pkg/checkpoint/checkpoint_linux_arm64.go deleted file mode 100644 index 38221f2b7..000000000 --- a/pkg/checkpoint/checkpoint_linux_arm64.go +++ /dev/null @@ -1,22 +0,0 @@ -package checkpoint - -import ( - "syscall" -) - -func getKernelVersion() string { - var uts syscall.Utsname - syscall.Uname(&uts) - return cstringToString(uts.Release[:]) -} - -func cstringToString(arr []int8) string { - b := make([]byte, 0, len(arr)) - for _, v := range arr { - if v == 0x00 { - break - } - b = append(b, byte(v)) - } - return string(b) -} diff --git a/pkg/checkpoint/types.go b/pkg/checkpoint/types.go new file mode 100644 index 000000000..c8ae7d43d --- /dev/null +++ b/pkg/checkpoint/types.go @@ -0,0 +1,31 @@ +package checkpoint + +import ( + "sync" + "time" +) + +type flag struct { + Key string + Value string +} + +type checkParams struct { + Product string + Version string + Flags map[string]string + ExtraFlags func() []flag + Arch string + OS string + Signature string + SignatureFile string + CacheFile string + CacheDuration time.Duration + Force bool +} + +type checker struct { + doneCh chan struct{} + nextCheckAt time.Time + nextCheckAtLock sync.RWMutex +} diff --git a/pkg/checkpoint/util.go b/pkg/checkpoint/util.go new file mode 100644 index 000000000..7a94dcefd --- /dev/null +++ b/pkg/checkpoint/util.go @@ -0,0 +1,16 @@ +package checkpoint + +import ( + mrand "math/rand" + "os" + "time" +) + +func isCheckDisabled() bool { + return os.Getenv("CHECKPOINT_DISABLE") != "" +} + +func randomStagger(interval time.Duration) time.Duration { + stagger := time.Duration(mrand.Int63()) % (interval / 2) + return 3*(interval/4) + stagger +}