diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-14 12:14:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-14 12:14:36 +0300 |
commit | 7bd8f9822b05eb2e8c8279678e38e7513c3612f6 (patch) | |
tree | ab85f35234e66b99a1d3400ffb4ee529a0011d6f /app/models/clusters | |
parent | d11616c828fa76b0fea100872b59d904560e6570 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/agent.rb | 8 | ||||
-rw-r--r-- | app/models/clusters/agent_token.rb | 5 | ||||
-rw-r--r-- | app/models/clusters/agents/activity_event.rb | 2 |
3 files changed, 13 insertions, 2 deletions
diff --git a/app/models/clusters/agent.rb b/app/models/clusters/agent.rb index 8705c0fbec4..79fc2b58237 100644 --- a/app/models/clusters/agent.rb +++ b/app/models/clusters/agent.rb @@ -5,6 +5,7 @@ module Clusters self.table_name = 'cluster_agents' INACTIVE_AFTER = 1.hour.freeze + ACTIVITY_EVENT_LIMIT = 200 belongs_to :created_by_user, class_name: 'User', optional: true belongs_to :project, class_name: '::Project' # Otherwise, it will load ::Clusters::Project @@ -39,5 +40,12 @@ module Clusters def connected? agent_tokens.active.where("last_used_at > ?", INACTIVE_AFTER.ago).exists? end + + def activity_event_deletion_cutoff + # Order is defined by the association + activity_events + .offset(ACTIVITY_EVENT_LIMIT - 1) + .pick(:recorded_at) + end end end diff --git a/app/models/clusters/agent_token.rb b/app/models/clusters/agent_token.rb index bcef6b6ecc8..acf13c55ba3 100644 --- a/app/models/clusters/agent_token.rb +++ b/app/models/clusters/agent_token.rb @@ -56,12 +56,13 @@ module Clusters end def log_activity_event!(recorded_at) - agent.activity_events.create!( + Clusters::Agents::CreateActivityEventService.new( # rubocop: disable CodeReuse/ServiceClass + agent, kind: :agent_connected, level: :info, recorded_at: recorded_at, agent_token: self - ) + ).execute end end end diff --git a/app/models/clusters/agents/activity_event.rb b/app/models/clusters/agents/activity_event.rb index 5d9c885c923..ec2bbfde339 100644 --- a/app/models/clusters/agents/activity_event.rb +++ b/app/models/clusters/agents/activity_event.rb @@ -3,6 +3,7 @@ module Clusters module Agents class ActivityEvent < ApplicationRecord + include EachBatch include NullifyIfBlank self.table_name = 'agent_activity_events' @@ -12,6 +13,7 @@ module Clusters belongs_to :agent_token, class_name: 'Clusters::AgentToken' scope :in_timeline_order, -> { order(recorded_at: :desc, id: :desc) } + scope :recorded_before, -> (cutoff) { where('recorded_at < ?', cutoff) } validates :recorded_at, :kind, :level, presence: true |