Skip to content

Commit

Permalink
Make user analytics optional (#59)
Browse files Browse the repository at this point in the history
* Make user analytics optional

* Mention analytics in README

* Use analytics flag
  • Loading branch information
undera authored Oct 31, 2022
1 parent 329ae05 commit c0a1d31
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To uninstall, run:
helm plugin uninstall dashboard
```

Note: In case standard Helm plugin way did not work for you, you can just download the appropriate [release package](https://github.com/komodorio/helm-dashboard/releases) for your platform, unpack it and just run `dashboard` binary from it.
> In case standard Helm plugin way did not work for you, you can just download the appropriate [release package](https://github.com/komodorio/helm-dashboard/releases) for your platform, unpack it and just run `dashboard` binary from it.
## Running

Expand Down Expand Up @@ -70,6 +70,8 @@ If you don't want browser tab to automatically open, add `--no-browser` flag in

If you want to increase the logging verbosity and see all the debug info, use the `--verbose` flag.

> Disclaimer: For the sake of improving the project quality, there is user analytics collected by the tool. You can disable this collecting with `--no-analytics` option. The collection is done via DataDog RUM and Heap Analytics. Only the anonymous data is collected, no sensitive information is used. No session recording is performed.
## Scanner Integrations

Upon startup, Helm Dashboard detects the presence of [Trivy](https://github.com/aquasecurity/trivy)
Expand Down
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ var (
)

type options struct {
Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
NoBrowser bool `short:"b" long:"no-browser" description:"Do not attempt to open Web browser upon start"`
Version bool `long:"version" description:"Show tool version"`
Version bool `long:"version" description:"Show tool version"`
Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
NoBrowser bool `short:"b" long:"no-browser" description:"Do not attempt to open Web browser upon start"`
NoTracking bool `long:"no-analytics" description:"Disable user analytics (GA, DataDog etc.)"`

Port uint `short:"p" long:"port" description:"Port to start server on" default:"8080"` // TODO: better default port to clash less?

Expand All @@ -31,7 +32,11 @@ func main() {

setupLogging(opts.Verbose)

address, webServerDone := dashboard.StartServer(version, int(opts.Port), opts.Namespace, opts.Verbose)
address, webServerDone := dashboard.StartServer(version, int(opts.Port), opts.Namespace, opts.Verbose, opts.NoTracking)

if !opts.NoTracking {
log.Infof("User analytics collected to improve the quality, disable it with --no-analytics")
}

if opts.NoBrowser {
log.Infof("Access web UI at: %s", address)
Expand Down
7 changes: 5 additions & 2 deletions pkg/dashboard/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"time"
)

func StartServer(version string, port int, ns string, debug bool) (string, utils.ControlChan) {
func StartServer(version string, port int, ns string, debug bool, noTracking bool) (string, utils.ControlChan) {
data := subproc.DataLayer{
Namespace: ns,
}
Expand All @@ -26,7 +26,10 @@ func StartServer(version string, port int, ns string, debug bool) (string, utils
os.Exit(1) // TODO: propagate error instead?
}

data.VersionInfo = &subproc.VersionInfo{CurVer: version}
data.VersionInfo = &subproc.VersionInfo{
CurVer: version,
Analytics: !noTracking,
}
go checkUpgrade(data.VersionInfo)

discoverScanners(&data)
Expand Down
58 changes: 58 additions & 0 deletions pkg/dashboard/static/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
const status = JSON.parse(xhr.responseText);
if (status.Analytics && status.version !== "dev") {
enableDD(status.version)
enableHeap()
}
}
}
xhr.open('GET', '/status', true);
xhr.send(null);


function enableDD(version) {
(function (h, o, u, n, d) {
h = h[d] = h[d] || {
q: [], onReady: function (c) {
h.q.push(c)
}
}
d = o.createElement(u);
d.async = true;
d.src = n
n = o.getElementsByTagName(u)[0];
n.parentNode.insertBefore(d, n)
})(window, document, 'script', 'https://www.datadoghq-browser-agent.com/datadog-rum-v4.js', 'DD_RUM')
DD_RUM.onReady(function () {
DD_RUM.init({
clientToken: 'pub16d64cd1c00cf073ce85af914333bf72',
applicationId: 'e75439e5-e1b3-46ba-a9e9-a2e58579a2e2',
site: 'datadoghq.com',
service: 'helm-dashboard',
version: version,
trackInteractions: true,
trackResources: true,
trackLongTasks: true,
defaultPrivacyLevel: 'mask',
sessionReplaySampleRate: 0
})
})
}

function enableHeap() {
window.heap = window.heap || [], heap.load = function (e, t) {
window.heap.appid = e, window.heap.config = t = t || {};
let r = document.createElement("script");
r.type = "text/javascript", r.async = !0, r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
let a = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(r, a);
for (let n = function (e) {
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)))
}
}, p = ["addEventProperties", "addUserProperties", "clearEventProperties", "identify", "resetIdentity", "removeEventProperty", "setEventProperties", "track", "unsetEventProperty"], o = 0; o < p.length; o++) heap[p[o]] = n(p[o])
};
heap.load("3615793373");
}
26 changes: 0 additions & 26 deletions pkg/dashboard/static/datadog.js

This file was deleted.

24 changes: 5 additions & 19 deletions pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,16 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Helm Dashboard</title>
<script src="static/datadog.js"></script>
<script src="static/analytics.js"></script>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto&family=Inter&family=Poppins:wght@600&family=Poppins:wght@500&family=Inter:wght@500&family=Roboto+Slab:wght@400&family=Roboto+Slab:wght@700&family=Roboto:wght@700&family=Roboto:wght@500"/>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/lightfair.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css"/>
<link href="static/styles-base.css" rel="stylesheet">
<link href="static/styles.css" rel="stylesheet">
<script type="text/javascript">
window.heap = window.heap || [], heap.load = function (e, t) {
window.heap.appid = e, window.heap.config = t = t || {};
var r = document.createElement("script");
r.type = "text/javascript", r.async = !0, r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
var a = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(r, a);
for (var n = function (e) {
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)))
}
}, p = ["addEventProperties", "addUserProperties", "clearEventProperties", "identify", "resetIdentity", "removeEventProperty", "setEventProperties", "track", "unsetEventProperty"], o = 0; o < p.length; o++) heap[p[o]] = n(p[o])
};
heap.load("3615793373");
</script>
</head>
<body>

Expand All @@ -57,7 +41,8 @@
Help
</a>
<ul class="dropdown-menu fs-80">
<li><a class="dropdown-item" href="https://join.slack.com/t/komodorkommunity/shared_invite/zt-1dm3cnkue-ov1Yh~_95teA35QNx5yuMg"
<li><a class="dropdown-item"
href="https://join.slack.com/t/komodorkommunity/shared_invite/zt-1dm3cnkue-ov1Yh~_95teA35QNx5yuMg"
target="_blank"><i class="bi-slack"></i> Support Chat</a></li>
<li><a class="dropdown-item" href="https://github.com/komodorio/helm-dashboard" target="_blank"><i
class="bi-github"></i> Project Page</a></li>
Expand All @@ -68,7 +53,8 @@
</ul>
</li>
<li class="nav-item mx-2 display-none upgrade-possible">
<a class="nav-link position-relative text-danger" href="https://github.com/komodorio/helm-dashboard#installing" target="_blank">
<a class="nav-link position-relative text-danger"
href="https://github.com/komodorio/helm-dashboard#installing" target="_blank">
Upgrade to <span id="toolVersionUpgrade"></span>
</a></li>

Expand Down
1 change: 1 addition & 0 deletions pkg/dashboard/subproc/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type DataLayer struct {
type VersionInfo struct {
CurVer string
LatestVer string
Analytics bool
}

func (d *DataLayer) runCommand(cmd ...string) (string, error) {
Expand Down

0 comments on commit c0a1d31

Please sign in to comment.