Skip to content

375 slice metrics for portal to display #377

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

Merged
merged 11 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions fabric_cf/actor/core/apis/abc_actor_management_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,48 @@ def get_slices(self, *, slice_id: ID, caller: AuthToken, slice_name: str = None,
@return returns list of slices
"""

@abstractmethod
def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
"""
Add or update metrics

@param project_id project id
@param oidc_sub oidc sub
@param slice_count slice_count

@return true or false

@throws Exception in case of error
"""

@abstractmethod
def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
"""
Get metrics

@param project_id project id
@param oidc_sub oidc sub
@param excluded_projects excluded_projects

@return list of metric information

@throws Exception in case of error
"""

def get_slice_count(self, *, caller: AuthToken, email: str = None, states: List[int] = None,
project: str = None, user_id: str = None, excluded_projects: List[str] = None) -> int:
"""
Obtains Slice count matching the filter criteria.

@param email email
@param project project id
@param states slice states
@param caller caller
@param user_id user_id
@param excluded_projects excluded_projects
@return returns number of slices
"""

def remove_slice(self, *, slice_id: ID, caller: AuthToken) -> ResultAvro:
"""
Removes the specified slice
Expand Down
44 changes: 44 additions & 0 deletions fabric_cf/actor/core/apis/abc_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ def get_slices(self, *, slice_id: ID = None, slice_name: str = None, project_id:
@throws Exception in case of error
"""

@abstractmethod
def get_slice_count(self, *, project_id: str = None, email: str = None, states: list[int] = None,
oidc_sub: str = None, slc_type: List[SliceTypes] = None,
excluded_projects: List[str] = None) -> int:
"""
Retrieves the slices count.

@param project_id project id
@param email email
@param states states
@param oidc_sub oidc sub
@param slc_type slice type
@param excluded_projects excluded_projects

@return number of slices matching the filter criteria

@throws Exception in case of error
"""

@abstractmethod
def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
"""
Add or Update Metrics

@param project_id project id
@param oidc_sub oidc sub
@param slice_count slice_count

@return true or false

@throws Exception in case of error
"""

@abstractmethod
def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
"""
Get Metrics
@param project_id: project id
@param oidc_sub: user id
@param excluded_projects: list of project ids to exclude

@return list of metrics
"""

@abstractmethod
def initialize(self):
"""
Expand Down
41 changes: 41 additions & 0 deletions fabric_cf/actor/core/apis/abc_mgmt_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ def get_slices(self, *, slice_id: ID = None, slice_name: str = None, email: str
@return returns list of slices
"""

def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
"""
Add or update metrics

@param project_id project id
@param oidc_sub oidc sub
@param slice_count slice_count

@return true or false

@throws Exception in case of error
"""
raise NotImplementedError

def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
"""
Get metrics

@param project_id project id
@param oidc_sub oidc sub
@param excluded_projects excluded_projects

@return list of metric information

@throws Exception in case of error
"""
raise NotImplementedError

def get_slice_count(self, *, email: str = None, project: str = None, states: List[int] = None,
user_id: str = None, excluded_projects: List[str] = None) -> int:
"""
Obtains slice count.
@param email email
@param project project id
@param states slice states
@param user_id user_id
@param excluded_projects excluded_projects
@return returns list of slices
"""
raise NotImplementedError

@abstractmethod
def add_slice(self, *, slice_obj: SliceAvro) -> ID:
"""
Expand Down
1 change: 1 addition & 0 deletions fabric_cf/actor/core/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Constants:
STATE_FILE_LOCATION = '/tmp/fabric_actor.tmp'
MAINT_PROJECT_ID = 'maint.project.id'
INFRASTRUCTURE_PROJECT_ID = "infrastructure.project.id"
TOTAL_SLICE_COUNT_SEED = "total_slice_count_seed"

ELASTIC_TIME = "request.elasticTime"
ELASTIC_SIZE = "request.elasticSize"
Expand Down
20 changes: 20 additions & 0 deletions fabric_cf/actor/core/manage/actor_management_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ def get_slices(self, *, slice_id: ID, caller: AuthToken, slice_name: str = None,
result.status = ManagementObject.set_exception_details(result=result.status, e=e)
return result

def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
try:
return self.db.get_metrics(project_id=project_id, oidc_sub=oidc_sub, excluded_projects=excluded_projects)
except Exception as e:
self.logger.error("get_metrics {}".format(e))

def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
try:
return self.db.increment_metrics(project_id=project_id, oidc_sub=oidc_sub, slice_count=slice_count)
except Exception as e:
self.logger.error("add_or_update_metrics {}".format(e))

def get_slice_count(self, *, caller: AuthToken, email: str = None, states: List[int] = None,
project: str = None, user_id: str = None, excluded_projects: List[str] = None) -> int:
try:
return self.db.get_slice_count(email=email, states=states, project_id=project, oidc_sub=user_id)
except Exception as e:
self.logger.error("get_slice_count {}".format(e))
return -1

def add_slice(self, *, slice_obj: SliceAvro, caller: AuthToken) -> ResultStringAvro:
result = ResultStringAvro()
result.status = ResultAvro()
Expand Down
26 changes: 25 additions & 1 deletion fabric_cf/actor/core/manage/local/local_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ def get_slices(self, *, slice_id: ID = None, slice_name: str = None, email: str

return None

def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
try:
return self.manager.increment_metrics(project_id=project_id, oidc_sub=oidc_sub, slice_count=slice_count)
except Exception as e:
self.on_exception(e=e, traceback_str=traceback.format_exc())
return False

def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
try:
return self.manager.get_metrics(project_id=project_id, oidc_sub=oidc_sub,
excluded_projects=excluded_projects)
except Exception as e:
self.on_exception(e=e, traceback_str=traceback.format_exc())

def get_slice_count(self, *, email: str = None, project: str = None, states: List[int] = None,
user_id: str = None, excluded_projects: List[str] = None) -> int:
try:
return self.manager.get_slice_count(caller=self.auth, states=states, email=email, project=project,
user_id=user_id, excluded_projects=excluded_projects)
except Exception as e:
self.on_exception(e=e, traceback_str=traceback.format_exc())

return -1

def remove_slice(self, *, slice_id: ID) -> bool:
self.clear_last()
try:
Expand Down Expand Up @@ -307,4 +331,4 @@ def get_poas(self, *, states: List[int] = None, slice_id: ID = None, rid: ID = N
return result.poas

except Exception as e:
self.on_exception(e=e, traceback_str=traceback.format_exc())
self.on_exception(e=e, traceback_str=traceback.format_exc())
40 changes: 40 additions & 0 deletions fabric_cf/actor/core/plugins/db/actor_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,46 @@ def get_slices(self, *, slice_id: ID = None, slice_name: str = None, project_id:
self.lock.release()
return result

def increment_metrics(self, *, project_id: str, oidc_sub: str, slice_count: int = 1) -> bool:
try:
self.lock.acquire()
self.db.increment_metrics(project_id=project_id, user_id=oidc_sub, slice_count=slice_count)
return True
except Exception as e:
self.logger.error(e)
self.logger.error(traceback.format_exc())
finally:
if self.lock.locked():
self.lock.release()
return False

def get_metrics(self, *, project_id: str, oidc_sub: str, excluded_projects: List[str] = None) -> list:
try:
return self.db.get_metrics(project_id=project_id, user_id=oidc_sub, excluded_projects=excluded_projects)
except Exception as e:
self.logger.error(e)
self.logger.error(traceback.format_exc())
finally:
if self.lock.locked():
self.lock.release()

def get_slice_count(self, *, project_id: str = None, email: str = None, states: list[int] = None,
oidc_sub: str = None, slc_type: List[SliceTypes] = None,
excluded_projects: List[str] = None) -> int:
try:
slice_type = [SliceTypes.ClientSlice.value]
if slc_type is not None:
slice_type = [x.value for x in slc_type]
return self.db.get_slice_count(project_id=project_id, email=email, states=states, oidc_sub=oidc_sub,
slc_type=slice_type, excluded_projects=excluded_projects)
except Exception as e:
self.logger.error(e)
self.logger.error(traceback.format_exc())
finally:
if self.lock.locked():
self.lock.release()
return -1

def add_reservation(self, *, reservation: ABCReservationMixin):
try:
#self.lock.acquire()
Expand Down
12 changes: 12 additions & 0 deletions fabric_cf/actor/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# Author: Komal Thareja ([email protected])

from sqlalchemy import JSON, ForeignKey, LargeBinary, Index, TIMESTAMP
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, String, Integer, Sequence
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -92,6 +93,17 @@ class Miscellaneous(Base):
properties = Column(JSON)


class Metrics(Base):
"""
Represents Metrics Database Table
"""
__tablename__ = 'Metrics'
m_id = Column(Integer, Sequence('m_id', start=1, increment=1), autoincrement=True, primary_key=True)
user_id = Column(String, nullable=False, index=True)
project_id = Column(String, nullable=False, index=True)
slice_count = Column(Integer, nullable=False)


class Proxies(Base):
"""
Represents Proxies Database Table
Expand Down
Loading