diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/boot.rb | 12 | ||||
-rw-r--r-- | config/initializers/active_record_data_types.rb | 73 | ||||
-rw-r--r-- | config/initializers/active_record_table_definition.rb | 22 | ||||
-rw-r--r-- | config/initializers/flipper.rb | 4 | ||||
-rw-r--r-- | config/prometheus/additional_metrics.yml | 32 | ||||
-rw-r--r-- | config/routes/project.rb | 6 | ||||
-rw-r--r-- | config/webpack.config.js | 1 |
7 files changed, 124 insertions, 26 deletions
diff --git a/config/boot.rb b/config/boot.rb index 16de55d7a86..2d01092acd5 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -9,15 +9,3 @@ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test' ENV['prometheus_multiproc_dir'] ||= 'tmp/prometheus_multiproc_dir' end - -# Default Bootsnap configuration from https://github.com/Shopify/bootsnap#usage -require 'bootsnap' -Bootsnap.setup( - cache_dir: 'tmp/cache', - development_mode: ENV['RAILS_ENV'] == 'development', - load_path_cache: true, - autoload_paths_cache: true, - disable_trace: false, - compile_cache_iseq: true, - compile_cache_yaml: true -) diff --git a/config/initializers/active_record_data_types.rb b/config/initializers/active_record_data_types.rb index beb97c6fce0..fef591c397d 100644 --- a/config/initializers/active_record_data_types.rb +++ b/config/initializers/active_record_data_types.rb @@ -4,21 +4,78 @@ if Gitlab::Database.postgresql? require 'active_record/connection_adapters/postgresql_adapter' - module ActiveRecord - module ConnectionAdapters - class PostgreSQLAdapter - NATIVE_DATABASE_TYPES.merge!(datetime_with_timezone: { name: 'timestamptz' }) + module ActiveRecord::ConnectionAdapters::PostgreSQL::OID + # Add the class `DateTimeWithTimeZone` so we can map `timestamptz` to it. + class DateTimeWithTimeZone < DateTime + def type + :datetime_with_timezone end end end + + module RegisterDateTimeWithTimeZone + # Run original `initialize_type_map` and then register `timestamptz` as a + # `DateTimeWithTimeZone`. + # + # Apparently it does not matter that the original `initialize_type_map` + # aliases `timestamptz` to `timestamp`. + # + # When schema dumping, `timestamptz` columns will be output as + # `t.datetime_with_timezone`. + def initialize_type_map(mapping) + super mapping + + mapping.register_type 'timestamptz' do |_, _, sql_type| + precision = extract_precision(sql_type) + ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::DateTimeWithTimeZone.new(precision: precision) + end + end + end + + class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + prepend RegisterDateTimeWithTimeZone + + # Add column type `datetime_with_timezone` so we can do this in + # migrations: + # + # add_column(:users, :datetime_with_timezone) + # + NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamptz' } + end elsif Gitlab::Database.mysql? require 'active_record/connection_adapters/mysql2_adapter' - module ActiveRecord - module ConnectionAdapters - class AbstractMysqlAdapter - NATIVE_DATABASE_TYPES.merge!(datetime_with_timezone: { name: 'timestamp' }) + module RegisterDateTimeWithTimeZone + # Run original `initialize_type_map` and then register `timestamp` as a + # `MysqlDateTimeWithTimeZone`. + # + # When schema dumping, `timestamp` columns will be output as + # `t.datetime_with_timezone`. + def initialize_type_map(mapping) + super mapping + + mapping.register_type(%r(timestamp)i) do |sql_type| + precision = extract_precision(sql_type) + ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTimeWithTimeZone.new(precision: precision) end end end + + class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter + prepend RegisterDateTimeWithTimeZone + + # Add the class `DateTimeWithTimeZone` so we can map `timestamp` to it. + class MysqlDateTimeWithTimeZone < MysqlDateTime + def type + :datetime_with_timezone + end + end + + # Add column type `datetime_with_timezone` so we can do this in + # migrations: + # + # add_column(:users, :datetime_with_timezone) + # + NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamp' } + end end diff --git a/config/initializers/active_record_table_definition.rb b/config/initializers/active_record_table_definition.rb index 4f59e35f4da..8e3a1c7a62f 100644 --- a/config/initializers/active_record_table_definition.rb +++ b/config/initializers/active_record_table_definition.rb @@ -3,15 +3,15 @@ require 'active_record/connection_adapters/abstract/schema_definitions' -# Appends columns `created_at` and `updated_at` to a table. -# -# It is used in table creation like: -# create_table 'users' do |t| -# t.timestamps_with_timezone -# end module ActiveRecord module ConnectionAdapters class TableDefinition + # Appends columns `created_at` and `updated_at` to a table. + # + # It is used in table creation like: + # create_table 'users' do |t| + # t.timestamps_with_timezone + # end def timestamps_with_timezone(**options) options[:null] = false if options[:null].nil? @@ -19,6 +19,16 @@ module ActiveRecord column(column_name, :datetime_with_timezone, options) end end + + # Adds specified column with appropriate timestamp type + # + # It is used in table creation like: + # create_table 'users' do |t| + # t.datetime_with_timezone :did_something_at + # end + def datetime_with_timezone(column_name, **options) + column(column_name, :datetime_with_timezone, options) + end end end end diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb new file mode 100644 index 00000000000..0fee832788d --- /dev/null +++ b/config/initializers/flipper.rb @@ -0,0 +1,4 @@ +require 'flipper/middleware/memoizer' + +Rails.application.config.middleware.use Flipper::Middleware::Memoizer, + lambda { Feature.flipper } diff --git a/config/prometheus/additional_metrics.yml b/config/prometheus/additional_metrics.yml new file mode 100644 index 00000000000..daecde49570 --- /dev/null +++ b/config/prometheus/additional_metrics.yml @@ -0,0 +1,32 @@ +- group: Kubernetes + priority: 1 + metrics: + - title: "Memory usage" + y_label: "Values" + required_metrics: + - container_memory_usage_bytes + weight: 1 + queries: + - query_range: 'avg(container_memory_usage_bytes{%{environment_filter}}) / 2^20' + label: Container memory + unit: MiB + - title: "Current memory usage" + required_metrics: + - container_memory_usage_bytes + weight: 1 + queries: + - query: 'avg(container_memory_usage_bytes{%{environment_filter}}) / 2^20' + display_empty: false + unit: MiB + - title: "CPU usage" + required_metrics: + - container_cpu_usage_seconds_total + weight: 1 + queries: + - query_range: 'avg(rate(container_cpu_usage_seconds_total{%{environment_filter}}[2m])) * 100' + - title: "Current CPU usage" + required_metrics: + - container_cpu_usage_seconds_total + weight: 1 + queries: + - query: 'avg(rate(container_cpu_usage_seconds_total{%{environment_filter}}[2m])) * 100' diff --git a/config/routes/project.rb b/config/routes/project.rb index f95cc3101d3..19e18c733b1 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -73,6 +73,10 @@ constraints(ProjectUrlConstrainer.new) do resource :mattermost, only: [:new, :create] + namespace :prometheus do + get :active_metrics + end + resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create, :edit, :update] do member do put :enable @@ -153,6 +157,7 @@ constraints(ProjectUrlConstrainer.new) do post :stop get :terminal get :metrics + get :additional_metrics get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil } end @@ -163,6 +168,7 @@ constraints(ProjectUrlConstrainer.new) do resources :deployments, only: [:index] do member do get :metrics + get :additional_metrics end end end diff --git a/config/webpack.config.js b/config/webpack.config.js index fb91ffef7e7..f27b7cae310 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -55,6 +55,7 @@ var config = { pipelines: './pipelines/pipelines_bundle.js', pipelines_details: './pipelines/pipeline_details_bundle.js', profile: './profile/profile_bundle.js', + prometheus_metrics: './prometheus_metrics', protected_branches: './protected_branches/protected_branches_bundle.js', protected_tags: './protected_tags', sidebar: './sidebar/sidebar_bundle.js', |