Skip to content
Snippets Groups Projects
Commit 8f9beefa authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent e4bf776a
No related branches found
No related tags found
No related merge requests found
Showing
with 339 additions and 60 deletions
Loading
@@ -1693,9 +1693,6 @@ class User < ApplicationRecord
Loading
@@ -1693,9 +1693,6 @@ class User < ApplicationRecord
end end
end end
   
# @deprecated
alias_method :owned_or_masters_groups, :owned_or_maintainers_groups
protected protected
   
# override, from Devise::Validatable # override, from Devise::Validatable
Loading
Loading
# frozen_string_literal: true
class PrometheusAlertEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :title
expose :query
expose :threshold
expose :operator do |prometheus_alert|
prometheus_alert.computed_operator
end
expose :alert_path do |prometheus_alert|
project_prometheus_alert_path(prometheus_alert.project, prometheus_alert.prometheus_metric_id, environment_id: prometheus_alert.environment.id, format: :json)
end
private
alias_method :prometheus_alert, :object
def can_read_prometheus_alerts?
can?(request.current_user, :read_prometheus_alerts, prometheus_alert.project)
end
end
# frozen_string_literal: true
class PrometheusAlertSerializer < BaseSerializer
entity PrometheusAlertEntity
end
Loading
@@ -12,7 +12,8 @@ module Metrics
Loading
@@ -12,7 +12,8 @@ module Metrics
steps :check_push_authorized, steps :check_push_authorized,
:check_branch_name, :check_branch_name,
:check_file_type, :check_file_type,
:update_file :update_file,
:create_merge_request
   
def execute def execute
execute_steps execute_steps
Loading
@@ -49,6 +50,23 @@ module Metrics
Loading
@@ -49,6 +50,23 @@ module Metrics
end end
end end
   
def create_merge_request(result)
return success(result) if project.default_branch == branch
merge_request_params = {
source_branch: branch,
target_branch: project.default_branch,
title: params[:commit_message]
}
merge_request = ::MergeRequests::CreateService.new(project, current_user, merge_request_params).execute
if merge_request.persisted?
success(result.merge(merge_request: Gitlab::UrlBuilder.build(merge_request)))
else
error(merge_request.errors.full_messages.join(','), :bad_request)
end
end
def push_authorized? def push_authorized?
Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(branch) Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(branch)
end end
Loading
Loading
Loading
@@ -17,57 +17,72 @@ module Notes
Loading
@@ -17,57 +17,72 @@ module Notes
# We execute commands (extracted from `params[:note]`) on the noteable # We execute commands (extracted from `params[:note]`) on the noteable
# **before** we save the note because if the note consists of commands # **before** we save the note because if the note consists of commands
# only, there is no need be create a note! # only, there is no need be create a note!
quick_actions_service = QuickActionsService.new(project, current_user)
   
if quick_actions_service.supported?(note) execute_quick_actions(note) do |only_commands|
content, update_params, message = quick_actions_service.execute(note, quick_action_options) note.run_after_commit do
# Finish the harder work in the background
NewNoteWorker.perform_async(note.id)
end
   
only_commands = content.empty? note_saved = note.with_transaction_returning_status do
!only_commands && note.save
end
   
note.note = content when_saved(note) if note_saved
end end
   
note.run_after_commit do note
# Finish the harder work in the background end
NewNoteWorker.perform_async(note.id)
end
   
note_saved = note.with_transaction_returning_status do private
!only_commands && note.save
end
   
if note_saved def execute_quick_actions(note)
if note.part_of_discussion? && note.discussion.can_convert_to_discussion? return yield(false) unless quick_actions_service.supported?(note)
note.discussion.convert_to_discussion!(save: true)
end
   
todo_service.new_note(note, current_user) content, update_params, message = quick_actions_service.execute(note, quick_action_options)
clear_noteable_diffs_cache(note) only_commands = content.empty?
Suggestions::CreateService.new(note).execute note.note = content
increment_usage_counter(note)
   
if Feature.enabled?(:notes_create_service_tracking, project) yield(only_commands)
Gitlab::Tracking.event('Notes::CreateService', 'execute', tracking_data_for(note))
end
end
   
if quick_actions_service.commands_executed_count.to_i > 0 do_commands(note, update_params, message, only_commands)
if update_params.present? end
quick_actions_service.apply_updates(update_params, note)
note.commands_changes = update_params
end
   
# We must add the error after we call #save because errors are reset def quick_actions_service
# when #save is called @quick_actions_service ||= QuickActionsService.new(project, current_user)
if only_commands end
note.errors.add(:commands_only, message.presence || _('Failed to apply commands.'))
end def when_saved(note)
if note.part_of_discussion? && note.discussion.can_convert_to_discussion?
note.discussion.convert_to_discussion!(save: true)
end end
   
note todo_service.new_note(note, current_user)
clear_noteable_diffs_cache(note)
Suggestions::CreateService.new(note).execute
increment_usage_counter(note)
if Feature.enabled?(:notes_create_service_tracking, project)
Gitlab::Tracking.event('Notes::CreateService', 'execute', tracking_data_for(note))
end
end end
   
private def do_commands(note, update_params, message, only_commands)
return if quick_actions_service.commands_executed_count.to_i.zero?
if update_params.present?
quick_actions_service.apply_updates(update_params, note)
note.commands_changes = update_params
end
# We must add the error after we call #save because errors are reset
# when #save is called
if only_commands
note.errors.add(:commands_only, message.presence || _('Failed to apply commands.'))
# Allow consumers to detect problems applying commands
note.errors.add(:commands, _('Failed to apply commands.')) unless message.present?
end
end
   
# EE::Notes::CreateService would override this method # EE::Notes::CreateService would override this method
def quick_action_options def quick_action_options
Loading
Loading
Loading
@@ -55,6 +55,8 @@ module Notes
Loading
@@ -55,6 +55,8 @@ module Notes
# We must add the error after we call #save because errors are reset # We must add the error after we call #save because errors are reset
# when #save is called # when #save is called
note.errors.add(:commands_only, message.presence || _('Commands did not apply')) note.errors.add(:commands_only, message.presence || _('Commands did not apply'))
# Allow consumers to detect problems applying commands
note.errors.add(:commands, _('Commands did not apply')) unless message.present?
   
Notes::DestroyService.new(project, current_user).execute(note) Notes::DestroyService.new(project, current_user).execute(note)
end end
Loading
Loading
# frozen_string_literal: true
module Projects
module Prometheus
module Alerts
# Persists a series of Prometheus alert events as list of PrometheusAlertEvent.
class CreateEventsService < BaseService
def execute
create_events_from(alerts)
end
private
def create_events_from(alerts)
Array.wrap(alerts).map { |alert| create_event(alert) }.compact
end
def create_event(payload)
parsed_alert = Gitlab::Alerting::Alert.new(project: project, payload: payload)
return unless parsed_alert.valid?
if parsed_alert.gitlab_managed?
create_managed_prometheus_alert_event(parsed_alert)
else
create_self_managed_prometheus_alert_event(parsed_alert)
end
end
def alerts
params['alerts']
end
def find_alert(metric)
Projects::Prometheus::AlertsFinder
.new(project: project, metric: metric)
.execute
.first
end
def create_managed_prometheus_alert_event(parsed_alert)
alert = find_alert(parsed_alert.metric_id)
payload_key = PrometheusAlertEvent.payload_key_for(parsed_alert.metric_id, parsed_alert.starts_at_raw)
event = PrometheusAlertEvent.find_or_initialize_by_payload_key(parsed_alert.project, alert, payload_key)
set_status(parsed_alert, event)
end
def create_self_managed_prometheus_alert_event(parsed_alert)
payload_key = SelfManagedPrometheusAlertEvent.payload_key_for(parsed_alert.starts_at_raw, parsed_alert.title, parsed_alert.full_query)
event = SelfManagedPrometheusAlertEvent.find_or_initialize_by_payload_key(parsed_alert.project, payload_key) do |event|
event.environment = parsed_alert.environment
event.title = parsed_alert.title
event.query_expression = parsed_alert.full_query
end
set_status(parsed_alert, event)
end
def set_status(parsed_alert, event)
persisted = case parsed_alert.status
when 'firing'
event.fire(parsed_alert.starts_at)
when 'resolved'
event.resolve(parsed_alert.ends_at)
end
event if persisted
end
end
end
end
end
Loading
@@ -38,19 +38,16 @@ module Snippets
Loading
@@ -38,19 +38,16 @@ module Snippets
private private
   
def save_and_commit(snippet) def save_and_commit(snippet)
result = snippet.with_transaction_returning_status do snippet_saved = snippet.with_transaction_returning_status do
(snippet.save && snippet.store_mentions!).tap do |saved| snippet.save && snippet.store_mentions!
break false unless saved
if Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet)
end
end
end end
   
create_commit(snippet) if result && snippet.repository_exists? if snippet_saved && Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet)
create_commit(snippet)
end
   
result snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ... rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet.errors.add(:base, e.message) snippet.errors.add(:base, e.message)
   
Loading
Loading
Loading
@@ -528,6 +528,13 @@
Loading
@@ -528,6 +528,13 @@
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 2 :weight: 2
:idempotent: :idempotent:
- :name: incident_management:incident_management_process_prometheus_alert
:feature_category: :incident_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :cpu
:weight: 2
:idempotent:
- :name: jira_importer:jira_import_advance_stage - :name: jira_importer:jira_import_advance_stage
:feature_category: :importers :feature_category: :importers
:has_external_dependencies: :has_external_dependencies:
Loading
Loading
# frozen_string_literal: true
module IncidentManagement
class ProcessPrometheusAlertWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
queue_namespace :incident_management
feature_category :incident_management
worker_resource_boundary :cpu
def perform(project_id, alert_hash)
project = find_project(project_id)
return unless project
parsed_alert = Gitlab::Alerting::Alert.new(project: project, payload: alert_hash)
event = find_prometheus_alert_event(parsed_alert)
if event&.resolved?
issue = event.related_issues.order_created_at_desc.detect(&:opened?)
close_issue(project, issue)
else
issue = create_issue(project, alert_hash)
relate_issue_to_event(event, issue)
end
end
private
def find_project(project_id)
Project.find_by_id(project_id)
end
def find_prometheus_alert_event(alert)
if alert.gitlab_managed?
find_gitlab_managed_event(alert)
else
find_self_managed_event(alert)
end
end
def find_gitlab_managed_event(alert)
payload_key = payload_key_for_alert(alert)
PrometheusAlertEvent.find_by_payload_key(payload_key)
end
def find_self_managed_event(alert)
payload_key = payload_key_for_alert(alert)
SelfManagedPrometheusAlertEvent.find_by_payload_key(payload_key)
end
def payload_key_for_alert(alert)
if alert.gitlab_managed?
PrometheusAlertEvent.payload_key_for(alert.metric_id, alert.starts_at_raw)
else
SelfManagedPrometheusAlertEvent.payload_key_for(alert.starts_at_raw, alert.title, alert.full_query)
end
end
def create_issue(project, alert)
IncidentManagement::CreateIssueService
.new(project, alert)
.execute
.dig(:issue)
end
def close_issue(project, issue)
return if issue.blank? || issue.closed?
processed_issue = Issues::CloseService
.new(project, User.alert_bot)
.execute(issue, system_note: false)
SystemNoteService.auto_resolve_prometheus_alert(issue, project, User.alert_bot) if processed_issue.reset.closed?
end
def relate_issue_to_event(event, issue)
return unless event && issue
if event.related_issues.exclude?(issue)
event.related_issues << issue
end
end
end
end
Loading
@@ -159,7 +159,11 @@ module Secpick
Loading
@@ -159,7 +159,11 @@ module Secpick
options[:branch] ||= `git rev-parse --abbrev-ref HEAD` options[:branch] ||= `git rev-parse --abbrev-ref HEAD`
options[:remote] ||= DEFAULT_REMOTE options[:remote] ||= DEFAULT_REMOTE
   
abort("Missing options. Use #{$0} --help to see the list of options available".red) if options.value?(nil) nil_options = options.select {|_, v| v.nil? }
unless nil_options.empty?
abort("Missing: #{nil_options.keys.join(', ')}. Use #{$0} --help to see the list of options available".red)
end
abort("Wrong version format #{options[:version].bold}".red) unless options[:version] =~ /\A\d*\-\d*\Z/ abort("Wrong version format #{options[:version].bold}".red) unless options[:version] =~ /\A\d*\-\d*\Z/
end end
end end
Loading
Loading
---
title: Only enable searching of projects by full path / name on certain dropdowns
merge_request: 21910
author:
type: changed
---
title: Start merge request for custom dashboard if new branch is provided
merge_request: 27189
author:
type: added
---
title: Fix smartcard config initialization
merge_request: 27560
author:
type: fixed
---
title: Return 202 for command only notes in REST API
merge_request: 19624
author:
type: fixed
---
title: Create a rake task to cleanup unused LFS files
merge_request: 21747
author:
type: added
---
title: Reuse default generated snippet file name in repository
merge_request: 27673
author:
type: fixed
---
title: Fix new file not being created in non-ascii character folders
merge_request: 26165
author:
type: fixed
Loading
@@ -74,15 +74,6 @@ if Settings.ldap['enabled'] || Rails.env.test?
Loading
@@ -74,15 +74,6 @@ if Settings.ldap['enabled'] || Rails.env.test?
end end
end end
   
Gitlab.ee do
Settings['smartcard'] ||= Settingslogic.new({})
Settings.smartcard['enabled'] = false if Settings.smartcard['enabled'].nil?
Settings.smartcard['client_certificate_required_host'] = Settings.gitlab['host'] if Settings.smartcard['client_certificate_required_host'].nil?
Settings.smartcard['client_certificate_required_port'] = 3444 if Settings.smartcard['client_certificate_required_port'].nil?
Settings.smartcard['required_for_git_access'] = false if Settings.smartcard['required_for_git_access'].nil?
Settings.smartcard['san_extensions'] = false if Settings.smartcard['san_extensions'].nil?
end
Settings['omniauth'] ||= Settingslogic.new({}) Settings['omniauth'] ||= Settingslogic.new({})
Settings.omniauth['enabled'] = true if Settings.omniauth['enabled'].nil? Settings.omniauth['enabled'] = true if Settings.omniauth['enabled'].nil?
Settings.omniauth['auto_sign_in_with_provider'] = false if Settings.omniauth['auto_sign_in_with_provider'].nil? Settings.omniauth['auto_sign_in_with_provider'] = false if Settings.omniauth['auto_sign_in_with_provider'].nil?
Loading
@@ -671,6 +662,18 @@ Gitlab.ee do
Loading
@@ -671,6 +662,18 @@ Gitlab.ee do
end end
end end
   
#
# Smartcard
#
Gitlab.ee do
Settings['smartcard'] ||= Settingslogic.new({})
Settings.smartcard['enabled'] = false if Settings.smartcard['enabled'].nil?
Settings.smartcard['client_certificate_required_host'] = Settings.gitlab.host if Settings.smartcard['client_certificate_required_host'].nil?
Settings.smartcard['client_certificate_required_port'] = 3444 if Settings.smartcard['client_certificate_required_port'].nil?
Settings.smartcard['required_for_git_access'] = false if Settings.smartcard['required_for_git_access'].nil?
Settings.smartcard['san_extensions'] = false if Settings.smartcard['san_extensions'].nil?
end
# #
# Extra customization # Extra customization
# #
Loading
Loading
Loading
@@ -339,6 +339,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
Loading
@@ -339,6 +339,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
   
namespace :prometheus do namespace :prometheus do
resources :alerts, constraints: { id: /\d+/ }, only: [:index, :create, :show, :update, :destroy] do
post :notify, on: :collection
member do
get :metrics_dashboard
end
end
resources :metrics, constraints: { id: %r{[^\/]+} }, only: [:index, :new, :create, :edit, :update, :destroy] do resources :metrics, constraints: { id: %r{[^\/]+} }, only: [:index, :new, :create, :edit, :update, :destroy] do
get :active_common, on: :collection get :active_common, on: :collection
end end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment