diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-16 03:09:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-16 03:09:22 +0300 |
commit | cf97983af87962e678412790363bba200a2be4b1 (patch) | |
tree | 2c16fc8a32b92d6e55fbda66796c0ea59e9bea61 /app | |
parent | 2eda658f34763b651b198365550c67d073439a12 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/clusters/services/application_state_machine.js | 3 | ||||
-rw-r--r-- | app/controllers/clusters/applications_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/metrics/dashboards/annotations_finder.rb | 42 | ||||
-rw-r--r-- | app/models/clusters/applications/fluentd.rb | 101 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 4 | ||||
-rw-r--r-- | app/models/metrics/dashboard/annotation.rb | 5 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/serializers/cluster_application_entity.rb | 3 | ||||
-rw-r--r-- | app/services/clusters/applications/base_service.rb | 12 | ||||
-rw-r--r-- | app/services/groups/import_export/import_service.rb | 10 |
10 files changed, 176 insertions, 8 deletions
diff --git a/app/assets/javascripts/clusters/services/application_state_machine.js b/app/assets/javascripts/clusters/services/application_state_machine.js index 6bc4be7b93a..6af9b10f12f 100644 --- a/app/assets/javascripts/clusters/services/application_state_machine.js +++ b/app/assets/javascripts/clusters/services/application_state_machine.js @@ -191,7 +191,8 @@ const applicationStateMachine = { * @param {*} event */ const transitionApplicationState = (application, event) => { - const newState = applicationStateMachine[application.status].on[event]; + const stateMachine = applicationStateMachine[application.status]; + const newState = stateMachine !== undefined ? stateMachine.on[event] : false; return newState ? { diff --git a/app/controllers/clusters/applications_controller.rb b/app/controllers/clusters/applications_controller.rb index 3ebd248c29e..de14bd319e0 100644 --- a/app/controllers/clusters/applications_controller.rb +++ b/app/controllers/clusters/applications_controller.rb @@ -47,7 +47,7 @@ class Clusters::ApplicationsController < Clusters::BaseController end def cluster_application_params - params.permit(:application, :hostname, :pages_domain_id, :email, :stack, :modsecurity_enabled, :modsecurity_mode) + params.permit(:application, :hostname, :pages_domain_id, :email, :stack, :modsecurity_enabled, :modsecurity_mode, :host, :port, :protocol) end def cluster_application_destroy_params diff --git a/app/finders/metrics/dashboards/annotations_finder.rb b/app/finders/metrics/dashboards/annotations_finder.rb new file mode 100644 index 00000000000..c42b8bf40e5 --- /dev/null +++ b/app/finders/metrics/dashboards/annotations_finder.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Metrics + module Dashboards + class AnnotationsFinder + def initialize(dashboard:, params:) + @dashboard, @params = dashboard, params + end + + def execute + if dashboard.environment + apply_filters_to(annotations_for_environment) + else + Metrics::Dashboard::Annotation.none + end + end + + private + + attr_reader :dashboard, :params + + def apply_filters_to(annotations) + annotations = annotations.after(params[:from]) if params[:from].present? + annotations = annotations.before(params[:to]) if params[:to].present? && valid_timespan_boundaries? + + by_dashboard(annotations) + end + + def annotations_for_environment + dashboard.environment.metrics_dashboard_annotations + end + + def by_dashboard(annotations) + annotations.for_dashboard(dashboard.path) + end + + def valid_timespan_boundaries? + params[:from].blank? || params[:to] >= params[:from] + end + end + end +end diff --git a/app/models/clusters/applications/fluentd.rb b/app/models/clusters/applications/fluentd.rb new file mode 100644 index 00000000000..a33b1e39ace --- /dev/null +++ b/app/models/clusters/applications/fluentd.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +module Clusters + module Applications + class Fluentd < ApplicationRecord + VERSION = '2.4.0' + + self.table_name = 'clusters_applications_fluentd' + + include ::Clusters::Concerns::ApplicationCore + include ::Clusters::Concerns::ApplicationStatus + include ::Clusters::Concerns::ApplicationVersion + include ::Clusters::Concerns::ApplicationData + + default_value_for :version, VERSION + default_value_for :port, 514 + default_value_for :protocol, :tcp + + enum protocol: { tcp: 0, udp: 1 } + + def chart + 'stable/fluentd' + end + + def install_command + Gitlab::Kubernetes::Helm::InstallCommand.new( + name: 'fluentd', + repository: repository, + version: VERSION, + rbac: cluster.platform_kubernetes_rbac?, + chart: chart, + files: files + ) + end + + def values + content_values.to_yaml + end + + private + + def content_values + YAML.load_file(chart_values_file).deep_merge!(specification) + end + + def specification + { + "configMaps" => { + "output.conf" => output_configuration_content, + "general.conf" => general_configuration_content + } + } + end + + def output_configuration_content + <<~EOF + <match kubernetes.**> + @type remote_syslog + @id out_kube_remote_syslog + host #{host} + port #{port} + program fluentd + hostname ${kubernetes_host} + protocol #{protocol} + packet_size 65535 + <buffer kubernetes_host> + </buffer> + <format> + @type ltsv + </format> + </match> + EOF + end + + def general_configuration_content + <<~EOF + <match fluent.**> + @type null + </match> + <source> + @type http + port 9880 + bind 0.0.0.0 + </source> + <source> + @type tail + @id in_tail_container_logs + path /var/log/containers/*#{Ingress::MODSECURITY_LOG_CONTAINER_NAME}*.log + pos_file /var/log/fluentd-containers.log.pos + tag kubernetes.* + read_from_head true + <parse> + @type json + time_format %Y-%m-%dT%H:%M:%S.%NZ + </parse> + </source> + EOF + end + end + end +end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 9ef3d64f21a..430a9b3c43e 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -19,7 +19,8 @@ module Clusters Clusters::Applications::Runner.application_name => Clusters::Applications::Runner, Clusters::Applications::Jupyter.application_name => Clusters::Applications::Jupyter, Clusters::Applications::Knative.application_name => Clusters::Applications::Knative, - Clusters::Applications::ElasticStack.application_name => Clusters::Applications::ElasticStack + Clusters::Applications::ElasticStack.application_name => Clusters::Applications::ElasticStack, + Clusters::Applications::Fluentd.application_name => Clusters::Applications::Fluentd }.freeze DEFAULT_ENVIRONMENT = '*' KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN' @@ -57,6 +58,7 @@ module Clusters has_one_cluster_application :jupyter has_one_cluster_application :knative has_one_cluster_application :elastic_stack + has_one_cluster_application :fluentd has_many :kubernetes_namespaces has_many :metrics_dashboard_annotations, class_name: 'Metrics::Dashboard::Annotation', inverse_of: :cluster diff --git a/app/models/metrics/dashboard/annotation.rb b/app/models/metrics/dashboard/annotation.rb index 2f1b6527742..8166880f0c9 100644 --- a/app/models/metrics/dashboard/annotation.rb +++ b/app/models/metrics/dashboard/annotation.rb @@ -15,6 +15,11 @@ module Metrics validate :single_ownership validate :orphaned_annotation + scope :after, ->(after) { where('starting_at >= ?', after) } + scope :before, ->(before) { where('starting_at <= ?', before) } + + scope :for_dashboard, ->(dashboard_path) { where(dashboard_path: dashboard_path) } + private def single_ownership diff --git a/app/models/project.rb b/app/models/project.rb index 443b44dd023..3168def7dd8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -591,7 +591,7 @@ class Project < ApplicationRecord # # query - The search query as a String. def search(query, include_namespace: false) - if include_namespace && Feature.enabled?(:project_search_by_full_path, default_enabled: true) + if include_namespace joins(:route).fuzzy_search(query, [Route.arel_table[:path], Route.arel_table[:name], :description]) else fuzzy_search(query, [:path, :name, :description]) diff --git a/app/serializers/cluster_application_entity.rb b/app/serializers/cluster_application_entity.rb index c08691c6bcf..85a40f1f5cb 100644 --- a/app/serializers/cluster_application_entity.rb +++ b/app/serializers/cluster_application_entity.rb @@ -16,4 +16,7 @@ class ClusterApplicationEntity < Grape::Entity expose :available_domains, using: Serverless::DomainEntity, if: -> (e, _) { e.respond_to?(:available_domains) } expose :pages_domain, using: Serverless::DomainEntity, if: -> (e, _) { e.respond_to?(:pages_domain) } expose :modsecurity_mode, if: -> (e, _) { e.respond_to?(:modsecurity_mode) } + expose :host, if: -> (e, _) { e.respond_to?(:host) } + expose :port, if: -> (e, _) { e.respond_to?(:port) } + expose :protocol, if: -> (e, _) { e.respond_to?(:protocol) } end diff --git a/app/services/clusters/applications/base_service.rb b/app/services/clusters/applications/base_service.rb index bd4ce693085..86b48b5228d 100644 --- a/app/services/clusters/applications/base_service.rb +++ b/app/services/clusters/applications/base_service.rb @@ -35,6 +35,18 @@ module Clusters application.modsecurity_mode = params[:modsecurity_mode] || 0 end + if application.has_attribute?(:host) + application.host = params[:host] + end + + if application.has_attribute?(:protocol) + application.protocol = params[:protocol] + end + + if application.has_attribute?(:port) + application.port = params[:port] + end + if application.respond_to?(:oauth_application) application.oauth_application = create_oauth_application(application, request) end diff --git a/app/services/groups/import_export/import_service.rb b/app/services/groups/import_export/import_service.rb index 548a4a98dc1..f62b9d3c8a6 100644 --- a/app/services/groups/import_export/import_service.rb +++ b/app/services/groups/import_export/import_service.rb @@ -33,10 +33,12 @@ module Groups end def restorer - @restorer ||= Gitlab::ImportExport::Group::TreeRestorer.new(user: @current_user, - shared: @shared, - group: @group, - group_hash: nil) + @restorer ||= Gitlab::ImportExport::Group::LegacyTreeRestorer.new( + user: @current_user, + shared: @shared, + group: @group, + group_hash: nil + ) end def remove_import_file |