Skip to content
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

Add schemas for hardware related metrics #75

Merged
merged 2 commits into from
Apr 8, 2022
Merged
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
40 changes: 35 additions & 5 deletions pipeline/schemas/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
from typing import List


class MetricsBucket(BaseModel):
class RunHardwareMetric(BaseModel):
resource_type: str
total_percentage: float
run_count: int
average_runtime: int


class ProjectHardwareMetric(BaseModel):
project_id: str
project_name: str
project_usage: List[RunHardwareMetric]


class HardwareMetric(BaseModel):
start: datetime
end: datetime
projects: List[ProjectHardwareMetric]
account_usage: List[RunHardwareMetric]


class RunMetricsBucket(BaseModel):
"""
Type of metadata of a specific bucket.

Expand Down Expand Up @@ -39,9 +59,9 @@ class RunMetricsGet(BaseModel):
start: datetime
end: datetime
bucket_count: int
metrics_buckets: List[MetricsBucket]
overall_bucket: MetricsBucket
preceding_bucket: MetricsBucket
metrics_buckets: List[RunMetricsBucket]
overall_bucket: RunMetricsBucket
preceding_bucket: RunMetricsBucket


class MetricsQuery(BaseModel):
Expand All @@ -50,11 +70,21 @@ class MetricsQuery(BaseModel):

start: start timestamp of the time range
end: end timestamp of the time range
bucket_count: number of buckets to divide the time range into
"""

start: datetime = Field(
default_factory=lambda: datetime.utcnow() - timedelta(hours=24)
)
end: datetime = Field(default_factory=datetime.utcnow)


class RunMetricsQuery(MetricsQuery):
"""
Query parameters for run metrics requests.

start: start timestamp of the time range
end: end timestamp of the time range
bucket_count: number of buckets to divide the time range into
"""

bucket_count: int = 100