summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 21:08:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 21:08:00 +0000
commit69d6d3ca2013e97cfd2d89449669ea7bf475f4e9 (patch)
tree2cc4227ebfc52b7603691f06b0b8e09e030e8428 /lib
parent01fdcf49b1553c22ae116fe96cedd7b91d02225c (diff)
downloadgitlab-ce-69d6d3ca2013e97cfd2d89449669ea7bf475f4e9.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/banzai/filter/inline_metrics_redactor_filter.rb10
-rw-r--r--lib/gitlab/diff/file_collection/base.rb2
-rw-r--r--lib/gitlab/kubernetes/helm/client_command.rb4
-rw-r--r--lib/gitlab/kubernetes/helm/install_command.rb4
-rw-r--r--lib/gitlab/kubernetes/helm/patch_command.rb73
-rw-r--r--lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb20
-rw-r--r--lib/tasks/gitlab/generate_sample_prometheus_data.rake20
7 files changed, 121 insertions, 12 deletions
diff --git a/lib/banzai/filter/inline_metrics_redactor_filter.rb b/lib/banzai/filter/inline_metrics_redactor_filter.rb
index e84ba83e03e..c70897fccbf 100644
--- a/lib/banzai/filter/inline_metrics_redactor_filter.rb
+++ b/lib/banzai/filter/inline_metrics_redactor_filter.rb
@@ -8,6 +8,7 @@ module Banzai
include Gitlab::Utils::StrongMemoize
METRICS_CSS_CLASS = '.js-render-metrics'
+ EMBED_LIMIT = 100
URL = Gitlab::Metrics::Dashboard::Url
Embed = Struct.new(:project_path, :permission)
@@ -35,9 +36,16 @@ module Banzai
# Returns all nodes which the FE will identify as
# a metrics embed placeholder element
#
+ # Removes any nodes beyond the first 100
+ #
# @return [Nokogiri::XML::NodeSet]
def nodes
- @nodes ||= doc.css(METRICS_CSS_CLASS)
+ strong_memoize(:nodes) do
+ nodes = doc.css(METRICS_CSS_CLASS)
+ nodes.drop(EMBED_LIMIT).each(&:remove)
+
+ nodes
+ end
end
# Maps a node to key properties of an embed.
diff --git a/lib/gitlab/diff/file_collection/base.rb b/lib/gitlab/diff/file_collection/base.rb
index b1f171c0e7d..38b636e4e5a 100644
--- a/lib/gitlab/diff/file_collection/base.rb
+++ b/lib/gitlab/diff/file_collection/base.rb
@@ -8,7 +8,7 @@ module Gitlab
attr_reader :project, :diff_options, :diff_refs, :fallback_diff_refs, :diffable
- delegate :count, :size, :real_size, to: :diff_files
+ delegate :count, :size, :real_size, to: :raw_diff_files
def self.default_options
::Commit.max_diff_options.merge(ignore_whitespace_change: false, expanded: false, include_stats: true)
diff --git a/lib/gitlab/kubernetes/helm/client_command.rb b/lib/gitlab/kubernetes/helm/client_command.rb
index df3f35d1075..b953ce24c4a 100644
--- a/lib/gitlab/kubernetes/helm/client_command.rb
+++ b/lib/gitlab/kubernetes/helm/client_command.rb
@@ -43,6 +43,10 @@ module Gitlab
optional_tls_flags
end
+ def repository_update_command
+ 'helm repo update'
+ end
+
def optional_tls_flags
return [] unless files.key?(:'ca.pem')
diff --git a/lib/gitlab/kubernetes/helm/install_command.rb b/lib/gitlab/kubernetes/helm/install_command.rb
index 82f6f5d0024..8e24cb4c24f 100644
--- a/lib/gitlab/kubernetes/helm/install_command.rb
+++ b/lib/gitlab/kubernetes/helm/install_command.rb
@@ -39,10 +39,6 @@ module Gitlab
private
- def repository_update_command
- 'helm repo update'
- end
-
# Uses `helm upgrade --install` which means we can use this for both
# installation and uprade of applications
def install_command
diff --git a/lib/gitlab/kubernetes/helm/patch_command.rb b/lib/gitlab/kubernetes/helm/patch_command.rb
new file mode 100644
index 00000000000..ed7a5c2b2d6
--- /dev/null
+++ b/lib/gitlab/kubernetes/helm/patch_command.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+# PatchCommand is for updating values in installed charts without overwriting
+# existing values.
+module Gitlab
+ module Kubernetes
+ module Helm
+ class PatchCommand
+ include BaseCommand
+ include ClientCommand
+
+ attr_reader :name, :files, :chart, :repository
+ attr_accessor :version
+
+ def initialize(name:, chart:, files:, rbac:, version:, repository: nil)
+ # version is mandatory to prevent chart mismatches
+ # we do not want our values interpreted in the context of the wrong version
+ raise ArgumentError, 'version is required' if version.blank?
+
+ @name = name
+ @chart = chart
+ @version = version
+ @rbac = rbac
+ @files = files
+ @repository = repository
+ end
+
+ def generate_script
+ super + [
+ init_command,
+ wait_for_tiller_command,
+ repository_command,
+ repository_update_command,
+ upgrade_command
+ ].compact.join("\n")
+ end
+
+ def rbac?
+ @rbac
+ end
+
+ private
+
+ def upgrade_command
+ command = ['helm', 'upgrade', name, chart] +
+ reuse_values_flag +
+ tls_flags_if_remote_tiller +
+ version_flag +
+ namespace_flag +
+ value_flag
+
+ command.shelljoin
+ end
+
+ def reuse_values_flag
+ ['--reuse-values']
+ end
+
+ def value_flag
+ ['-f', "/data/helm/#{name}/config/values.yaml"]
+ end
+
+ def namespace_flag
+ ['--namespace', Gitlab::Kubernetes::Helm::NAMESPACE]
+ end
+
+ def version_flag
+ ['--version', version]
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
index c00ef208848..4f5e9a98799 100644
--- a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
+++ b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
@@ -16,12 +16,20 @@ module Gitlab
private
def endpoint_for_metric(metric)
- Gitlab::Routing.url_helpers.prometheus_api_project_environment_path(
- project,
- params[:environment],
- proxy_path: query_type(metric),
- query: query_for_metric(metric)
- )
+ if ENV['USE_SAMPLE_METRICS']
+ Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
+ project,
+ params[:environment],
+ identifier: metric[:id]
+ )
+ else
+ Gitlab::Routing.url_helpers.prometheus_api_project_environment_path(
+ project,
+ params[:environment],
+ proxy_path: query_type(metric),
+ query: query_for_metric(metric)
+ )
+ end
end
def query_type(metric)
diff --git a/lib/tasks/gitlab/generate_sample_prometheus_data.rake b/lib/tasks/gitlab/generate_sample_prometheus_data.rake
new file mode 100644
index 00000000000..a988494ca61
--- /dev/null
+++ b/lib/tasks/gitlab/generate_sample_prometheus_data.rake
@@ -0,0 +1,20 @@
+namespace :gitlab do
+ desc "GitLab | Generate Sample Prometheus Data"
+ task :generate_sample_prometheus_data, [:environment_id] => :gitlab_environment do |_, args|
+ environment = Environment.find(args[:environment_id])
+ metrics = PrometheusMetric.where(project_id: [environment.project.id, nil])
+ query_variables = Gitlab::Prometheus::QueryVariables.call(environment)
+
+ sample_metrics_directory_name = Metrics::SampleMetricsService::DIRECTORY
+ FileUtils.mkdir_p(sample_metrics_directory_name)
+
+ metrics.each do |metric|
+ query = metric.query % query_variables
+ result = environment.prometheus_adapter.prometheus_client.query_range(query, start: 7.days.ago)
+
+ next unless metric.identifier
+
+ File.write("#{sample_metrics_directory_name}/#{metric.identifier}.yml", result.to_yaml)
+ end
+ end
+end