-
Notifications
You must be signed in to change notification settings - Fork 371
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
feat: calculate admins traffic usage #935
base: dev
Are you sure you want to change the base?
Conversation
desc: show admin traffic usage in admin panel not system traffic usage
desc: show admin traffic usage in admin panel not system traffic usage
This reverts commit ea29eb0.
i had same idea for this part |
yes node usages still showing whole system traffic , i'll fix it |
Non sudo admins can't see node usage |
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.
great job but your code need some small changes
app/views/node.py
Outdated
usages = crud.get_nodes_usage(db, start_date, end_date) | ||
if not admin.is_sudo: | ||
# get non sudo admin usage | ||
dbadmin: Union[Admin, None] = crud.get_admin(db, admin.username) |
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.
/api/nodes/usage
should remain same as before
we already have admin object and we don't need to get it again
also sudo admin should be able to see other admins usages
for this , is better to have separated function
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.
we should have different API endpoint for non sudo admin node usage ?
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.
different api to see admin usage by sudo admin
app/jobs/record_usages.py
Outdated
@@ -161,6 +219,7 @@ def record_user_usages(): | |||
|
|||
for node_id, params in api_params.items(): | |||
record_user_stats(params, node_id, usage_coefficient[node_id]) | |||
record_admin_stats(params, node_id, usage_coefficient[node_id]) |
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.
separate record_admin_stats and record_user_stats , they both use DISABLE_RECORDING_NODE_USAGE variable
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 think its a general variable it is also used in record_node_usages()
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.
yeap it is and it's better to become separated for each one
app/jobs/record_usages.py
Outdated
@@ -76,6 +76,64 @@ def record_user_stats(params: list, node_id: Union[int, None], | |||
NodeUserUsage.created_at == created_at)) | |||
safe_execute(db, stmt, params) | |||
|
|||
def record_admin_stats(params: list, node_id: Union[int, None], | |||
consumption_factor: int = 1): |
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.
it's usage_coefficient not consumption_factor
In my opinion, the table user_usage_logs with the new columns used_traffic_on_delete and admin_id can be used for More details on this issue: |
یه حرکتی بزنید |
بررسی کردم ایشو رو بنظر اوکیه احتمالا برای محاسبه مصرف نود ادمین هم بشه کار مشابه روی جدول node_user_uasage انجام داد و اینکه تست کردید جواب نمیداد چون مرج نشده pr |
ممنون امید جان، ۱.فیلد های admin_id و used_traffic_on_delete و deleted_user_id رو به تیبل node_user_usages اضافه کنیم ۲.فیلد admin_id به تیبل node_user_usages اضافه بشه و یه تیبل جدید node_user_usage_logs اضافه بشه که وقتی کاربر پاک شد اطلاعات node_user_usages مربوط به کاربر در یک ریکورد اونجا ذخیره بشه که میتونه دارای node_id و used_traffic و user_id و deleted_at و admin_id باشه ۳.فیلد admin_id به تیبل node_user_usages اضافه بشه و cascade رو از ریلیشن تیبل node_user_usages با تیبل users برداشته بشه یعنی cascade رو از اینجا پاک کنیم Line 41 in 16ed7ec
و موقع گرفتن اطلاعات مربوط به مصرف کاربران ادمین از نود اگر ادمین غیر sudo هست میتوان بر اساس ایدی ادمین غیر sudo اطلاعات لازم رو دریافت کرد و نمایش داد. اگر کمکی از دست من برمیاد بگین |
یه حرکتی بزنید |
درسته |
ممنون امید جان، بازم شما یه حرکتی زدی تشکر میکنم. |
نه |
ممنون امید جان، پس چرا مرج نمیشه؟ |
desc: show admin traffic usage in admin panel not system traffic usage for non sudoers admins