Skip to content

Commit

Permalink
telemetry (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: Reuven <[email protected]>
  • Loading branch information
effoeffi and Reuven authored Aug 23, 2023
1 parent 44d94da commit c0ae362
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 ./

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
13 changes: 10 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
49 changes: 41 additions & 8 deletions internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}

0 comments on commit c0ae362

Please sign in to comment.