- Make usage language more accurate by stating "repositories"
- Have usage counter be based on a 4 weeks TTL - Add a simple usage counter breakage test
This commit is contained in:
parent
79e4864eb2
commit
4eedd54b66
5 changed files with 20 additions and 8 deletions
|
@ -188,4 +188,4 @@ class DefaultConfig(object):
|
|||
LOG_ARCHIVE_PATH = 'logarchive/'
|
||||
|
||||
# For enterprise:
|
||||
MAXIMUM_CONTAINER_USAGE = 20
|
||||
MAXIMUM_REPOSITORY_USAGE = 20
|
||||
|
|
|
@ -3,7 +3,7 @@ import logging
|
|||
import dateutil.parser
|
||||
import json
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, date
|
||||
|
||||
from data.database import (User, Repository, Image, AccessToken, Role, RepositoryPermission,
|
||||
Visibility, RepositoryTag, EmailConfirmation, FederatedLogin,
|
||||
|
@ -2225,11 +2225,13 @@ def confirm_team_invite(code, user):
|
|||
|
||||
|
||||
def get_repository_usage():
|
||||
one_month_ago = date.today() - timedelta(weeks=4)
|
||||
repo_pull = LogEntryKind.get(name = 'pull_repo')
|
||||
repo_verb = LogEntryKind.get(name = 'repo_verb')
|
||||
return (LogEntry.select()
|
||||
.where((LogEntry.kind == repo_pull) | (LogEntry.kind == repo_verb))
|
||||
.where(~(LogEntry.repository >> None))
|
||||
.where(LogEntry.datetime >= one_month_ago)
|
||||
.group_by(LogEntry.ip)
|
||||
.group_by(LogEntry.repository)
|
||||
.count())
|
||||
|
|
|
@ -64,7 +64,7 @@ class UsageInformation(ApiResource):
|
|||
if SuperUserPermission().can():
|
||||
return {
|
||||
'usage': model.get_repository_usage(),
|
||||
'allowed': app.config.get('MAXIMUM_CONTAINER_USAGE', 20)
|
||||
'allowed': app.config.get('MAXIMUM_REPOSITORY_USAGE', 20)
|
||||
}
|
||||
|
||||
abort(403)
|
||||
|
|
|
@ -34,21 +34,21 @@
|
|||
<div id="usage-counter" class="tab-pane">
|
||||
<div class="quay-spinner" ng-show="systemUsage == null"></div>
|
||||
<div class="usage-chart" total="systemUsage.allowed" limit="systemUsageLimit"
|
||||
current="systemUsage.usage" usage-title="Container Usage"></div>
|
||||
current="systemUsage.usage" usage-title="Deployed Repositories"></div>
|
||||
|
||||
<!-- Alerts -->
|
||||
<div class="alert alert-danger" ng-show="systemUsageLimit == 'over' && systemUsage">
|
||||
You have deployed more containers than your plan allows. Please
|
||||
You have deployed more repositories than your plan allows. Please
|
||||
upgrade your subscription by contacting <a href="mailto:sales@coreos.com">CoreOS Sales</a>.
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning" ng-show="systemUsageLimit == 'at' && systemUsage">
|
||||
You are at your current plan's number of allowed containers. It might be time to think about
|
||||
You are at your current plan's number of allowed repositories. It might be time to think about
|
||||
upgrading your subscription by contacting <a href="mailto:sales@coreos.com">CoreOS Sales</a>.
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success" ng-show="systemUsageLimit == 'near' && systemUsage">
|
||||
You are nearing the number of allowed deployed containers. It might be time to think about
|
||||
You are nearing the number of allowed deployed repositories. It might be time to think about
|
||||
upgrading your subscription by contacting <a href="mailto:sales@coreos.com">CoreOS Sales</a>.
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -43,7 +43,8 @@ from endpoints.api.organization import (OrganizationList, OrganizationMember,
|
|||
from endpoints.api.repository import RepositoryList, RepositoryVisibility, Repository
|
||||
from endpoints.api.permission import (RepositoryUserPermission, RepositoryTeamPermission,
|
||||
RepositoryTeamPermissionList, RepositoryUserPermissionList)
|
||||
from endpoints.api.superuser import SuperUserLogs, SuperUserList, SuperUserManagement
|
||||
from endpoints.api.superuser import (SuperUserLogs, SuperUserList, SuperUserManagement,
|
||||
UsageInformation)
|
||||
|
||||
try:
|
||||
app.register_blueprint(api_bp, url_prefix='/api')
|
||||
|
@ -2358,6 +2359,15 @@ class TestSuperUserList(ApiTestCase):
|
|||
assert len(json['users']) > 0
|
||||
|
||||
|
||||
class TestUsageInformation(ApiTestCase):
|
||||
def test_get_usage(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
json = self.getJsonResponse(UsageInformation)
|
||||
|
||||
assert 'usage' in json
|
||||
assert 'allowed' in json
|
||||
|
||||
|
||||
class TestSuperUserManagement(ApiTestCase):
|
||||
def test_get_user(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
|
Reference in a new issue