summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
commit6315ed9630fb1c6ade3114beb762cd1568d79219 (patch)
tree2a5d31936d09c14420c8f4c8bd752e268f0eb19f /app
parentfedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (diff)
downloadgitlab-ce-6315ed9630fb1c6ade3114beb762cd1568d79219.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/broadcast_notification.js21
-rw-r--r--app/assets/javascripts/main.js2
-rw-r--r--app/helpers/broadcast_messages_helper.rb13
-rw-r--r--app/models/ci/job_artifact.rb9
-rw-r--r--app/models/concerns/atomic_internal_id.rb4
-rw-r--r--app/models/internal_id.rb2
-rw-r--r--app/models/performance_monitoring/prometheus_dashboard.rb31
-rw-r--r--app/models/performance_monitoring/prometheus_metric.rb25
-rw-r--r--app/models/performance_monitoring/prometheus_panel.rb24
-rw-r--r--app/models/performance_monitoring/prometheus_panel_group.rb22
-rw-r--r--app/models/repository.rb12
-rw-r--r--app/views/shared/_broadcast_message.html.haml8
12 files changed, 149 insertions, 24 deletions
diff --git a/app/assets/javascripts/broadcast_notification.js b/app/assets/javascripts/broadcast_notification.js
new file mode 100644
index 00000000000..b124502506a
--- /dev/null
+++ b/app/assets/javascripts/broadcast_notification.js
@@ -0,0 +1,21 @@
+import Cookies from 'js-cookie';
+
+const handleOnDismiss = ({ currentTarget }) => {
+ currentTarget.removeEventListener('click', handleOnDismiss);
+ const {
+ dataset: { id },
+ } = currentTarget;
+
+ Cookies.set(`hide_broadcast_notification_message_${id}`, true);
+
+ const notification = document.querySelector(`.js-broadcast-notification-${id}`);
+ notification.parentNode.removeChild(notification);
+};
+
+export default () => {
+ const dismissButton = document.querySelector('.js-dismiss-current-broadcast-notification');
+
+ if (dismissButton) {
+ dismissButton.addEventListener('click', handleOnDismiss);
+ }
+};
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
index d755e7e8cdb..1e07469bd7a 100644
--- a/app/assets/javascripts/main.js
+++ b/app/assets/javascripts/main.js
@@ -35,6 +35,7 @@ import initPerformanceBar from './performance_bar';
import initSearchAutocomplete from './search_autocomplete';
import GlFieldErrors from './gl_field_errors';
import initUserPopovers from './user_popovers';
+import initBroadcastNotifications from './broadcast_notification';
import { initUserTracking } from './tracking';
import { __ } from './locale';
@@ -105,6 +106,7 @@ function deferredInitialisation() {
initUsagePingConsent();
initUserPopovers();
initUserTracking();
+ initBroadcastNotifications();
if (document.querySelector('.search')) initSearchAutocomplete();
diff --git a/app/helpers/broadcast_messages_helper.rb b/app/helpers/broadcast_messages_helper.rb
index b95fd8800c0..34e65c322c6 100644
--- a/app/helpers/broadcast_messages_helper.rb
+++ b/app/helpers/broadcast_messages_helper.rb
@@ -6,19 +6,16 @@ module BroadcastMessagesHelper
end
def current_broadcast_notification_message
- BroadcastMessage.current_notification_messages(request.path).last
+ not_hidden_messages = BroadcastMessage.current_notification_messages(request.path).select do |message|
+ cookies["hide_broadcast_notification_message_#{message.id}"].blank?
+ end
+ not_hidden_messages.last
end
def broadcast_message(message, opts = {})
return unless message.present?
- classes = "broadcast-#{message.broadcast_type}-message #{opts[:preview] && 'preview'}"
-
- content_tag :div, dir: 'auto', class: classes, style: broadcast_message_style(message) do
- concat sprite_icon('bullhorn', size: 16, css_class: 'vertical-align-text-top')
- concat ' '
- concat render_broadcast_message(message)
- end
+ render "shared/broadcast_message", { message: message, opts: opts }
end
def broadcast_message_style(broadcast_message)
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb
index 9eca324f0fc..4b205cbe67a 100644
--- a/app/models/ci/job_artifact.rb
+++ b/app/models/ci/job_artifact.rb
@@ -27,7 +27,8 @@ module Ci
license_management: 'gl-license-management-report.json',
license_scanning: 'gl-license-scanning-report.json',
performance: 'performance.json',
- metrics: 'metrics.txt'
+ metrics: 'metrics.txt',
+ lsif: 'lsif.sqlite3'
}.freeze
INTERNAL_TYPES = {
@@ -52,7 +53,8 @@ module Ci
dast: :raw,
license_management: :raw,
license_scanning: :raw,
- performance: :raw
+ performance: :raw,
+ lsif: :raw
}.freeze
TYPE_AND_FORMAT_PAIRS = INTERNAL_TYPES.merge(REPORT_TYPES).freeze
@@ -114,7 +116,8 @@ module Ci
performance: 11, ## EE-specific
metrics: 12, ## EE-specific
metrics_referee: 13, ## runner referees
- network_referee: 14 ## runner referees
+ network_referee: 14, ## runner referees
+ lsif: 15 # LSIF dump for code navigation
}
enum file_format: {
diff --git a/app/models/concerns/atomic_internal_id.rb b/app/models/concerns/atomic_internal_id.rb
index 3e9b084e784..4a632e8cd0c 100644
--- a/app/models/concerns/atomic_internal_id.rb
+++ b/app/models/concerns/atomic_internal_id.rb
@@ -27,7 +27,7 @@ module AtomicInternalId
extend ActiveSupport::Concern
class_methods do
- def has_internal_id(column, scope:, init:, ensure_if: nil, track_if: nil, presence: true) # rubocop:disable Naming/PredicateName
+ def has_internal_id(column, scope:, init:, ensure_if: nil, track_if: nil, presence: true, backfill: false) # rubocop:disable Naming/PredicateName
# We require init here to retain the ability to recalculate in the absence of a
# InternalId record (we may delete records in `internal_ids` for example).
raise "has_internal_id requires a init block, none given." unless init
@@ -38,6 +38,8 @@ module AtomicInternalId
validates column, presence: presence
define_method("ensure_#{scope}_#{column}!") do
+ return if backfill && self.class.where(column => nil).exists?
+
scope_value = internal_id_read_scope(scope)
value = read_attribute(column)
return value unless scope_value
diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb
index 8d3eeaf2461..3e8d0c6a778 100644
--- a/app/models/internal_id.rb
+++ b/app/models/internal_id.rb
@@ -21,7 +21,7 @@ class InternalId < ApplicationRecord
belongs_to :project
belongs_to :namespace
- enum usage: { issues: 0, merge_requests: 1, deployments: 2, milestones: 3, epics: 4, ci_pipelines: 5 }
+ enum usage: { issues: 0, merge_requests: 1, deployments: 2, milestones: 3, epics: 4, ci_pipelines: 5, operations_feature_flags: 6 }
validates :usage, presence: true
diff --git a/app/models/performance_monitoring/prometheus_dashboard.rb b/app/models/performance_monitoring/prometheus_dashboard.rb
new file mode 100644
index 00000000000..5f2df444fd0
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_dashboard.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusDashboard
+ include ActiveModel::Model
+
+ attr_accessor :dashboard, :panel_groups
+
+ validates :dashboard, presence: true
+ validates :panel_groups, presence: true
+
+ def self.from_json(json_content)
+ dashboard = new(
+ dashboard: json_content['dashboard'],
+ panel_groups: json_content['panel_groups'].map { |group| PrometheusPanelGroup.from_json(group) }
+ )
+
+ dashboard.tap(&:validate!)
+ end
+
+ def to_yaml
+ self.as_json(only: valid_attributes).to_yaml
+ end
+
+ private
+
+ def valid_attributes
+ %w(panel_groups panels metrics group priority type title y_label weight id unit label query query_range dashboard)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_metric.rb b/app/models/performance_monitoring/prometheus_metric.rb
new file mode 100644
index 00000000000..7b8bef906fa
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_metric.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusMetric
+ include ActiveModel::Model
+
+ attr_accessor :id, :unit, :label, :query, :query_range
+
+ validates :unit, presence: true
+ validates :query, presence: true, unless: :query_range
+ validates :query_range, presence: true, unless: :query
+
+ def self.from_json(json_content)
+ metric = PrometheusMetric.new(
+ id: json_content['id'],
+ unit: json_content['unit'],
+ label: json_content['label'],
+ query: json_content['query'],
+ query_range: json_content['query_range']
+ )
+
+ metric.tap(&:validate!)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_panel.rb b/app/models/performance_monitoring/prometheus_panel.rb
new file mode 100644
index 00000000000..c03218b4219
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_panel.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusPanel
+ include ActiveModel::Model
+
+ attr_accessor :type, :title, :y_label, :weight, :metrics
+
+ validates :title, presence: true
+ validates :metrics, presence: true
+
+ def self.from_json(json_content)
+ panel = new(
+ type: json_content['type'],
+ title: json_content['title'],
+ y_label: json_content['y_label'],
+ weight: json_content['weight'],
+ metrics: json_content['metrics'].map { |metric| PrometheusMetric.from_json(metric) }
+ )
+
+ panel.tap(&:validate!)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_panel_group.rb b/app/models/performance_monitoring/prometheus_panel_group.rb
new file mode 100644
index 00000000000..e672545fce3
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_panel_group.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusPanelGroup
+ include ActiveModel::Model
+
+ attr_accessor :group, :priority, :panels
+
+ validates :group, presence: true
+ validates :panels, presence: true
+
+ def self.from_json(json_content)
+ panel_group = new(
+ group: json_content['group'],
+ priority: json_content['priority'],
+ panels: json_content['panels'].map { |panel| PrometheusPanel.from_json(panel) }
+ )
+
+ panel_group.tap(&:validate!)
+ end
+ end
+end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c0d1750fe42..ee919f844dc 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -927,22 +927,12 @@ class Repository
def ancestor?(ancestor_id, descendant_id)
return false if ancestor_id.nil? || descendant_id.nil?
- counter = Gitlab::Metrics.counter(
- :repository_ancestor_calls_total,
- 'The number of times we call Repository#ancestor with valid arguments')
- cache_hit = true
-
cache_key = "ancestor:#{ancestor_id}:#{descendant_id}"
- result = request_store_cache.fetch(cache_key) do
+ request_store_cache.fetch(cache_key) do
cache.fetch(cache_key) do
- cache_hit = false
raw_repository.ancestor?(ancestor_id, descendant_id)
end
end
-
- counter.increment(cache_hit: cache_hit.to_s)
-
- result
end
def fetch_as_mirror(url, forced: false, refmap: :all_refs, remote_name: nil, prune: true)
diff --git a/app/views/shared/_broadcast_message.html.haml b/app/views/shared/_broadcast_message.html.haml
new file mode 100644
index 00000000000..c058b210688
--- /dev/null
+++ b/app/views/shared/_broadcast_message.html.haml
@@ -0,0 +1,8 @@
+%div{ class: "broadcast-#{message.broadcast_type}-message #{opts[:preview] && 'preview'} js-broadcast-notification-#{message.id} d-flex",
+ style: broadcast_message_style(message), dir: 'auto' }
+ %div
+ = sprite_icon('bullhorn', size: 16, css_class: 'vertical-align-text-top')
+ = render_broadcast_message(message)
+ - if message.notification? && opts[:preview].blank?
+ %button.js-dismiss-current-broadcast-notification.btn.btn-link.text-dark.pl-2.pr-2{ 'aria-label' => _('Close'), :type => 'button', data: { id: message.id } }
+ %i.fa.fa-times