style: add self to make sure python isnt confused and format code

This commit is contained in:
nhnn 2024-07-15 17:00:36 +03:00
parent a24e36fa01
commit 2797b0b331
2 changed files with 15 additions and 6 deletions

View file

@ -7,18 +7,27 @@ from selfprivacy_api.utils.prometheus import PrometheusQueries, PrometheusQueryR
class Monitoring: class Monitoring:
@strawberry.field @strawberry.field
def disk_usage( def disk_usage(
start: Optional[int] = None, end: Optional[int] = None, step: int = 60 self,
start: Optional[int] = None,
end: Optional[int] = None,
step: int = 60,
) -> PrometheusQueryResult: ) -> PrometheusQueryResult:
return PrometheusQueries.disk_usage(start, end, step) return PrometheusQueries.disk_usage(start, end, step)
@strawberry.field @strawberry.field
def memory_usage( def memory_usage(
start: Optional[int] = None, end: Optional[int] = None, step: int = 60 self,
start: Optional[int] = None,
end: Optional[int] = None,
step: int = 60,
) -> PrometheusQueryResult: ) -> PrometheusQueryResult:
return PrometheusQueries.memory_usage(start, end, step) return PrometheusQueries.memory_usage(start, end, step)
@strawberry.field @strawberry.field
def cpu_usage( def cpu_usage(
start: Optional[int] = None, end: Optional[int] = None, step: int = 60 self,
start: Optional[int] = None,
end: Optional[int] = None,
step: int = 60,
) -> PrometheusQueryResult: ) -> PrometheusQueryResult:
return PrometheusQueries.cpu_usage(start, end, step) return PrometheusQueries.cpu_usage(start, end, step)

View file

@ -36,11 +36,11 @@ class PrometheusQueries:
if response.status_code != 200: if response.status_code != 200:
raise Exception("Prometheus returned unexpected HTTP status code") raise Exception("Prometheus returned unexpected HTTP status code")
json = response.json() json = response.json()
if json['status'] != 'success': if json["status"] != "success":
raise Exception("Prometheus returned unexpected status") raise Exception("Prometheus returned unexpected status")
result = json['data'] result = json["data"]
return PrometheusQueryResult( return PrometheusQueryResult(
result_type=result['resultType'], result=result['result'] result_type=result["resultType"], result=result["result"]
) )
except Exception as error: except Exception as error:
raise Exception("Prometheus request failed! " + str(error)) raise Exception("Prometheus request failed! " + str(error))