-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quota Notifications #2116
Merged
Merged
Quota Notifications #2116
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,21 @@ | |
angular.module("openshiftConsole") | ||
.factory("QuotaService", function(APIService, | ||
$filter, | ||
$location, | ||
$rootScope, | ||
$routeParams, | ||
$q, | ||
Constants, | ||
DataService, | ||
Logger) { | ||
EventsService, | ||
Logger, | ||
NotificationsService) { | ||
|
||
var isNil = $filter('isNil'); | ||
var usageValue = $filter('usageValue'); | ||
var usageWithUnits = $filter('usageWithUnits'); | ||
var percent = $filter('percent'); | ||
|
||
var isBestEffortPod = function(pod) { | ||
// To be best effort a pod must not have any containers that have non-zero requests or limits | ||
// Break out as soon as we find any pod with a non-zero request or limit | ||
|
@@ -254,6 +263,99 @@ angular.module("openshiftConsole") | |
}); | ||
}; | ||
|
||
var COMPUTE_RESOURCE_QUOTAS = [ | ||
"cpu", | ||
"requests.cpu", | ||
"memory", | ||
"requests.memory", | ||
"limits.cpu", | ||
"limits.memory" | ||
]; | ||
|
||
var getNotificaitonMessage = function(used, usedValue, hard, hardValue, quotaKey) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a comment that this function returns HTML markup, not plain text. |
||
// Note: This function returns HTML markup, not plain text | ||
|
||
var msgPrefix = "Your project is " + (hardValue < usedValue ? 'over' : 'at') + " quota. "; | ||
var msg; | ||
if (_.includes(COMPUTE_RESOURCE_QUOTAS, quotaKey)) { | ||
msg = msgPrefix + "It is using " + percent((usedValue/hardValue), 0) + " of " + usageWithUnits(hard, quotaKey) + " " + humanizeQuotaResource(quotaKey) + "."; | ||
} else { | ||
msg = msgPrefix + "It is using " + usedValue + " of " + hardValue + " " + humanizeQuotaResource(quotaKey) + "."; | ||
} | ||
|
||
msg = _.escape(msg); | ||
|
||
if (Constants.QUOTA_NOTIFICATION_MESSAGE && Constants.QUOTA_NOTIFICATION_MESSAGE[quotaKey]) { | ||
// QUOTA_NOTICIATION_MESSAGE can contain HTML and shouldn't be escaped. | ||
msg += " " + Constants.QUOTA_NOTIFICATION_MESSAGE[quotaKey]; | ||
} | ||
|
||
return msg; | ||
}; | ||
|
||
// Return notifications if you are at quota or over any quota for any resource. Do *not* | ||
// warn about quota for 'resourcequotas' or resources whose hard limit is | ||
// 0, however. | ||
var getQuotaNotifications = function(quotas, clusterQuotas, projectName) { | ||
var notifications = []; | ||
|
||
var notificationsForQuota = function(quota) { | ||
var q = quota.status.total || quota.status; | ||
_.each(q.hard, function(hard, quotaKey) { | ||
var hardValue = usageValue(hard); | ||
var used = _.get(q, ['used', quotaKey]); | ||
var usedValue = usageValue(used); | ||
|
||
// We always ignore quota warnings about being out of | ||
// resourcequotas since end users cant do anything about it | ||
if (quotaKey === 'resourcequotas' || !hardValue || !usedValue) { | ||
return; | ||
} | ||
|
||
if(hardValue <= usedValue) { | ||
notifications.push({ | ||
id: "quota-limit-reached-" + quotaKey, | ||
namespace: projectName, | ||
type: (hardValue < usedValue ? 'warning' : 'info'), | ||
message: getNotificaitonMessage(used, usedValue, hard, hardValue, quotaKey), | ||
isHTML: true, | ||
skipToast: true, | ||
showInDrawer: true, | ||
actions: [ | ||
{ | ||
name: 'View Quotas', | ||
title: 'View project quotas', | ||
onClick: function() { | ||
$location.url("/project/" + $routeParams.project + "/quota"); | ||
$rootScope.$emit('NotificationDrawerWrapper.hide'); | ||
} | ||
}, | ||
{ | ||
name: "Don't Show Me Again", | ||
title: 'Permenantly hide this notificaiton until quota limit changes', | ||
onClick: function(notification) { | ||
NotificationsService.permanentlyHideNotification(notification.uid, notification.namespace); | ||
$rootScope.$emit('NotificationDrawerWrapper.clear', notification); | ||
} | ||
}, | ||
{ | ||
name: "Clear", | ||
title: 'Clear this notificaiton', | ||
onClick: function(notification) { | ||
$rootScope.$emit('NotificationDrawerWrapper.clear', notification); | ||
} | ||
} | ||
] | ||
}); | ||
} | ||
}); | ||
}; | ||
_.each(quotas, notificationsForQuota); | ||
_.each(clusterQuotas, notificationsForQuota); | ||
|
||
return notifications; | ||
}; | ||
|
||
// Warn if you are at quota or over any quota for any resource. Do *not* | ||
// warn about quota for 'resourcequotas' or resources whose hard limit is | ||
// 0, however. | ||
|
@@ -324,6 +426,7 @@ angular.module("openshiftConsole") | |
getLatestQuotaAlerts: getLatestQuotaAlerts, | ||
isAnyQuotaExceeded: isAnyQuotaExceeded, | ||
isAnyStorageQuotaExceeded: isAnyStorageQuotaExceeded, | ||
willRequestExceedQuota: willRequestExceedQuota | ||
willRequestExceedQuota: willRequestExceedQuota, | ||
getQuotaNotifications: getQuotaNotifications | ||
}; | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we intend to leave this in as an empty object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so. Similar to the other two empty objects right before this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, they're for custom messages. We generate a default message in code.