diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 06:08:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 06:08:02 +0300 |
commit | ed73d4f207ef6cb8646719baa1188d096c9f3139 (patch) | |
tree | dea7ab9906154c73204a0361163e30500f929d44 /app | |
parent | 2349eabc1a473bfb70555f0ce6d3d808cecb181d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/pages/snippets/show/index.js | 12 | ||||
-rw-r--r-- | app/finders/clusters/knative_serving_namespace_finder.rb | 17 | ||||
-rw-r--r-- | app/finders/clusters/knative_version_role_binding_finder.rb | 6 | ||||
-rw-r--r-- | app/finders/deployments_finder.rb | 26 | ||||
-rw-r--r-- | app/models/clusters/applications/prometheus.rb | 6 | ||||
-rw-r--r-- | app/models/concerns/prometheus_adapter.rb | 8 | ||||
-rw-r--r-- | app/models/environment.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 14 | ||||
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 4 | ||||
-rw-r--r-- | app/models/upload.rb | 15 | ||||
-rw-r--r-- | app/services/clusters/kubernetes/create_or_update_service_account_service.rb | 6 | ||||
-rw-r--r-- | app/views/snippets/show.html.haml | 17 | ||||
-rw-r--r-- | app/workers/hashed_storage/project_migrate_worker.rb | 2 |
13 files changed, 110 insertions, 27 deletions
diff --git a/app/assets/javascripts/pages/snippets/show/index.js b/app/assets/javascripts/pages/snippets/show/index.js index 26936110402..5efcc901fde 100644 --- a/app/assets/javascripts/pages/snippets/show/index.js +++ b/app/assets/javascripts/pages/snippets/show/index.js @@ -5,9 +5,11 @@ import initNotes from '~/init_notes'; import snippetEmbed from '~/snippet/snippet_embed'; document.addEventListener('DOMContentLoaded', () => { - new LineHighlighter(); // eslint-disable-line no-new - new BlobViewer(); // eslint-disable-line no-new - initNotes(); - new ZenMode(); // eslint-disable-line no-new - snippetEmbed(); + if (!gon.features.snippetsVue) { + new LineHighlighter(); // eslint-disable-line no-new + new BlobViewer(); // eslint-disable-line no-new + initNotes(); + new ZenMode(); // eslint-disable-line no-new + snippetEmbed(); + } }); diff --git a/app/finders/clusters/knative_serving_namespace_finder.rb b/app/finders/clusters/knative_serving_namespace_finder.rb new file mode 100644 index 00000000000..d3db5be558c --- /dev/null +++ b/app/finders/clusters/knative_serving_namespace_finder.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Clusters + class KnativeServingNamespaceFinder + attr_reader :cluster + + def initialize(cluster) + @cluster = cluster + end + + def execute + cluster.kubeclient&.get_namespace(Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE) + rescue Kubeclient::ResourceNotFoundError + nil + end + end +end diff --git a/app/finders/clusters/knative_version_role_binding_finder.rb b/app/finders/clusters/knative_version_role_binding_finder.rb index 06ec5ea557f..26f5492840a 100644 --- a/app/finders/clusters/knative_version_role_binding_finder.rb +++ b/app/finders/clusters/knative_version_role_binding_finder.rb @@ -9,9 +9,9 @@ module Clusters end def execute - cluster&.kubeclient&.get_cluster_role_bindings&.find do |resource| - resource.metadata.name == Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME - end + cluster.kubeclient&.get_cluster_role_binding(Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME) + rescue Kubeclient::ResourceNotFoundError + nil end end end diff --git a/app/finders/deployments_finder.rb b/app/finders/deployments_finder.rb index 085c6a04fa6..b718b55dd68 100644 --- a/app/finders/deployments_finder.rb +++ b/app/finders/deployments_finder.rb @@ -22,9 +22,28 @@ class DeploymentsFinder private + # rubocop: disable CodeReuse/ActiveRecord def init_collection - project.deployments + project + .deployments + .includes( + :user, + environment: [], + deployable: { + job_artifacts: [], + pipeline: { + project: { + route: [], + namespace: :route + } + }, + project: { + namespace: :route + } + } + ) end + # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord def sort(items) @@ -43,6 +62,9 @@ class DeploymentsFinder order_by = ALLOWED_SORT_VALUES.include?(params[:order_by]) ? params[:order_by] : DEFAULT_SORT_VALUE order_direction = ALLOWED_SORT_DIRECTIONS.include?(params[:sort]) ? params[:sort] : DEFAULT_SORT_DIRECTION - { order_by => order_direction } + { order_by => order_direction }.tap do |sort_values| + sort_values['id'] = 'desc' if sort_values['updated_at'] + sort_values['id'] = sort_values.delete('created_at') if sort_values['created_at'] # Sorting by `id` produces the same result as sorting by `created_at` + end end end diff --git a/app/models/clusters/applications/prometheus.rb b/app/models/clusters/applications/prometheus.rb index 5e7fdd55cb6..91ffdac3273 100644 --- a/app/models/clusters/applications/prometheus.rb +++ b/app/models/clusters/applications/prometheus.rb @@ -84,13 +84,17 @@ module Clusters # ensures headers containing auth data are appended to original k8s client options options = kube_client.rest_client.options.merge(headers: kube_client.headers) Gitlab::PrometheusClient.new(proxy_url, options) - rescue Kubeclient::HttpError + rescue Kubeclient::HttpError, Errno::ECONNRESET, Errno::ECONNREFUSED # If users have mistakenly set parameters or removed the depended clusters, # `proxy_url` could raise an exception because gitlab can not communicate with the cluster. # Since `PrometheusAdapter#can_query?` is eargely loaded on environement pages in gitlab, # we need to silence the exceptions end + def configured? + kube_client.present? && available? + end + private def disable_prometheus_integration diff --git a/app/models/concerns/prometheus_adapter.rb b/app/models/concerns/prometheus_adapter.rb index 9df77b565da..99da8b81398 100644 --- a/app/models/concerns/prometheus_adapter.rb +++ b/app/models/concerns/prometheus_adapter.rb @@ -16,6 +16,14 @@ module PrometheusAdapter raise NotImplementedError end + # This is a light-weight check if a prometheus client is properly configured. + def configured? + raise NotImplemented + end + + # This is a heavy-weight check if a prometheus is properly configured and accesible from GitLab. + # This actually sends a request to an external service and often it could take a long time, + # Please consider using `configured?` instead if the process is running on unicorn/puma threads. def can_query? prometheus_client.present? end diff --git a/app/models/environment.rb b/app/models/environment.rb index 327b1e594d7..fec1f034d63 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -193,11 +193,11 @@ class Environment < ApplicationRecord end def has_metrics? - available? && prometheus_adapter&.can_query? + available? && prometheus_adapter&.configured? end def metrics - prometheus_adapter.query(:environment, self) if has_metrics? + prometheus_adapter.query(:environment, self) if has_metrics? && prometheus_adapter.can_query? end def prometheus_status diff --git a/app/models/project.rb b/app/models/project.rb index 03a99577d5c..301fcfc8c98 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -374,9 +374,17 @@ class Project < ApplicationRecord scope :pending_delete, -> { where(pending_delete: true) } scope :without_deleted, -> { where(pending_delete: false) } - scope :with_storage_feature, ->(feature) { where('storage_version >= :version', version: HASHED_STORAGE_FEATURES[feature]) } - scope :without_storage_feature, ->(feature) { where('storage_version < :version OR storage_version IS NULL', version: HASHED_STORAGE_FEATURES[feature]) } - scope :with_unmigrated_storage, -> { where('storage_version < :version OR storage_version IS NULL', version: LATEST_STORAGE_VERSION) } + scope :with_storage_feature, ->(feature) do + where(arel_table[:storage_version].gteq(HASHED_STORAGE_FEATURES[feature])) + end + scope :without_storage_feature, ->(feature) do + where(arel_table[:storage_version].lt(HASHED_STORAGE_FEATURES[feature]) + .or(arel_table[:storage_version].eq(nil))) + end + scope :with_unmigrated_storage, -> do + where(arel_table[:storage_version].lt(LATEST_STORAGE_VERSION) + .or(arel_table[:storage_version].eq(nil))) + end # last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push scope :sorted_by_activity, -> { reorder(Arel.sql("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC")) } diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb index 3e0606fd34a..2ca74b081aa 100644 --- a/app/models/project_services/prometheus_service.rb +++ b/app/models/project_services/prometheus_service.rb @@ -95,6 +95,10 @@ class PrometheusService < MonitoringService self_monitoring_project? && internal_prometheus_url? end + def configured? + should_return_client? + end + private def self_monitoring_project? diff --git a/app/models/upload.rb b/app/models/upload.rb index 8c409641452..650321e2793 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -23,6 +23,21 @@ class Upload < ApplicationRecord after_destroy :delete_file!, if: -> { uploader_class <= FileUploader } class << self + def inner_join_local_uploads_projects + upload_table = Upload.arel_table + project_table = Project.arel_table + + join_statement = upload_table.project(upload_table[Arel.star]) + .join(project_table) + .on( + upload_table[:model_type].eq('Project') + .and(upload_table[:model_id].eq(project_table[:id])) + .and(upload_table[:store].eq(ObjectStorage::Store::LOCAL)) + ) + + joins(join_statement.join_sources) + end + ## # FastDestroyAll concerns def begin_fast_destroy diff --git a/app/services/clusters/kubernetes/create_or_update_service_account_service.rb b/app/services/clusters/kubernetes/create_or_update_service_account_service.rb index 0fea398d234..046046bf5a3 100644 --- a/app/services/clusters/kubernetes/create_or_update_service_account_service.rb +++ b/app/services/clusters/kubernetes/create_or_update_service_account_service.rb @@ -71,9 +71,9 @@ module Clusters end def knative_serving_namespace - kubeclient.core_client.get_namespaces.find do |namespace| - namespace.metadata.name == Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE - end + kubeclient.get_namespace(Clusters::Kubernetes::KNATIVE_SERVING_NAMESPACE) + rescue Kubeclient::ResourceNotFoundError + nil end def create_role_or_cluster_role_binding diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml index 36b4e00e8d5..c77b05e3ea8 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -4,13 +4,16 @@ - breadcrumb_title @snippet.to_reference - page_title "#{@snippet.title} (#{@snippet.to_reference})", _("Snippets") -= render 'shared/snippets/header' +- if Feature.enabled?(:snippets_vue) + #js-snippet-view{ 'data-qa-selector': 'snippet_view' } +- else + = render 'shared/snippets/header' -.personal-snippets - %article.file-holder.snippet-file-content - = render 'shared/snippets/blob' + .personal-snippets + %article.file-holder.snippet-file-content + = render 'shared/snippets/blob' - .row-content-block.top-block.content-component-block - = render 'award_emoji/awards_block', awardable: @snippet, inline: true + .row-content-block.top-block.content-component-block + = render 'award_emoji/awards_block', awardable: @snippet, inline: true - #notes.limited-width-notes= render "shared/notes/notes_with_form", :autocomplete => false + #notes.limited-width-notes= render "shared/notes/notes_with_form", :autocomplete => false diff --git a/app/workers/hashed_storage/project_migrate_worker.rb b/app/workers/hashed_storage/project_migrate_worker.rb index 8c0ec97638f..0174467923d 100644 --- a/app/workers/hashed_storage/project_migrate_worker.rb +++ b/app/workers/hashed_storage/project_migrate_worker.rb @@ -14,7 +14,7 @@ module HashedStorage try_obtain_lease do project = Project.without_deleted.find_by(id: project_id) - break unless project + break unless project && project.storage_upgradable? old_disk_path ||= Storage::LegacyProject.new(project).disk_path |