diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-31 18:10:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-31 18:10:41 +0300 |
commit | 2368893df711f330cd210005e616fc3b6003ff31 (patch) | |
tree | d48874fb1279741f8e97a7f397e46d14ac2df05f /lib | |
parent | 729eabcb410add9dbcfa46677308003dc95a64d0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/users.rb | 1 | ||||
-rw-r--r-- | lib/banzai/filter/inline_metrics_filter.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/url.rb | 58 | ||||
-rw-r--r-- | lib/tasks/pngquant.rake | 50 |
4 files changed, 50 insertions, 62 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb index 335624963aa..aa3ecf4019d 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -84,6 +84,7 @@ module API optional :created_after, type: DateTime, desc: 'Return users created after the specified time' optional :created_before, type: DateTime, desc: 'Return users created before the specified time' optional :without_projects, type: Boolean, default: false, desc: 'Filters only users without projects' + optional :exclude_internal, as: :non_internal, type: Boolean, default: false, desc: 'Filters only non internal users' all_or_none_of :extern_uid, :provider use :sort_params diff --git a/lib/banzai/filter/inline_metrics_filter.rb b/lib/banzai/filter/inline_metrics_filter.rb index 543d98e62be..2872ad7b632 100644 --- a/lib/banzai/filter/inline_metrics_filter.rb +++ b/lib/banzai/filter/inline_metrics_filter.rb @@ -10,7 +10,6 @@ module Banzai # the cost of doing a full regex match. def xpath_search "descendant-or-self::a[contains(@href,'metrics') and \ - contains(@href,'environments') and \ starts-with(@href, '#{gitlab_domain}')]" end @@ -29,7 +28,7 @@ module Banzai params['project'], params['environment'], embedded: true, - **query_params(params['url']) + **query_params(params['url']).except(:environment) ) end end diff --git a/lib/gitlab/metrics/dashboard/url.rb b/lib/gitlab/metrics/dashboard/url.rb index 160ecfb85c9..6dcc73c0f6a 100644 --- a/lib/gitlab/metrics/dashboard/url.rb +++ b/lib/gitlab/metrics/dashboard/url.rb @@ -10,20 +10,23 @@ module Gitlab QUERY_PATTERN = '(?<query>\?[a-zA-Z0-9%.()+_=-]+(&[a-zA-Z0-9%.()+_=-]+)*)?' ANCHOR_PATTERN = '(?<anchor>\#[a-z0-9_-]+)?' - OPTIONAL_DASH_PATTERN = '(?:/-)?' + DASH_PATTERN = '(?:/-)' - # Matches urls for a metrics dashboard. This could be - # either the /metrics endpoint or the /metrics_dashboard - # endpoint. + # Matches urls for a metrics dashboard. + # This regex needs to match the old metrics URL, the new metrics URL, + # and the dashboard URL (inline_metrics_redactor_filter.rb + # uses this regex to match against the dashboard URL.) # - # EX - https://<host>/<namespace>/<project>/environments/<env_id>/metrics + # EX - Old URL: https://<host>/<namespace>/<project>/environments/<env_id>/metrics + # OR + # New URL: https://<host>/<namespace>/<project>/-/metrics?environment=<env_id> + # OR + # dashboard URL: https://<host>/<namespace>/<project>/environments/<env_id>/metrics_dashboard def metrics_regex strong_memoize(:metrics_regex) do regex_for_project_metrics( %r{ - /environments - /(?<environment>\d+) - /(metrics_dashboard|metrics) + ( #{environment_metrics_regex} ) | ( #{non_environment_metrics_regex} ) }x ) end @@ -36,6 +39,7 @@ module Gitlab strong_memoize(:grafana_regex) do regex_for_project_metrics( %r{ + #{DASH_PATTERN}? /grafana /metrics_dashboard }x @@ -44,16 +48,22 @@ module Gitlab end # Matches dashboard urls for a metric chart embed - # for cluster metrics + # for cluster metrics. + # This regex needs to match the dashboard URL as well, not just the trigger URL. + # The inline_metrics_redactor_filter.rb uses this regex to match against + # the dashboard URL. # # EX - https://<host>/<namespace>/<project>/-/clusters/<cluster_id>/?group=Cluster%20Health&title=Memory%20Usage&y_label=Memory%20(GiB) + # dashboard URL - https://<host>/<namespace>/<project>/-/clusters/<cluster_id>/metrics_dashboard?group=Cluster%20Health&title=Memory%20Usage&y_label=Memory%20(GiB) def clusters_regex strong_memoize(:clusters_regex) do regex_for_project_metrics( %r{ + #{DASH_PATTERN}? /clusters /(?<cluster_id>\d+) /? + ( (/metrics) | ( /metrics_dashboard\.json ) )? }x ) end @@ -67,10 +77,11 @@ module Gitlab strong_memoize(:alert_regex) do regex_for_project_metrics( %r{ + #{DASH_PATTERN}? /prometheus /alerts /(?<alert>\d+) - /metrics_dashboard + /metrics_dashboard(\.json)? }x ) end @@ -95,16 +106,37 @@ module Gitlab private + def environment_metrics_regex + %r{ + #{DASH_PATTERN}? + /environments + /(?<environment>\d+) + /(metrics_dashboard|metrics) + }x + end + + def non_environment_metrics_regex + %r{ + #{DASH_PATTERN} + /metrics + (?= # Lookahead to ensure there is an environment query param + \? + .* + environment=(?<environment>\d+) + .* + ) + }x + end + def regex_for_project_metrics(path_suffix_pattern) %r{ - (?<url> + ^(?<url> #{gitlab_host_pattern} #{project_path_pattern} - #{OPTIONAL_DASH_PATTERN} #{path_suffix_pattern} #{QUERY_PATTERN} #{ANCHOR_PATTERN} - ) + )$ }x end diff --git a/lib/tasks/pngquant.rake b/lib/tasks/pngquant.rake index ceb4de55373..63bc1c7c16e 100644 --- a/lib/tasks/pngquant.rake +++ b/lib/tasks/pngquant.rake @@ -2,10 +2,10 @@ return if Rails.env.production? require 'png_quantizator' require 'parallel' +require_relative '../../tooling/lib/tooling/images' # The amount of variance (in bytes) allowed in # file size when testing for compression size -TOLERANCE = 10000 namespace :pngquant do # Returns an array of all images eligible for compression @@ -13,55 +13,13 @@ namespace :pngquant do Dir.glob('doc/**/*.png', File::FNM_CASEFOLD) end - # Runs pngquant on an image and optionally - # writes the result to disk - def compress_image(file, overwrite_original) - compressed_file = "#{file}.compressed" - FileUtils.copy(file, compressed_file) - - pngquant_file = PngQuantizator::Image.new(compressed_file) - - # Run the image repeatedly through pngquant until - # the change in file size is within TOLERANCE - loop do - before = File.size(compressed_file) - pngquant_file.quantize! - after = File.size(compressed_file) - break if before - after <= TOLERANCE - end - - savings = File.size(file) - File.size(compressed_file) - is_uncompressed = savings > TOLERANCE - - if is_uncompressed && overwrite_original - FileUtils.copy(compressed_file, file) - end - - FileUtils.remove(compressed_file) - - [is_uncompressed, savings] - end - - # Ensures pngquant is available and prints an error if not - def check_executable - unless system('pngquant --version', out: File::NULL) - warn( - 'Error: pngquant executable was not detected in the system.'.color(:red), - 'Download pngquant at https://pngquant.org/ and place the executable in /usr/local/bin'.color(:green) - ) - abort - end - end - desc 'GitLab | Pngquant | Compress all documentation PNG images using pngquant' task :compress do - check_executable - files = doc_images puts "Compressing #{files.size} PNG files in doc/**" Parallel.each(files) do |file| - was_uncompressed, savings = compress_image(file, true) + was_uncompressed, savings = Tooling::Image.compress_image(file) if was_uncompressed puts "#{file} was reduced by #{savings} bytes" @@ -71,13 +29,11 @@ namespace :pngquant do desc 'GitLab | Pngquant | Checks that all documentation PNG images have been compressed with pngquant' task :lint do - check_executable - files = doc_images puts "Checking #{files.size} PNG files in doc/**" uncompressed_files = Parallel.map(files) do |file| - is_uncompressed, _ = compress_image(file, false) + is_uncompressed, _ = Tooling::Image.compress_image(file, true) if is_uncompressed puts "Uncompressed file detected: ".color(:red) + file file |