Commit 41e89139 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent e16f446a7a29
# frozen_string_literal: true
module RenderServiceResults
extend ActiveSupport::Concern
def success_response(result)
render({
status: result[:http_status],
json: result[:body]
})
end
def continue_polling_response
render({
status: :no_content,
json: {
status: _('processing'),
message: _('Not ready yet. Try again later.')
}
})
end
def error_response(result)
render({
status: result[:http_status] || :bad_request,
json: { status: result[:status], message: result[:message] }
})
end
end
# frozen_string_literal: true
class Projects::Environments::PrometheusApiController < Projects::ApplicationController
include RenderServiceResults
before_action :authorize_read_prometheus!
before_action :environment
......@@ -12,21 +14,10 @@ def proxy
proxy_params
).execute
if result.nil?
return render status: :no_content, json: {
status: _('processing'),
message: _('Not ready yet. Try again later.')
}
end
if result[:status] == :success
render status: result[:http_status], json: result[:body]
else
render(
status: result[:http_status] || :bad_request,
json: { status: result[:status], message: result[:message] }
)
end
return continue_polling_response if result.nil?
return error_response(result) if result[:status] == :error
success_response(result)
end
private
......
# frozen_string_literal: true
class Projects::GrafanaApiController < Projects::ApplicationController
include RenderServiceResults
def proxy
result = ::Grafana::ProxyService.new(
project,
params[:datasource_id],
params[:proxy_path],
query_params.to_h
).execute
return continue_polling_response if result.nil?
return error_response(result) if result[:status] == :error
success_response(result)
end
private
def query_params
params.permit(:query, :start, :end, :step)
end
end
......@@ -7,7 +7,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
before_action :apply_diff_view_cookie!
before_action :commit, except: :diffs_batch
before_action :define_diff_vars, except: :diffs_batch
before_action :define_diff_comment_vars, except: :diffs_batch
before_action :define_diff_comment_vars, except: [:diffs_batch, :diffs_metadata]
def show
render_diffs
......@@ -37,6 +37,11 @@ def diffs_batch
render json: PaginatedDiffSerializer.new(current_user: current_user).represent(diffs, options)
end
def diffs_metadata
render json: DiffsMetadataSerializer.new(project: @merge_request.project)
.represent(@diffs, additional_attributes)
end
private
def preloadable_mr_relations
......
......@@ -203,8 +203,8 @@ def toggle_whitespace_link(url, options)
link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class]
end
def render_overflow_warning?(diff_files)
diffs = @merge_request_diff.presence || diff_files
def render_overflow_warning?(diffs_collection)
diffs = @merge_request_diff.presence || diffs_collection.diff_files
diffs.overflow?
end
......
......@@ -13,4 +13,8 @@ class GrafanaIntegration < ApplicationRecord
addressable_url: { enforce_sanitization: true, ascii_only: true }
validates :token, :project, presence: true
def client
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
end
end
......@@ -7,7 +7,7 @@ class RepositoryLanguage < ApplicationRecord
default_scope { includes(:programming_language) }
validates :project, presence: true
validates :share, inclusion: { in: 0..100, message: "The share of a lanuage is between 0 and 100" }
validates :share, inclusion: { in: 0..100, message: "The share of a language is between 0 and 100" }
validates :programming_language, uniqueness: { scope: :project_id }
delegate :name, :color, to: :programming_language
......
# frozen_string_literal: true
class DiffFileMetadataEntity < Grape::Entity
expose :added_lines
expose :removed_lines
expose :new_path
expose :old_path
expose :new_file?, as: :new_file
expose :deleted_file?, as: :deleted_file
end
......@@ -53,7 +53,7 @@ class DiffsEntity < Grape::Entity
# rubocop: enable CodeReuse/ActiveRecord
expose :render_overflow_warning do |diffs|
render_overflow_warning?(diffs.diff_files)
render_overflow_warning?(diffs)
end
expose :email_patch_path, if: -> (*) { merge_request } do |diffs|
......
# frozen_string_literal: true
class DiffsMetadataEntity < DiffsEntity
unexpose :diff_files
expose :diff_files, using: DiffFileMetadataEntity
end
# frozen_string_literal: true
class DiffsMetadataSerializer < BaseSerializer
entity DiffsMetadataEntity
end
# frozen_string_literal: true
# Proxies calls to a Grafana-integrated Prometheus instance
# through the Grafana proxy API
# This allows us to fetch and render metrics in GitLab from a Prometheus
# instance for which dashboards are configured in Grafana
module Grafana
class ProxyService < BaseService
include ReactiveCaching
self.reactive_cache_key = ->(service) { service.cache_key }
self.reactive_cache_lease_timeout = 30.seconds
self.reactive_cache_refresh_interval = 30.seconds
self.reactive_cache_worker_finder = ->(_id, *args) { from_cache(*args) }
attr_accessor :project, :datasource_id, :proxy_path, :query_params
# @param project_id [Integer] Project id for which grafana is configured.
#
# See #initialize for other parameters.
def self.from_cache(project_id, datasource_id, proxy_path, query_params)
project = Project.find(project_id)
new(project, datasource_id, proxy_path, query_params)
end
# @param project [Project] Project for which grafana is configured.
# @param datasource_id [String] Grafana datasource id for Prometheus instance
# @param proxy_path [String] Path to Prometheus endpoint; EX) 'api/v1/query_range'
# @param query_params [Hash<String, String>] Supported params: [query, start, end, step]
def initialize(project, datasource_id, proxy_path, query_params)
@project = project
@datasource_id = datasource_id
@proxy_path = proxy_path
@query_params = query_params
end
def execute
return cannot_proxy_response unless client
with_reactive_cache(*cache_key) { |result| result }
end
def calculate_reactive_cache(*)
return cannot_proxy_response unless client
response = client.proxy_datasource(
datasource_id: datasource_id,
proxy_path: proxy_path,
query: query_params
)
success(http_status: response.code, body: response.body)
rescue ::Grafana::Client::Error => error
service_unavailable_response(error)
end
# Required for ReactiveCaching; Usage overridden by
# self.reactive_cache_worker_finder
def id
nil
end
def cache_key
[project.id, datasource_id, proxy_path, query_params]
end
private
def client
project.grafana_integration&.client
end
def service_unavailable_response(exception)
error(exception.message, :service_unavailable)
end
def cannot_proxy_response
error('Proxy support for this API is not available currently')
end
end
end
......@@ -21,7 +21,7 @@
= parallel_diff_btn
= render 'projects/diffs/stats', diff_files: diff_files
- if render_overflow_warning?(diff_files)
- if render_overflow_warning?(diffs)
= render 'projects/diffs/warning', diff_files: diffs
.files{ data: { can_create_note: can_create_note } }
......
---
title: Schedule background migration to populate pages metadata
merge_request: 17993
author:
type: added
---
title: Create clusters with VPC-Native enabled
merge_request: 18284
author:
type: changed
---
title: Introduce a lightweight diffs_metadata endpoint
merge_request: 18104
author:
type: added
---
title: Add endpoint to proxy requests to grafana's proxy endpoint
merge_request: 18210
author:
type: added
......@@ -186,6 +186,10 @@
resource :import, only: [:new, :create, :show]
resource :avatar, only: [:show, :destroy]
get 'grafana/proxy/:datasource_id/*proxy_path',
to: 'grafana_api#proxy',
as: :grafana_api
end
# End of the /-/ scope.
......@@ -282,6 +286,7 @@
get :pipelines
get :diffs, to: 'merge_requests/diffs#show'
get :diffs_batch, to: 'merge_requests/diffs#diffs_batch'
get :diffs_metadata, to: 'merge_requests/diffs#diffs_metadata'
get :widget, to: 'merge_requests/content#widget'
get :cached_widget, to: 'merge_requests/content#cached_widget'
end
......
# frozen_string_literal: true
class SchedulePagesMetadataMigration < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 10_000
MIGRATION = 'MigratePagesMetadata'
disable_ddl_transaction!
class Project < ActiveRecord::Base
include ::EachBatch
self.table_name = 'projects'
end
def up
say "Scheduling `#{MIGRATION}` jobs"
# At the time of writing there are ~10_669_292 records to be inserted for GitLab.com,
# batches of 10_000 with delay interval of 2 minutes gives us an estimate of close to 36 hours.
queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE)
end
def down
# no-op
end
end
......@@ -96,6 +96,9 @@ def make_cluster_options(cluster_name, cluster_size, machine_type, legacy_abac,
legacy_abac: {
enabled: legacy_abac
},
ip_allocation_policy: {
use_ip_aliases: true
},
addons_config: enable_addons.each_with_object({}) do |addon, hash|
hash[addon] = { disabled: false }
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment