Skip to content

Commit 9fb209e

Browse files
mkovaluafelliott
andauthored
[ENG-5751] remove old keen logic (#11082)
* ENG-5751 remove old keen logic * add migration * remove legacy keen from metrics .js (maybe another keen logic is also needed to be removed in the files) * remove dashboard keen (it is not used in any views) * ENG-5751 code updates * ENG-5751 remove keen dependency from poetry * ENG-5751 code updates * code updates * ENG-5751 resolve PR comments * ENG-5751 add default '' analytics_key * ENG-5751 remove base_analytics.html * add keen-dashboards.css * fix/ENG-5751 it seems 'keen' is used in base mako files and keen js rely on it and it is not needed to be deleted * fix/ENG-5751 resolve PR comments (not confident about 'getUniqueId' implementation https://stackoverflow.com/questions/18230217/javascript-generate-a-random-number-within-a-range-using-crypto-getrandomvalues ) * remove keen-tracking * update getUniqueId * fix/ENG-5751 PR comments related updates * fix/ENG-5751 PR comments related updates * remove geoip from deps and location code from app * PR comment related updates #10992 (comment) * fix migrations conflicts * a few tidy-ups: * Relocate code changes in api.nodes.serializers to be more compact when squished. * Really delete `cumulative_plos_metrics.py`. Per Eric's comments on Slack, we no longer need this. * Remove `cumulative_plos_metrics.py`-related config from website.settings.defaults.py * Add attributive comments for borrowed code in metrics library. --------- Co-authored-by: Fitz Elliott <[email protected]>
1 parent 75c4d9d commit 9fb209e

File tree

31 files changed

+133
-2274
lines changed

31 files changed

+133
-2274
lines changed

admin/base/settings/defaults.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,6 @@
199199
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
200200
NOSE_ARGS = ['--verbosity=2']
201201

202-
# Keen.io settings in local.py
203-
KEEN_PROJECT_ID = osf_settings.KEEN['private']['project_id']
204-
KEEN_READ_KEY = osf_settings.KEEN['private']['read_key']
205-
KEEN_WRITE_KEY = osf_settings.KEEN['private']['write_key']
206-
207-
KEEN_CREDENTIALS = {
208-
'keen_ready': False
209-
}
210-
211-
if KEEN_CREDENTIALS['keen_ready']:
212-
KEEN_CREDENTIALS.update({
213-
'keen_project_id': KEEN_PROJECT_ID,
214-
'keen_read_key': KEEN_READ_KEY,
215-
'keen_write_key': KEEN_WRITE_KEY
216-
})
217-
218202

219203
# Set in local.py
220204
DESK_KEY = ''

admin/metrics/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from django.contrib.auth.mixins import PermissionRequiredMixin
33

44
from admin.base import settings
5-
from admin.base.settings import KEEN_CREDENTIALS
65

76

87
class MetricsView(PermissionRequiredMixin, TemplateView):
@@ -11,7 +10,6 @@ class MetricsView(PermissionRequiredMixin, TemplateView):
1110
raise_exception = True
1211

1312
def get_context_data(self, **kwargs):
14-
kwargs.update(KEEN_CREDENTIALS.copy())
1513
api_report_url = f'{settings.API_DOMAIN}_/metrics/reports/'
1614
kwargs.update({'metrics_url': api_report_url})
1715
return super().get_context_data(**kwargs)

admin/nodes/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ def post(self, request, *args, **kwargs):
643643
node = self.get_object()
644644

645645
node.is_public = False
646-
node.keenio_read_key = ''
647646

648647
# After set permissions callback
649648
for addon in node.get_addons():

admin/static/css/keen-dashboards.css

100755100644
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,4 @@ body.application .return-link:hover,
113113
.hr-menu {
114114
background-color: lightgray;
115115
height: 1px;
116-
}
117-
118-
#reload-node-logs {
119-
margin-left: 20px;
120-
}
116+
}

admin/static/js/metrics/metrics.es6.js

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@ require('keen-dataviz/dist/keen-dataviz.min.css');
55

66

77
var c3 = require('c3/c3.js');
8-
var keen = require('keen-js');
98
var keenDataviz = require('keen-dataviz');
10-
var keenAnalysis = require('keen-analysis');
119
var $ = require('jquery');
1210

13-
var client = new keenAnalysis({
14-
projectId: keenProjectId,
15-
readKey: keenReadKey
16-
});
17-
18-
var publicClient = new keenAnalysis({
19-
projectId: keenPublicProjectId,
20-
readKey: keenPublicReadKey
21-
});
2211

2312
// Heights and Colors for the below rendered
2413
// Keen and c3 Data visualizations
@@ -423,67 +412,6 @@ var getMetricTitle = function(metric, type) {
423412
return title;
424413
};
425414

426-
var renderKeenMetric = function(element, type, query, height, colors, keenClient) {
427-
if (!keenClient) {
428-
keenClient = client;
429-
}
430-
431-
var chart = new keenDataviz()
432-
.el(element)
433-
.height(height)
434-
.title(' ')
435-
.type(type)
436-
.prepare();
437-
438-
if (colors) {
439-
chart.colors([colors]);
440-
}
441-
442-
keenClient
443-
.run(query)
444-
.then(function(res){
445-
var metricChart = chart.data(res);
446-
metricChart.dataset.sortRows("desc", function(row) {
447-
return row[1]
448-
});
449-
metricChart.render();
450-
})
451-
.catch(function(err){
452-
chart.message(err.message);
453-
});
454-
};
455-
456-
var renderNodeLogsForOneUserChart = function(user_id) {
457-
var chart = new keenDataviz()
458-
.el('#yesterdays-node-logs-by-user')
459-
.height(bigMetricHeight)
460-
.title('Individual Logs for ' + '<a href=../users/' + user_id + '>' + user_id + '</a>')
461-
.type('line')
462-
.prepare();
463-
464-
client
465-
.query('count', {
466-
event_collection: "node_log_events",
467-
interval: "hourly",
468-
group_by: "action",
469-
filters: [{
470-
property_name: 'user_id',
471-
operator: 'eq',
472-
property_value: user_id
473-
}],
474-
timeframe: "previous_1_days",
475-
timezone: "UTC"
476-
})
477-
.then(function(res){
478-
chart
479-
.data(res)
480-
.render();
481-
})
482-
.catch(function(err){
483-
chart.message(err.message);
484-
});
485-
};
486-
487415
// called from pageview collection
488416
var differenceGrowthBetweenMetrics = function(query1, query2, totalQuery, element, colors) {
489417

@@ -837,46 +765,6 @@ var renderEmailDomainsChart = function() {
837765
});
838766
};
839767

840-
var NodeLogsPerUser = function() {
841-
var chart = new keenDataviz()
842-
.el('#yesterdays-node-logs-by-user')
843-
.title(' ')
844-
.height(bigMetricHeight)
845-
.chartOptions({
846-
data: {
847-
onclick: function (d, element) {
848-
renderNodeLogsForOneUserChart(d.name);
849-
}
850-
}
851-
})
852-
853-
.type('line')
854-
.prepare();
855-
856-
client
857-
.query('count', {
858-
event_collection: 'node_log_events',
859-
group_by: "user_id",
860-
timeframe: 'previous_1_days',
861-
interval: 'hourly'
862-
})
863-
.then(function (res) {
864-
var chartWithData = chart.data(res);
865-
chartWithData.dataset.filterColumns(function (column, index) {
866-
var logThreshhold = 25;
867-
for (var i = 0; i < column.length; i++) {
868-
if (column[i] > logThreshhold && column[0] != 'null' && column[0] != 'uj57r') {
869-
return column;
870-
}
871-
}
872-
});
873-
874-
chartWithData.render();
875-
})
876-
.catch(function (err) {
877-
chart.message(err.message);
878-
});
879-
};
880768

881769
var renderRawNodeMetrics = function() {
882770
var propertiesAndElements = [
@@ -966,7 +854,6 @@ var UserGainMetrics = function() {
966854
renderMainCounts();
967855
renderWeeklyUserGainMetrics();
968856
renderEmailDomainsChart();
969-
NodeLogsPerUser();
970857
};
971858

972859

@@ -1084,36 +971,6 @@ function renderPreprintMetrics(timeframe) {
1084971
// ><+><+><+<+><+
1085972

1086973
var DownloadMetrics = function() {
1087-
1088-
// ********** legacy keen **********
1089-
var totalDownloadsQuery = new keenAnalysis.Query("count", {
1090-
eventCollection: "file_stats",
1091-
timeframe: 'previous_1_days',
1092-
filters: [{
1093-
property_name: 'action.type',
1094-
operator: 'eq',
1095-
property_value: 'download_file',
1096-
timezone: "UTC"
1097-
}]
1098-
});
1099-
renderKeenMetric("#number-of-downloads", "metric", totalDownloadsQuery,
1100-
defaultHeight, defaultColor, publicClient);
1101-
1102-
// ********** legacy keen **********
1103-
var uniqueDownloadsQuery = new keenAnalysis.Query("count_unique", {
1104-
eventCollection: "file_stats",
1105-
timeframe: 'previous_1_days',
1106-
target_property: 'file.resource',
1107-
filters: [{
1108-
property_name: 'action.type',
1109-
operator: 'eq',
1110-
property_value: 'download_file',
1111-
timezone: "UTC"
1112-
}]
1113-
});
1114-
renderKeenMetric("#number-of-unique-downloads", "metric", uniqueDownloadsQuery,
1115-
defaultHeight, defaultColor, publicClient);
1116-
1117974
renderDownloadMetrics();
1118975
};
1119976

@@ -1138,13 +995,11 @@ function renderDownloadMetrics(timeframe) {
1138995

1139996
module.exports = {
1140997
UserGainMetrics: UserGainMetrics,
1141-
NodeLogsPerUser: NodeLogsPerUser,
1142998
InstitutionMetrics: InstitutionMetrics,
1143999
RawNumberMetrics: RawNumberMetrics,
11441000
AddonMetrics: AddonMetrics,
11451001
PreprintMetrics: PreprintMetrics,
11461002
DownloadMetrics: DownloadMetrics,
1147-
KeenRenderMetrics: renderKeenMetric,
11481003
RenderPreprintMetrics: renderPreprintMetrics,
11491004
RenderDownloadMetrics: renderDownloadMetrics,
11501005
};

admin/static/js/pages/metrics-page.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
'use strict';
22

33
var $ = require('jquery');
4-
var keenAnalysis = require('keen-analysis');
54
var Metrics = require('js/metrics/metrics');
65

76

87

9-
keenAnalysis.ready(function() {
10-
8+
$( document ).ready(function() {
119
Metrics.UserGainMetrics();
1210

13-
$('#reload-node-logs')[0].onclick = function() {
14-
Metrics.NodeLogsPerUser();
15-
};
16-
1711
$('#institution-tab')[0].onclick = function() {
1812
Metrics.InstitutionMetrics();
1913
};

0 commit comments

Comments
 (0)