Skip to content
Draft
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
3 changes: 3 additions & 0 deletions app/graphql/types/flow_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class FlowType < Types::BaseObject
field :input_type, Types::DataTypeType,
null: true,
description: 'The input data type of the flow'
field :last_execution_duration, Integer,
null: true,
description: 'The duration of the last execution of the flow in nanoseconds'
field :return_type, Types::DataTypeType,
null: true,
description: 'The return data type of the flow'
Expand Down
27 changes: 27 additions & 0 deletions app/grpc/runtime_usage_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

class RuntimeUsageHandler < Tucana::Sagittarius::RuntimeUsageService::Service
include GrpcHandler
include Code0::ZeroTrack::Loggable

def update(request, _call)
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])

request.runtime_usage.each do |usage_info|
flow = Flow.find_by(id: usage_info.flow_id)

if flow.nil? || flow.project.primary_runtime != current_runtime
logger.error(
message: 'Flow not found or does not belong to current runtime',
runtime_id: current_runtime.id,
flow_id: usage_info.flow_id
)
return Tucana::Sagittarius::RuntimeUsageResponse.new(success: false)
end
flow.last_execution_duration = usage_info.duration.to_i
flow.save!
end

Tucana::Sagittarius::RuntimeUsageeResponse.new(success: true)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddLastExecutionDurationToFlows < Code0::ZeroTrack::Database::Migration[1.0]
def change
add_column :flows, :last_execution_duration, :bigint, null: true, default: nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single field is not going to work for our requirements. We need to store each execution duration (well, more like a daily aggregate of all executions that day) and can't store only the last execution duration. This is going to be used for usage quotas, so we need to know how much time was used for a given time span.

We definitely also need to store the time in relation to the runtime because not every runtime is subject to usage quotas. Not sure if we need granularity for each flow or if we should limit the granularity to projects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should store every execution time of every flow? Or just in the last 14 days or so?

end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20251217140333
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bc5cbc74c587f21ba1d98a76876dfd3d5e91bc2e4ef2eccd8d85129f5f740fb3
3 changes: 2 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ CREATE TABLE flows (
starting_node_id bigint,
name text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
updated_at timestamp with time zone NOT NULL,
last_execution_duration bigint
);

CREATE SEQUENCE flows_id_seq
Expand Down
1 change: 1 addition & 0 deletions docs/graphql/object/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Represents a flow
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created |
| `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow |
| `inputType` | [`DataType`](../object/datatype.md) | The input data type of the flow |
| `lastExecutionDuration` | [`Int`](../scalar/int.md) | The duration of the last execution of the flow in nanoseconds |
| `name` | [`String!`](../scalar/string.md) | Name of the flow |
| `nodes` | [`NodeFunctionConnection!`](../object/nodefunctionconnection.md) | Nodes of the flow |
| `returnType` | [`DataType`](../object/datatype.md) | The return data type of the flow |
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/types/flow_type_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
input_type
return_type
flow_type_settings
last_execution_duration
names
display_messages
aliases
Expand Down