summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 21:07:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 21:07:29 +0000
commit1da3754b25657f49afdcb0b942506d365b1ee89d (patch)
tree9f4bfa94fdd1762ef99e6a61bf180ac8cd7b5616 /app
parent25521def84a6987fe9d4265b560e930bfb32c195 (diff)
downloadgitlab-ce-1da3754b25657f49afdcb0b942506d365b1ee89d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/monitoring/utils.js8
-rw-r--r--app/assets/javascripts/reports/store/utils.js2
-rw-r--r--app/controllers/health_controller.rb41
-rw-r--r--app/controllers/projects/settings/operations_controller.rb4
-rw-r--r--app/helpers/groups_helper.rb3
-rw-r--r--app/helpers/projects_helper.rb10
-rw-r--r--app/models/grafana_integration.rb16
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/storage/hashed_project.rb6
-rw-r--r--app/models/storage/legacy_project.rb6
-rw-r--r--app/services/projects/operations/update_service.rb12
12 files changed, 69 insertions, 45 deletions
diff --git a/app/assets/javascripts/monitoring/utils.js b/app/assets/javascripts/monitoring/utils.js
index 46b01f753f8..a134b4e3c33 100644
--- a/app/assets/javascripts/monitoring/utils.js
+++ b/app/assets/javascripts/monitoring/utils.js
@@ -1,19 +1,21 @@
import { secondsIn, timeWindowsKeyNames } from './constants';
+const secondsToMilliseconds = seconds => seconds * 1000;
+
export const getTimeDiff = timeWindow => {
const end = Math.floor(Date.now() / 1000); // convert milliseconds to seconds
const difference = secondsIn[timeWindow] || secondsIn.eightHours;
const start = end - difference;
return {
- start: new Date(start * 1000).toISOString(),
- end: new Date(end * 1000).toISOString(),
+ start: new Date(secondsToMilliseconds(start)).toISOString(),
+ end: new Date(secondsToMilliseconds(end)).toISOString(),
};
};
export const getTimeWindow = ({ start, end }) =>
Object.entries(secondsIn).reduce((acc, [timeRange, value]) => {
- if (end - start === value) {
+ if (new Date(end) - new Date(start) === secondsToMilliseconds(value)) {
return timeRange;
}
return acc;
diff --git a/app/assets/javascripts/reports/store/utils.js b/app/assets/javascripts/reports/store/utils.js
index 10560d0ae8e..7381f038eaf 100644
--- a/app/assets/javascripts/reports/store/utils.js
+++ b/app/assets/javascripts/reports/store/utils.js
@@ -11,7 +11,7 @@ const textBuilder = results => {
const { failed, resolved, total } = results;
const failedString = failed
- ? n__('%d failed test result', '%d failed test results', failed)
+ ? n__('%d failed/error test result', '%d failed/error test results', failed)
: null;
const resolvedString = resolved
? n__('%d fixed test result', '%d fixed test results', resolved)
diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb
index 84b4932ba7a..99840e40af1 100644
--- a/app/controllers/health_controller.rb
+++ b/app/controllers/health_controller.rb
@@ -4,19 +4,15 @@ class HealthController < ActionController::Base
protect_from_forgery with: :exception, prepend: true
include RequiresWhitelistedMonitoringClient
- CHECKS = [
- Gitlab::HealthChecks::DbCheck,
- Gitlab::HealthChecks::Redis::RedisCheck,
- Gitlab::HealthChecks::Redis::CacheCheck,
- Gitlab::HealthChecks::Redis::QueuesCheck,
- Gitlab::HealthChecks::Redis::SharedStateCheck,
- Gitlab::HealthChecks::GitalyCheck
- ].freeze
-
def readiness
- results = CHECKS.map { |check| [check.name, check.readiness] }
+ results = checks.flat_map(&:readiness)
+ success = results.all?(&:success)
- render_check_results(results)
+ # disable static error pages at the gitlab-workhorse level, we want to see this error response even in production
+ headers["X-GitLab-Custom-Error"] = 1 unless success
+
+ response = results.map { |result| [result.name, result.payload] }.to_h
+ render json: response, status: success ? :ok : :service_unavailable
end
def liveness
@@ -25,26 +21,7 @@ class HealthController < ActionController::Base
private
- def render_check_results(results)
- flattened = results.flat_map do |name, result|
- if result.is_a?(Gitlab::HealthChecks::Result)
- [[name, result]]
- else
- result.map { |r| [name, r] }
- end
- end
- success = flattened.all? { |name, r| r.success }
-
- response = flattened.map do |name, r|
- info = { status: r.success ? 'ok' : 'failed' }
- info['message'] = r.message if r.message
- info[:labels] = r.labels if r.labels
- [name, info]
- end
-
- # disable static error pages at the gitlab-workhorse level, we want to see this error response even in production
- headers["X-GitLab-Custom-Error"] = 1 unless success
-
- render json: response.to_h, status: success ? :ok : :service_unavailable
+ def checks
+ ::Gitlab::HealthChecks::CHECKS
end
end
diff --git a/app/controllers/projects/settings/operations_controller.rb b/app/controllers/projects/settings/operations_controller.rb
index 7c71486a765..6110a7759ad 100644
--- a/app/controllers/projects/settings/operations_controller.rb
+++ b/app/controllers/projects/settings/operations_controller.rb
@@ -63,7 +63,9 @@ module Projects
:api_host,
:token,
project: [:slug, :name, :organization_slug, :organization_name]
- ]
+ ],
+
+ grafana_integration_attributes: [:token, :grafana_url]
}
end
end
diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb
index 601560cca92..9cba87ac444 100644
--- a/app/helpers/groups_helper.rb
+++ b/app/helpers/groups_helper.rb
@@ -32,8 +32,7 @@ module GroupsHelper
end
def can_disable_group_emails?(group)
- Feature.enabled?(:emails_disabled, group, default_enabled: true) &&
- can?(current_user, :set_emails_disabled, group) && !group.parent&.emails_disabled?
+ can?(current_user, :set_emails_disabled, group) && !group.parent&.emails_disabled?
end
def group_issues_count(state:)
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 177778a7278..4b00c11b27c 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -160,7 +160,7 @@ module ProjectsHelper
def can_disable_emails?(project, current_user)
return false if project.group&.emails_disabled?
- can?(current_user, :set_emails_disabled, project) && Feature.enabled?(:emails_disabled, project, default_enabled: true)
+ can?(current_user, :set_emails_disabled, project)
end
def last_push_event
@@ -354,6 +354,14 @@ module ProjectsHelper
@project.metrics_setting_external_dashboard_url
end
+ def grafana_integration_url
+ @project.grafana_integration&.grafana_url
+ end
+
+ def grafana_integration_token
+ @project.grafana_integration&.token
+ end
+
private
def get_project_nav_tabs(project, current_user)
diff --git a/app/models/grafana_integration.rb b/app/models/grafana_integration.rb
new file mode 100644
index 00000000000..668b9dafd7d
--- /dev/null
+++ b/app/models/grafana_integration.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class GrafanaIntegration < ApplicationRecord
+ belongs_to :project
+
+ attr_encrypted :token,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm',
+ key: Settings.attr_encrypted_db_key_base_32
+
+ validates :grafana_url,
+ length: { maximum: 1024 },
+ addressable_url: { enforce_sanitization: true, ascii_only: true }
+
+ validates :token, :project, presence: true
+end
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 2fe691bd959..0e6059f8715 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -182,7 +182,7 @@ class Namespace < ApplicationRecord
# any ancestor can disable emails for all descendants
def emails_disabled?
strong_memoize(:emails_disabled) do
- Feature.enabled?(:emails_disabled, self, default_enabled: true) && self_and_ancestors.where(emails_disabled: true).exists?
+ self_and_ancestors.where(emails_disabled: true).exists?
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 512734e9b3f..6b8067ddd7d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -195,6 +195,7 @@ class Project < ApplicationRecord
has_one :project_repository, inverse_of: :project
has_one :error_tracking_setting, inverse_of: :project, class_name: 'ErrorTracking::ProjectErrorTrackingSetting'
has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting'
+ has_one :grafana_integration, inverse_of: :project
# Merge Requests for target project should be removed with it
has_many :merge_requests, foreign_key: 'target_project_id', inverse_of: :target_project
@@ -311,6 +312,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :error_tracking_setting, update_only: true
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true
+ accepts_nested_attributes_for :grafana_integration, update_only: true, allow_destroy: true
delegate :name, to: :owner, allow_nil: true, prefix: true
delegate :members, to: :team, prefix: true
@@ -664,7 +666,7 @@ class Project < ApplicationRecord
def emails_disabled?
strong_memoize(:emails_disabled) do
# disabling in the namespace overrides the project setting
- Feature.enabled?(:emails_disabled, self, default_enabled: true) && (super || namespace.emails_disabled?)
+ super || namespace.emails_disabled?
end
end
diff --git a/app/models/storage/hashed_project.rb b/app/models/storage/hashed_project.rb
index f5d0d6fab3b..519d91434ad 100644
--- a/app/models/storage/hashed_project.rb
+++ b/app/models/storage/hashed_project.rb
@@ -27,8 +27,12 @@ module Storage
"#{base_dir}/#{disk_hash}" if disk_hash
end
+ # TODO: remove this method entirely after 12.4 https://gitlab.com/gitlab-org/gitlab/issues/33244
+ # we no longer need ensure_storage_path_exists to call add_namespace since both creating and moving
+ # repositories will be preceded by a mkdir -p in gitaly to ensure the parent of the destination directory
+ # exists.
def ensure_storage_path_exists
- gitlab_shell.add_namespace(repository_storage, base_dir)
+ true
end
def rename_repo(old_full_path: nil, new_full_path: nil)
diff --git a/app/models/storage/legacy_project.rb b/app/models/storage/legacy_project.rb
index 928c773c307..1d0124e8321 100644
--- a/app/models/storage/legacy_project.rb
+++ b/app/models/storage/legacy_project.rb
@@ -23,10 +23,14 @@ module Storage
project.full_path
end
+ # TODO: remove this method entirely after 12.4 https://gitlab.com/gitlab-org/gitlab/issues/33244
+ # we no longer need ensure_storage_path_exists to call add_namespace since both creating and moving
+ # repositories will be preceded by a mkdir -p in gitaly to ensure the parent of the destination directory
+ # exists.
def ensure_storage_path_exists
return unless namespace
- gitlab_shell.add_namespace(repository_storage, base_dir)
+ true
end
def rename_repo(old_full_path: nil, new_full_path: nil)
diff --git a/app/services/projects/operations/update_service.rb b/app/services/projects/operations/update_service.rb
index dd72c2844c2..64519501ff4 100644
--- a/app/services/projects/operations/update_service.rb
+++ b/app/services/projects/operations/update_service.rb
@@ -12,7 +12,9 @@ module Projects
private
def project_update_params
- error_tracking_params.merge(metrics_setting_params)
+ error_tracking_params
+ .merge(metrics_setting_params)
+ .merge(grafana_integration_params)
end
def metrics_setting_params
@@ -44,6 +46,14 @@ module Projects
}
}
end
+
+ def grafana_integration_params
+ return {} unless attrs = params[:grafana_integration_attributes]
+
+ destroy = attrs[:grafana_url].blank? && attrs[:token].blank?
+
+ { grafana_integration_attributes: attrs.merge(_destroy: destroy) }
+ end
end
end
end