Skip to content

Commit 808543f

Browse files
Hacks, add a few more event types to cache
1 parent 70ab5ba commit 808543f

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

Diff for: app/scripts/directives/notifications/notificationDrawerWrapper.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ angular
6060
});
6161

6262
var subscription = notifications.subscribe($routeParams.project, function(notificationGroups) {
63-
console.log('what we got?', notificationGroups);
64-
$scope.notificationGroups = [];
65-
// $scope.notificationGroups = notificationGroups[$routeParams.project];
63+
$scope.notificationGroups = notificationGroups[$routeParams.project] || [];
6664
});
6765

6866
$scope.$on('$destroy', function() {

Diff for: app/scripts/services/notifications.js

+29-14
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ angular
2020
return {
2121
sort: function(type, reason, kind, name, message) {
2222
var msg = `${name}: ${message}`;
23-
var tier1 = `${kind} ${reason}`;
23+
//var tier1 = `${kind} ${reason}`;
2424
cachedEvents[kind] = cachedEvents[kind] || {};
2525
cachedEvents[kind][reason] = cachedEvents[kind][reason] || {};
2626
cachedEvents[kind][reason][type] = cachedEvents[kind][reason][type] || [];
2727
if(!_.contains(cachedEvents[kind][reason][type], msg)) {
2828
cachedEvents[kind][reason][type].unshift(msg);
2929
// no need to keep excessive records...
3030
}
31-
// if we want to limit...
32-
// if(cachedEvents[kind][reason][type].length > 15) {
33-
// cachedEvents[kind][reason][type].length = 15;
34-
// }
31+
// // if we want to limit...
32+
if(cachedEvents[kind][reason][type].length > 6) {
33+
cachedEvents[kind][reason][type].length = 6;
34+
}
3535
// cachedEvents[tier1] = cachedEvents[tier1] || {};
3636
// cachedEvents[tier1][type] = cachedEvents[tier1][type] || [];
3737
// if(!_.contains(cachedEvents[tier1][type], msg)) {
@@ -52,25 +52,27 @@ angular
5252
var save = function(data) {
5353
window[storageType].setItem(cachedUserActionsKey, JSON.stringify(data));
5454
};
55-
var cachedProcessedEvents;
55+
var cachedProcessedEvents = {};
5656
var getTypeIndex = function(type) {
5757
// TODO: verify these are correct
5858
var indexes = {
5959
// Applications
6060
DeploymentConfig: 0,
6161
ReplicationController: 0,
62+
ReplicaSet: 0,
6263
Deployment: 0,
6364
StatefulSet: 0,
6465
Pod: 0,
6566
Service: 0,
6667
Route: 0,
6768
HorizontalPodAutoscaler: 0,
6869
// Builds
70+
BuildConfig: 1,
6971
Build: 1,
7072
Pipeline: 1,
7173
ImageStream: 1,
7274
// Storage
73-
PVC: 2
75+
PersistentVolumeClaim: 2
7476
};
7577
var index = indexes[type];
7678
if(typeof index !== 'number') {
@@ -80,6 +82,10 @@ angular
8082
}
8183
return indexes[type];
8284
};
85+
var isImportantEvent = function(event) {
86+
console.log('isImportantEvent');
87+
return true;
88+
};
8389
// TRELLO for adding build events:
8490
// https://trello.com/c/YiK7d5gs/1149-3-create-events-for-started-completed-failed-builds-builds
8591
// - TODO: white list proactively filter in, if we didnt discuss,
@@ -101,14 +107,18 @@ angular
101107
if(!data) {
102108
return []; // TODO: fix mo' betta
103109
};
104-
cachedProcessedEvents = _.reduce(data.by('metadata.name'), function(result, event) {
110+
console.log('process', _.keys(data.by('metadata.name')).length);
111+
console.log('cache', cachedProcessedEvents);
112+
_.each(data.by('metadata.name'), function(event) {
105113
var namespace = event.involvedObject.namespace;
114+
var type = event.type;
115+
// TODO: type, reason, kind....
106116
var name = event.involvedObject.name;
107117
var uid = event.metadata.uid;
108118
var kind = event.involvedObject.kind;
109119
var index = getTypeIndex(kind);
110-
// there are 3 arrays in the result, each has a specific use:
111-
result[namespace] = result[namespace] || [{
120+
// there are 3 arrays for each namespace, matching the current menu structure:
121+
cachedProcessedEvents[namespace] = cachedProcessedEvents[namespace] || [{
112122
heading: 'Applications',
113123
// Applications: Deployments, Pods, StatefulSets, Services, Routes
114124
notifications: []
@@ -121,21 +131,26 @@ angular
121131
// Storage: PVC
122132
notifications: []
123133
}];
124-
// make the notification object:
125-
result[namespace][index].notifications.push({
134+
if(!cachedProcessedEvents[namespace][index]) {
135+
console.warn('missing, add to index list!', cachedProcessedEvents, namespace, index);
136+
}
137+
if(!isImportantEvent(event)) {
138+
return;
139+
}
140+
cachedProcessedEvents[namespace][index].notifications.push({
126141
unread: !_.get(cachedUserActions, [namespace, uid, 'read']),
127142
message: event.message,
128143
timestamp: event.lastTimestamp,
129144
metadata: event.metadata,
130145
involvedObject: event.involvedObject,
131146
status: event.type,
147+
reason: event.reason,
132148
actions: null
133149
});
134150
// console.log('[', event.type, '>', event.reason, event.involvedObject.kind,']', '(', event.involvedObject.name, ')');
135151
// console.log(' ', event.message);
136152
eventTypeOrganizer.sort(event.type, event.reason, event.involvedObject.kind, event.involvedObject.name, event.message);
137-
return result;
138-
}, {});
153+
});
139154
return cachedProcessedEvents;
140155
};
141156

Diff for: app/views/directives/notifications/notification-body.html

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<span
2424
class="drawer-pf-notification-message"
2525
ng-click="customScope.markRead(notification)">{{notification.message}}</span>
26+
<br />
27+
<!-- TODO: eliminate, this is for filtering -->
28+
<span style="font-size: 0.8em; color: #666;">
29+
{{notification.status}},
30+
{{notification.reason}},
31+
{{notification.involvedObject.kind}},
32+
{{notification.involvedObject.name}}
33+
</span>
2634
<div
2735
class="drawer-pf-notification-info"
2836
ng-click="customScope.markRead(notification)">

0 commit comments

Comments
 (0)