From c0ae362c8777808ea2422c323b596889e310235b Mon Sep 17 00:00:00 2001 From: Effi Date: Thu, 24 Aug 2023 01:55:16 +0300 Subject: [PATCH] telemetry (#367) Co-authored-by: Reuven --- Dockerfile | 1 + README.md | 6 ++++++ go.mod | 5 ++++- go.sum | 13 ++++++++++--- internal/run.go | 49 +++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4dc52b01..4e9d1610 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ ### Go get dependecies and build ### FROM golang:1.21 as builder +ENV PLATFORM docker WORKDIR /go/src/app COPY go.mod go.sum ./ diff --git a/README.md b/README.md index a3930fac..a370006c 100644 --- a/README.md +++ b/README.md @@ -279,5 +279,11 @@ References are normally resolved automatically when you load the spec. In other If you have other ideas, please [let us know](https://github.com/Tufin/oasdiff/discussions/new?category=ideas). +## Telemetry +The oasdiff tool collects data in order to help us, the development team, understand how it is being used and what we can to do to continue improving it. +We use this data in compliance with our [privacy policy](https://www.oasdiff.com/about/privacy-policy). +To disable telemetry, add the environment variable: `OASDIFF_NO_TELEMETRY=1` + ## Credits This project relies on the excellent implementation of OpenAPI 3.0 for Go: [kin-openapi](https://github.com/getkin/kin-openapi). + diff --git a/go.mod b/go.mod index df96fbfc..d5692080 100644 --- a/go.mod +++ b/go.mod @@ -6,17 +6,20 @@ require ( cloud.google.com/go v0.110.7 github.com/TwiN/go-color v1.4.1 github.com/getkin/kin-openapi v0.118.0 + github.com/oasdiff/telemetry v0.0.5 github.com/stretchr/testify v1.8.4 github.com/yargevad/filepathx v1.0.0 github.com/yuin/goldmark v1.5.6 - golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 gopkg.in/yaml.v3 v3.0.1 ) require ( + github.com/denisbrodbeck/machineid v1.0.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/sys v0.11.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 520e4710..6c352352 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/getkin/kin-openapi v0.118.0 h1:z43njxPmJ7TaPpMSCQb7PN0dEYno4tyBPQcrFdHoLuM= github.com/getkin/kin-openapi v0.118.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -39,6 +41,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/oasdiff/telemetry v0.0.5 h1:+0b0q5MVUqFauK7YZvETzKgYs9kyGmsH+9+parGAnCM= +github.com/oasdiff/telemetry v0.0.5/go.mod h1:GCpMPOYNwarTUnqa7iKOHOZ+VzzNTlXnH7x+I7GQM7k= github.com/perimeterx/marshmallow v1.1.4/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= @@ -62,14 +66,17 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= -github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc= github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA= github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA= github.com/yuin/goldmark v1.5.6/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/internal/run.go b/internal/run.go index 601c7f54..b0dd5e7d 100644 --- a/internal/run.go +++ b/internal/run.go @@ -2,8 +2,12 @@ package internal import ( "io" + "os" "strconv" + "time" + "github.com/oasdiff/telemetry/client" + "github.com/oasdiff/telemetry/model" "github.com/spf13/cobra" "github.com/tufin/oasdiff/build" ) @@ -26,14 +30,7 @@ func Run(args []string, stdout io.Writer, stderr io.Writer) int { getChangelogCmd(), ) - if err := rootCmd.Execute(); err != nil { - if ret := getReturnValue(rootCmd); ret != 0 { - return ret - } - return 100 - } - - return getReturnValue(rootCmd) + return strategy()(rootCmd) } func setReturnValue(cmd *cobra.Command, code int) { @@ -62,3 +59,39 @@ func getReturnValue(cmd *cobra.Command) int { return code } + +func strategy() func(*cobra.Command) int { + + if os.Getenv(model.EnvNoTelemetry) == "1" { + return run + } + + return func(cmd *cobra.Command) int { + c := make(chan int) + go func() { + defer close(c) + _ = client.NewCollector().Send(cmd) + }() + + ret := run(cmd) + + select { + case <-c: + case <-time.After(model.DefaultTimeout): + } + + return ret + } +} + +func run(cmd *cobra.Command) int { + + if err := cmd.Execute(); err != nil { + if ret := getReturnValue(cmd); ret != 0 { + return ret + } + return 100 + } + + return getReturnValue(cmd) +}