Skip to content

Commit

Permalink
feat: save FunctionProfilingStep when event is received
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Barthés <[email protected]>
  • Loading branch information
guilhem-barthes committed Apr 11, 2024
1 parent d2dfcc3 commit 0a9839b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions backend/api/events/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from api.models import DataManager
from api.models import DataSample
from api.models import Function
from api.models import FunctionProfilingStep
from api.models import Model
from api.serializers import ChannelOrganizationSerializer
from api.serializers import ComputePlanSerializer
Expand Down Expand Up @@ -430,6 +431,13 @@ def _create_failure_report(data: dict) -> None:
logger.debug("FailureReport already exists", asset_key=data["asset_key"])


def _on_create_profiling_step_event(data: dict) -> None:
profiling_step = FunctionProfilingStep(
function_key=data["asset_key"], duration=data["profiling_step"]["duration"], step=data["profiling_step"]["step"]
)
profiling_step.save()


EVENT_CALLBACKS = {
common_pb2.ASSET_COMPUTE_PLAN: {
event_pb2.EVENT_ASSET_CREATED: _on_create_computeplan_event,
Expand Down Expand Up @@ -467,6 +475,9 @@ def _create_failure_report(data: dict) -> None:
common_pb2.ASSET_FAILURE_REPORT: {
event_pb2.EVENT_ASSET_CREATED: _on_create_failure_report_event,
},
common_pb2.ASSET_PROFILING_STEP: {
event_pb2.EVENT_ASSET_CREATED: _on_create_profiling_step_event,
},
}


Expand Down
43 changes: 43 additions & 0 deletions backend/api/migrations/0060_functionprofilingstep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.10 on 2024-04-11 06:55

import django.db.models.deletion
from django.db import migrations
from django.db import models

import orchestrator.resources


class Migration(migrations.Migration):
dependencies = [
("api", "0059_remove_datamanager_type"),
]

operations = [
migrations.CreateModel(
name="FunctionProfilingStep",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"step",
models.CharField(
choices=[
("BUILD_IMAGE", orchestrator.resources.FunctionProfilingStep["BUILD_IMAGE"]),
("SAVE_FUNCTION", orchestrator.resources.FunctionProfilingStep["SAVE_FUNCTION"]),
],
max_length=100,
),
),
("duration", models.DurationField()),
(
"function",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="profiling_steps", to="api.function"
),
),
],
options={
"ordering": ["step"],
"unique_together": {("function", "step")},
},
),
]
2 changes: 2 additions & 0 deletions backend/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from .model import Model
from .organization import ChannelOrganization
from .performance import Performance
from .task_profiling import FunctionProfilingStep
from .task_profiling import ProfilingStep
from .task_profiling import TaskProfiling

__all__ = [
"Function",
"FunctionInput",
"FunctionOutput",
"FunctionProfilingStep",
"ComputePlan",
"ComputeTask",
"ComputeTaskOutput",
Expand Down
16 changes: 15 additions & 1 deletion backend/api/models/task_profiling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.db import models

import orchestrator


class ProfilingStep(models.Model):
"""A profiling step"""
"""A task profiling step"""

compute_task_profile = models.ForeignKey(
"TaskProfiling", on_delete=models.CASCADE, related_name="execution_rundown"
Expand All @@ -25,3 +27,15 @@ class TaskProfiling(models.Model):

class Meta:
ordering = ["creation_date"]


class FunctionProfilingStep(models.Model):
"""A function profiling step"""

function = models.ForeignKey("Function", on_delete=models.CASCADE, related_name="profiling_steps")
step = models.CharField(max_length=100, choices=orchestrator.FunctionProfilingStep.to_choices())
duration = models.DurationField()

class Meta:
unique_together = (("function", "step"),)
ordering = ["step"]
2 changes: 2 additions & 0 deletions backend/orchestrator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .resources import Function
from .resources import FunctionInput
from .resources import FunctionOutput
from .resources import FunctionProfilingStep
from .resources import FunctionStatus
from .resources import InvalidInputAsset
from .resources import Model
Expand All @@ -40,6 +41,7 @@
"OrcError",
"FunctionInput",
"FunctionOutput",
"FunctionProfilingStep",
"FunctionStatus",
"get_orchestrator_client",
)

0 comments on commit 0a9839b

Please sign in to comment.