Skip to content

Commit

Permalink
Merge pull request #4899 from mdeniz/metrics_for_project_package_and_…
Browse files Browse the repository at this point in the history
…users

Metrics for projects, packages and users
  • Loading branch information
bgeuken committed Apr 24, 2018
2 parents c744abc + 13299d3 commit 74688df
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
## AMQP queue name
queue = ""
## Binding Key
binding_key = "#"
binding_key = "opensuse.obs.metrics"

## Maximum number of messages server should give to the worker.
prefetch_count = 50
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/controllers/webui/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def update

def delete
other_user = User.find_by(login: user_params[:login])
other_user.update_attributes(state: 'deleted')
if other_user.save
if other_user.delete
flash[:notice] = "Marked user '#{other_user}' as deleted."
else
flash[:error] = "Marking user '#{other_user}' as deleted failed: #{other_user.errors.full_messages.to_sentence}"
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/event/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _roles(role, project, package = nil)

def send_to_bus
RabbitmqBus.send_to_bus(self.class.message_bus_routing_key, self[:payload])
RabbitmqBus.send_to_bus("metrics.#{self.class.message_bus_routing_key}", to_metric) if metric_fields.present?
RabbitmqBus.send_to_bus('metrics', to_metric) if metric_fields.present?
end

private
Expand Down
10 changes: 10 additions & 0 deletions src/api/app/models/event/create_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def self.message_bus_routing_key
def subject
"New Package #{payload['project']}/#{payload['package']}"
end

private

def metric_tags
{ home: ::Project.home?(payload['project']) }
end

def metric_fields
{ value: 1 }
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions src/api/app/models/event/create_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def self.message_bus_routing_key
def subject
"New Project #{payload['project']}"
end

private

def metric_tags
{ home: ::Project.home?(payload['project']) }
end

def metric_fields
{ value: 1 }
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions src/api/app/models/event/delete_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ def set_payload(attribs, keys)
attribs['comment'] = attribs['comment'][0..800] if attribs['comment'].present?
super(attribs, keys)
end

private

def metric_tags
{ home: ::Project.home?(payload['project']) }
end

def metric_fields
{ value: 1 }
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions src/api/app/models/event/delete_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ class DeleteProject < Base
def self.message_bus_routing_key
'project.delete'
end

private

def metric_tags
{ home: ::Project.home?(payload['project']) }
end

def metric_fields
{ value: 1 }
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def autocomplete(search)
validate :valid_name
validates :kind, inclusion: { in: ['standard', 'maintenance', 'maintenance_incident', 'maintenance_release'] }

def self.home?(name)
name.start_with?('home:')
end

def self.deleted?(project_name)
return false if find_by_name(project_name)

Expand Down
18 changes: 16 additions & 2 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ class User < ApplicationRecord
validates :password, length: { minimum: 6, maximum: ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED }, allow_nil: true
validates :password, confirmation: true, allow_blank: true

after_create :create_home_project
after_create :create_home_project, :track_create

def track_create
RabbitmqBus.send_to_bus('metrics', "user.create id=#{id}")
end

def create_home_project
# avoid errors during seeding
Expand Down Expand Up @@ -612,7 +616,14 @@ def lock!
end
end

def delete
delete!
rescue ActiveRecord::RecordInvalid
false
end

def delete!
oldstate = self.state
self.state = 'deleted'
save!

Expand All @@ -621,6 +632,9 @@ def delete!
prj.commit_opts = { comment: 'User account got deleted' }
prj.destroy
end

RabbitmqBus.send_to_bus('metrics', "user.delete id=#{id}") unless oldstate == 'deleted'
true
end

def involved_projects
Expand Down Expand Up @@ -841,7 +855,7 @@ def combined_rss_feed_items

def mark_login!
update_attributes(last_logged_in_at: Time.now, login_failure_count: 0)
RabbitmqBus.send_to_bus('metrics.user', "login id=#{id}")
RabbitmqBus.send_to_bus('metrics', "user.login id=#{id}")
end

private
Expand Down

0 comments on commit 74688df

Please sign in to comment.