Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

Commit 5dbb1163 authored by sebastien letort's avatar sebastien letort

little code factorisation. min date += 3 years. WARN: from-to dates returned...

little code factorisation. min date += 3 years. WARN: from-to dates returned by the API are now in date isoformat YYYY-mm-dd.
parent d6d12547
......@@ -8,7 +8,7 @@ Metrics API allows to get some metrics about some apps.
- a nemo user will have access to nothing.
"""
from datetime import datetime
from datetime import date, datetime
import logging
from django.utils.timezone import make_aware
......@@ -22,15 +22,17 @@ log = logging.getLogger('allgo')
# ~ log = logging.getLogger(__name__)
# ======================================
DATE_FMT = "%d-%m-%Y %H:%M"
# ~ DATE_FMT = "%d-%m-%Y %H:%M"
def fmt_date(date):
return datetime.strftime( date, DATE_FMT )
"""date is datetime object (for from/to)"""
# ~ return datetime.strftime( date, DATE_FMT )
return date.date().isoformat()
DATE_IN_FMT = "%Y-%m-%d"
def str2date(date):
return datetime.strptime( date, DATE_IN_FMT )
DATE_MIN = str2date('2010-01-01')
DATE_MIN = str2date('2013-01-01')
# SLetort : I used this function to set the default
# because metrics function have all their params, possibly set to None
......@@ -48,6 +50,15 @@ def get_params(from_, to, step, d_defaults):
return ( d_return[x] for x in ('from', 'to', 'step' ))
def __api_dict(from_, to, step, l_records ):
"""from_ and to are datetime.datetime object."""
return {
'data': l_records,
'from': fmt_date(from_),
'to' : fmt_date(to),
'step' : step,
}
def nb_jobs_per_user(app_id, from_=None, to=None, step=None):
"""compute for the webapp app_id, for each user the number of jobs "updated" (created,launched,terminated)
per step period between [from\_ ; to[.
......@@ -65,7 +76,6 @@ def nb_jobs_per_user(app_id, from_=None, to=None, step=None):
and 'data' which contains a list of dictionnaries {user:, uname:, time_period:, n:}
:rtype: dictionnary
"""
d_defaults = { 'from': DATE_MIN, 'to': timezone.now(), 'step': 'month' }
from_,to,step = get_params(from_, to, step, d_defaults)
msg = "provided from '{}' to '{}', step of '{}'"\
......@@ -80,12 +90,9 @@ def nb_jobs_per_user(app_id, from_=None, to=None, step=None):
# SLETORT: There should be a "django" way of doing this !
for d_res in res:
d_res['uname'] = d_res.pop('user__username')
d_res['time_period'] = fmt_date( d_res.pop('time_period') )
return {
'data': list(res),
'from': fmt_date(from_),
'to' : fmt_date(to),
}
return __api_dict( from_, to, step, list(res) );
def nb_jobs_per_state(app_id, from_=None, to=None, step=None):
"""compute for the webapp app_id, for each state (result) the number of jobs "updated" (created,launched,terminated)
......@@ -118,11 +125,7 @@ def nb_jobs_per_state(app_id, from_=None, to=None, step=None):
for d_res in res:
d_res['result'] = Job.JOB_RESULT_CHOICES[d_res['result']][1]
return {
'data': list(res),
'from': fmt_date(from_),
'to' : fmt_date(to),
}
return __api_dict( from_, to, step, list(res) );
def nb_jobs_launched(app_id, from_=None, to=None, step=None):
"""compute for the webapp app_id, the number of jobs created
......@@ -152,11 +155,8 @@ def nb_jobs_launched(app_id, from_=None, to=None, step=None):
.annotate(time_period=Trunc('created_at', step)) \
.values('time_period') \
.annotate(n=Count('id'))
return {
'data': list(res),
'from': fmt_date(from_),
'to' : fmt_date(to),
}
return __api_dict( from_, to, step, list(res) );
# ======================================
d_actions = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment