Skip to content

runtime usage service#960

Open
raphael-goetz wants to merge 9 commits into
mainfrom
#779-runtime-usage-service
Open

runtime usage service#960
raphael-goetz wants to merge 9 commits into
mainfrom
#779-runtime-usage-service

Conversation

@raphael-goetz
Copy link
Copy Markdown
Member

Resolves: #779

@raphael-goetz raphael-goetz requested a review from Taucher2003 May 12, 2026 18:52
@raphael-goetz raphael-goetz marked this pull request as ready for review May 12, 2026 18:52
Copilot AI review requested due to automatic review settings May 12, 2026 18:52
@raphael-goetz raphael-goetz self-assigned this May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements a “runtime usage” pipeline end-to-end: persists daily aggregated runtime usage per flow/namespace, exposes it via GraphQL connections (with date filtering), and accepts updates via a new gRPC RuntimeUsage service.

Changes:

  • Add daily_runtime_usages persistence (migration, model, associations) and a gRPC update service/handler to record/increment usage.
  • Expose daily runtime usage via GraphQL (Namespace.dailyRuntimeUsages, Flow.dailyRuntimeUsages) plus a Date scalar and new GraphQL type.
  • Add request/service/type specs and generate GraphQL docs for the new schema surface and error code.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
spec/services/runtimes/grpc/runtime_usage_update_service_spec.rb Unit coverage for usage update service behavior and validation.
spec/requests/grpc/sagittarius/runtime_usage_service_spec.rb gRPC request spec for RuntimeUsageService update behavior.
spec/requests/graphql/query/namespace_runtime_usages_query_spec.rb GraphQL query coverage for namespace-level usage retrieval and filters.
spec/requests/graphql/query/flow_runtime_usages_query_spec.rb GraphQL query coverage for flow-level usage retrieval and date filtering.
spec/graphql/types/namespace_type_spec.rb Updates Namespace type field expectations to include dailyRuntimeUsages.
spec/graphql/types/flow_type_spec.rb Adds Flow type spec including dailyRuntimeUsages.
spec/graphql/types/date_type_spec.rb Adds tests for the new Types::DateType scalar coercion.
spec/graphql/types/daily_runtime_usage_type_spec.rb Adds GraphQL type coverage for DailyRuntimeUsage.
spec/factories/daily_runtime_usages.rb Factory for DailyRuntimeUsage records.
extensions/cloud/spec/graphql/types/cloud/types/namespace_type_spec.rb Updates Cloud extension Namespace type field expectations.
docs/graphql/scalar/float.md Adds/records Float scalar documentation entry.
docs/graphql/scalar/date.md Adds Date scalar documentation entry.
docs/graphql/scalar/dailyruntimeusageid.md Adds scalar doc entry for DailyRuntimeUsageID.
docs/graphql/object/namespace.md Documents Namespace.dailyRuntimeUsages field and arguments.
docs/graphql/object/flow.md Documents Flow.dailyRuntimeUsages field and arguments.
docs/graphql/object/dailyruntimeusageedge.md Adds connection edge documentation for daily runtime usage.
docs/graphql/object/dailyruntimeusageconnection.md Adds connection documentation for daily runtime usage.
docs/graphql/object/dailyruntimeusage.md Adds object documentation for daily runtime usage.
docs/graphql/enum/errorcodeenum.md Documents the new INVALID_RUNTIME_USAGE error code.
db/structure.sql Reflects the new daily_runtime_usages table and indexes.
db/schema_migrations/20260510081622 Adds checksum file for the new migration per repo convention.
db/migrate/20260510081622_create_daily_runtime_usage.rb Migration creating daily_runtime_usages table and FK behavior.
app/services/runtimes/grpc/runtime_usage_update_service.rb Implements the transactional upsert/increment logic for daily usage.
app/services/error_code.rb Registers invalid_runtime_usage error code.
app/models/namespace.rb Adds has_many :daily_runtime_usages association.
app/models/flow.rb Adds has_many :daily_runtime_usages association.
app/models/daily_runtime_usage.rb New model for daily runtime usage with validations and relations.
app/grpc/runtime_usage_handler.rb New gRPC handler wiring RuntimeUsageService update to the new service.
app/graphql/types/namespace_type.rb Adds daily_runtime_usages connection field and resolver with filters.
app/graphql/types/namespace_project_type.rb Fixes project flow lookup to use GlobalID model_id with find_by.
app/graphql/types/flow_type.rb Adds daily_runtime_usages connection field and resolver with date filters.
app/graphql/types/date_type.rb Adds custom Date scalar (ISO8601) for GraphQL.
app/graphql/types/daily_runtime_usage_type.rb Adds GraphQL object type for DailyRuntimeUsage with auth subject.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/migrate/20260510081622_create_daily_runtime_usage.rb
t.references :namespace, null: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }
t.date :day, null: false
t.decimal :usage, null: false, default: 0

Comment on lines +32 to +44
def update_usage(usage)
flow = Flow.includes(project: :namespace).find_by(id: usage_attribute(usage, :flow_id))
return ServiceResponse.error(message: 'Flow not found', error_code: :flow_not_found) if flow.nil?

day = usage_day(usage)
amount = usage_amount(usage)
return invalid_usage_error('Usage amount must be greater than zero') unless amount&.positive?

db_usage = DailyRuntimeUsage.find_or_initialize_by(
namespace: flow.project.namespace,
flow: flow,
day: day
)
Comment on lines +40 to +52
db_usage = DailyRuntimeUsage.find_or_initialize_by(
namespace: flow.project.namespace,
flow: flow,
day: day
)

return increment_usage(db_usage, amount) unless db_usage.persisted?

db_usage.with_lock { increment_usage(db_usage, amount) }
rescue ActiveRecord::RecordInvalid => e
invalid_usage_error(e.record.errors)
rescue ActiveRecord::RecordNotUnique
retry
Comment on lines +7 to +13
def update(request, _call)
response = Runtimes::Grpc::RuntimeUsageUpdateService.new(usages: request.runtime_usage).execute

logger.debug("RuntimeUsageHandler#update response: #{response.inspect}")

Tucana::Sagittarius::RuntimeUsageResponse.new(success: response.success?)
end
@github-actions
Copy link
Copy Markdown

GitLab Pipeline Action

General information

Link to pipeline: https://gitlab.com/code0-tech/development/sagittarius/-/pipelines/2520165948

Status: Failed
Duration: 6 minutes

Job summaries

rspec: [cloud]

Coverage report available at https://code0-tech.gitlab.io/-/development/sagittarius/-/jobs/14336380692/artifacts/tmp/coverage/index.html
Test summary available at https://gitlab.com/code0-tech/development/sagittarius/-/pipelines/2520165948/test_report
Finished in 26.74 seconds (files took 11.37 seconds to load)
1402 examples, 0 failures
Line Coverage: 92.49% (4572 / 4943)
[TEST PROF INFO] Time spent in factories: 00:14.603 (43.37% of total time)

rspec: [ee]

Coverage report available at https://code0-tech.gitlab.io/-/development/sagittarius/-/jobs/14336380691/artifacts/tmp/coverage/index.html
Test summary available at https://gitlab.com/code0-tech/development/sagittarius/-/pipelines/2520165948/test_report
Finished in 22.86 seconds (files took 12.58 seconds to load)
1380 examples, 0 failures
Line Coverage: 92.86% (4472 / 4816)
[TEST PROF INFO] Time spent in factories: 00:12.262 (40.67% of total time)

rspec: [ce]

Coverage report available at https://code0-tech.gitlab.io/-/development/sagittarius/-/jobs/14336380690/artifacts/tmp/coverage/index.html
Test summary available at https://gitlab.com/code0-tech/development/sagittarius/-/pipelines/2520165948/test_report
Finished in 22.79 seconds (files took 12.19 seconds to load)
1330 examples, 0 failures
Line Coverage: 92.38% (4301 / 4656)
[TEST PROF INFO] Time spent in factories: 00:12.153 (41.89% of total time)

rubocop

787 files inspected, no offenses detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement runtime usage service

2 participants