Commit 08461c15 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Merge migrations and fix schema.rb + add required fields to prometheus metrics

parent dda417bf
......@@ -4,10 +4,18 @@ class PrometheusMetric < ActiveRecord::Base
validates :title, presence: true
validates :query, presence: true
validates :group, presence: true
GROUP_NAMES = {
business_metrics: 'Business metrics',
response: 'Response metrics',
system: 'System metrics'
}.freeze
def self.to_grouped_query_metrics
self.all.group_by(&:group).map do |name, metrics|
[name, metrics.map(&:to_query_metric)]
self.all.group_by(&:group).map do |group, metrics|
group ||= :business
[GROUP_NAMES[group], metrics.map(&:to_query_metric)]
end
end
......
......@@ -2,12 +2,13 @@ class CreatePrometheusMetrics < ActiveRecord::Migration
def change
create_table :prometheus_metrics do |t|
t.references :project, index: true, foreign_key: true
t.string :title
t.string :query
t.string :title, null: false
t.string :query, null: false
t.string :y_label
t.string :unit
t.string :legend
t.integer :group, null: false
t.index :group
t.timestamps null: false
end
end
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddGroupToPrometheusMetrics < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :prometheus_metrics, :group, :integer
add_index :prometheus_metrics, :group
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180104215427) do
ActiveRecord::Schema.define(version: 20180101160629) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -1895,11 +1895,12 @@ ActiveRecord::Schema.define(version: 20180104215427) do
create_table "prometheus_metrics", force: :cascade do |t|
t.integer "project_id"
t.string "title"
t.string "query"
t.string "title", null: false
t.string "query", null: false
t.string "y_label"
t.string "unit"
t.string "legend"
t.integer "group", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment