-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce usage analytics (#379)
Analytics were temporarily removed as we sent them to a third-party server. With this new implementation, these are being sent to Kong Inc directly. Furthermore, to alleviate concerns raised in #242, we are now providing a flag on the root-level, in addition to DECK_ANALYTICS environment variable to tweak the setting.
- Loading branch information
Showing
13 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net" | ||
"os" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/shirou/gopsutil/v3/host" | ||
) | ||
|
||
const ( | ||
reportsHost = "kong-hf.konghq.com" | ||
reportsPort = 61829 | ||
) | ||
|
||
func SendAnalytics(cmd, deckVersion, kongVersion string) error { | ||
if strings.ToLower(os.Getenv("DECK_ANALYTICS")) == "off" { | ||
return nil | ||
} | ||
if cmd == "" { | ||
return fmt.Errorf("invalid argument, 'cmd' cannot be empty") | ||
} | ||
|
||
stats := collectStats(cmd, deckVersion, kongVersion) | ||
body := formatStats(stats) | ||
|
||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", reportsHost, reportsPort)) | ||
if err != nil { | ||
return err | ||
} | ||
conn, err := net.DialUDP("udp", nil, addr) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
|
||
_, err = conn.Write([]byte(body)) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func formatStats(stats map[string]string) string { | ||
var buffer bytes.Buffer | ||
buffer.WriteString("<14>") | ||
for k, v := range stats { | ||
buffer.WriteString(fmt.Sprintf("%s=%s;", k, v)) | ||
} | ||
return buffer.String() | ||
} | ||
|
||
func collectStats(cmd, deckVersion, kongVersion string) map[string]string { | ||
result := map[string]string{ | ||
"signal": "decK", | ||
"v": deckVersion, | ||
"cmd": cmd, | ||
"os": runtime.GOOS, | ||
"arch": runtime.GOARCH, | ||
} | ||
if kongVersion != "" { | ||
result["kv"] = kongVersion | ||
} | ||
info, err := host.Info() | ||
if err == nil { | ||
result["osv"] = info.Platform + " " + info.PlatformVersion | ||
} | ||
return result | ||
} |