From 0b06036a3938b3a2cadec786d52e23c0fb69ce3f Mon Sep 17 00:00:00 2001 From: Itiel shwartz Date: Thu, 24 Nov 2022 12:35:45 +0200 Subject: [PATCH] add stats and change heap (#108) * add stats and change heap * improve analytics * revert main changes * add repo --- main.go | 2 +- pkg/dashboard/server.go | 9 +++++---- pkg/dashboard/static/analytics.js | 15 +++++++++++---- pkg/dashboard/static/list-view.js | 2 ++ pkg/dashboard/static/repo.js | 3 ++- pkg/dashboard/static/scripts.js | 3 ++- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 6a19ce4..a1b6152 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) var ( - version = "dev" + version = "0.0.0" commit = "none" date = "unknown" ) diff --git a/pkg/dashboard/server.go b/pkg/dashboard/server.go index 1550b1f..9fae8a9 100644 --- a/pkg/dashboard/server.go +++ b/pkg/dashboard/server.go @@ -35,10 +35,11 @@ func (s Server) StartServer() (string, utils.ControlChan) { log.Errorf("Failed to check that Helm is operational, cannot continue. The error was: %s", err) os.Exit(1) // TODO: propagate error instead? } - + isDevModeWithAnalytics := os.Getenv("HD_DEV_ANALYTICS") == "true" + enableAnalytics := !s.NoTracking || isDevModeWithAnalytics data.StatusInfo = &subproc.StatusInfo{ CurVer: s.Version, - Analytics: !s.NoTracking, + Analytics: enableAnalytics, LimitedToNamespace: s.Namespace, } go checkUpgrade(data.StatusInfo) @@ -136,13 +137,13 @@ func checkUpgrade(d *subproc.StatusInfo) { v1, err := version.NewVersion(d.CurVer) if err != nil { - log.Warnf("Failed to parse version: %s", err) + log.Warnf("Failed to parse CurVer: %s", err) v1 = &version.Version{} } v2, err := version.NewVersion(d.LatestVer) if err != nil { - log.Warnf("Failed to parse version: %s", err) + log.Warnf("Failed to parse LatestVer: %s", err) } else { if v1.LessThan(v2) { log.Warnf("Newer Helm Dashboard version is available: %s", d.LatestVer) diff --git a/pkg/dashboard/static/analytics.js b/pkg/dashboard/static/analytics.js index 7a5d209..05219b6 100644 --- a/pkg/dashboard/static/analytics.js +++ b/pkg/dashboard/static/analytics.js @@ -3,9 +3,9 @@ xhr.onload = function () { if (xhr.readyState === XMLHttpRequest.DONE) { const status = JSON.parse(xhr.responseText); const version = status.CurVer - if (status.Analytics && version !== "dev") { + if (status.Analytics) { enableDD(version) - enableHeap() + enableHeap(version) } } } @@ -42,7 +42,7 @@ function enableDD(version) { }) } -function enableHeap() { +function enableHeap(version) { window.heap = window.heap || [], heap.load = function (e, t) { window.heap.appid = e, window.heap.config = t = t || {}; let r = document.createElement("script"); @@ -55,5 +55,12 @@ function enableHeap() { } }, 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"); + heap.load("4249623943"); + window.heap.addEventProperties({'version': version}); +} + +function sendStats(name, prop){ + if (window.heap) { + window.heap.track(name, prop); + } } \ No newline at end of file diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index 3b4d836..5280bc7 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -4,6 +4,7 @@ function loadChartsList() { const chartsCards = $("#installedList .body") chartsCards.empty().append("
Loading...
") $.getJSON("/api/helm/charts").fail(function (xhr) { + sendStats('Get releases', {'status': 'failed'}); reportError("Failed to get list of charts", xhr) }).done(function (data) { chartsCards.empty().hide() @@ -12,6 +13,7 @@ function loadChartsList() { let card = buildChartCard(elm); chartsCards.append(card) }) + sendStats('Get releases', {'status': 'success', length:data.length}); filterInstalledList(chartsCards.find(".row")) chartsCards.show() if (!data.length) { diff --git a/pkg/dashboard/static/repo.js b/pkg/dashboard/static/repo.js index 1e1ac63..a3340f4 100644 --- a/pkg/dashboard/static/repo.js +++ b/pkg/dashboard/static/repo.js @@ -4,6 +4,7 @@ function loadRepoView() { $.getJSON("/api/helm/repo").fail(function (xhr) { reportError("Failed to get list of repositories", xhr) + sendStats('Get repo', {'status': 'fail'}); }).done(function (data) { const items = $("#sectionRepo .repo-list ul").empty() data.sort((a, b) => (a.name > b.name) - (a.name < b.name)) @@ -19,7 +20,7 @@ function loadRepoView() { if (!data.length) { items.text("No repositories found, try adding one") } - + sendStats('Get repo', {'status': 'success', length:data.length}); items.find("input").click(function () { $("#inputSearch").val('') const self = $(this) diff --git a/pkg/dashboard/static/scripts.js b/pkg/dashboard/static/scripts.js index 987fbf3..8e77358 100644 --- a/pkg/dashboard/static/scripts.js +++ b/pkg/dashboard/static/scripts.js @@ -40,13 +40,14 @@ function fillClusters(limNS) { }) $.getJSON("/api/kube/contexts").fail(function (xhr) { + sendStats('contexts', {'status': 'fail'}); reportError("Failed to get list of clusters", xhr) }).done(function (data) { $("body").data("contexts", data) const context = getHashParam("context") data.sort((a, b) => (getCleanClusterName(a.Name) > getCleanClusterName(b.Name)) - (getCleanClusterName(a.Name) < getCleanClusterName(b.Name))) fillClusterList(data, context); - + sendStats('contexts', {'status': 'success', length:data.length}); $.getJSON("/api/kube/namespaces").fail(function (xhr) { reportError("Failed to get namespaces", xhr) }).done(function (res) {