Commit 850d6bc1 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 633bf6a5 88a3cf8b
......@@ -1324,6 +1324,7 @@ class MergeRequest < ApplicationRecord
variables.append(key: 'CI_MERGE_REQUEST_PROJECT_URL', value: project.web_url)
variables.append(key: 'CI_MERGE_REQUEST_TARGET_BRANCH_NAME', value: target_branch.to_s)
variables.append(key: 'CI_MERGE_REQUEST_TITLE', value: title)
variables.append(key: 'CI_MERGE_REQUEST_DESCRIPTION', value: description) if Gitlab::Ci::Features.expose_mr_description_predefined_variable?
variables.append(key: 'CI_MERGE_REQUEST_ASSIGNEES', value: assignee_username_list) if assignees.present?
variables.append(key: 'CI_MERGE_REQUEST_MILESTONE', value: milestone.title) if milestone
variables.append(key: 'CI_MERGE_REQUEST_LABELS', value: label_names.join(',')) if labels.present?
......
---
title: Add CI_MERGE_REQUEST_DESCRIPTION env variable
merge_request: 40771
author: Paul Spooren @aparcar
type: added
---
name: expose_mr_description_predefined_variable
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40771
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/243556
group: group::continuous integration
type: development
default_enabled: true
......@@ -88,7 +88,8 @@ Kubernetes-specific environment variables are detailed in the
| `CI_MERGE_REQUEST_SOURCE_PROJECT_URL` | 11.6 | all | The URL of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_TARGET_BRANCH_NAME` | 11.6 | all | The target branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_TARGET_BRANCH_SHA` | 11.9 | all | The HEAD SHA of the target branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used, the merge request is created, and the pipeline is a [merged result pipeline](../merge_request_pipelines/pipelines_for_merged_results/index.md). **(PREMIUM)** |
| `CI_MERGE_REQUEST_TITLE` | 11.9 | all | The title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_TITLE` | 11.9 | all | The title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_DESCRIPTION` | 13.3 | all | The description of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_EVENT_TYPE` | 12.3 | all | The event type of the merge request, if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Can be `detached`, `merged_result` or `merge_train`. |
| `CI_NODE_INDEX` | 11.5 | all | Index of the job in the job set. If the job is not parallelized, this variable is not set. |
| `CI_NODE_TOTAL` | 11.5 | all | Total number of instances of this job running in parallel. If the job is not parallelized, this variable is set to `1`. |
......
---
title: Add ability to track unique uses of API endpoints
merge_request: 39616
author:
type: added
......@@ -3,7 +3,6 @@
module API
class AuditEvents < ::Grape::API::Instance
include ::API::PaginationParams
use ::API::UniqueCallTracking, event_name: 'i_compliance_audit_events_api', feature: :track_unique_visits
before do
authenticated_as_admin!
......
# frozen_string_literal: true
module API
class UniqueCallTracking < Grape::Middleware::Base
def visitor_id
return context.session[:visitor_id] if context.session[:visitor_id].present?
return unless context.current_user
uuid = SecureRandom.uuid
context.session[:visitor_id] = uuid
uuid
end
def track_redis_hll_event(event_name, feature)
return unless feature_enabled?(feature)
return unless visitor_id
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(visitor_id, event_name)
end
def after
track_redis_hll_event(@options[:event_name], @options[:feature])
nil
end
private
def feature_enabled?(feature = :track_unique_visits)
Feature.enabled?(feature) && Gitlab::CurrentSettings.usage_ping_enabled?
end
end
end
......@@ -89,8 +89,6 @@ module EE
end
segment ':id/audit_events' do
use ::API::UniqueCallTracking, event_name: 'i_compliance_audit_events_api', feature: :track_unique_visits
before do
authorize! :admin_group, user_group
check_audit_events_available!(user_group)
......
......@@ -22,8 +22,6 @@ module EE
end
end
segment ':id/audit_events' do
use ::API::UniqueCallTracking, event_name: 'i_compliance_audit_events_api', feature: :track_unique_visits
before do
authorize! :admin_project, user_project
check_audit_events_available!(user_project)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::UniqueCallTracking do
describe 'i_compliance_audit_events_api', :clean_gitlab_redis_shared_state do
let_it_be(:current_user) { create(:admin) }
let_it_be(:group) { create(:group, owner_id: current_user) }
let_it_be(:project) { create(:project) }
before do
project.add_user(current_user, :maintainer)
end
context 'after calling all audit_events APIs as a single licensed user' do
before do
stub_feature_flags(track_unique_visits: true)
stub_licensed_features(admin_audit_log: true)
end
subject do
travel_to 8.days.ago do
get api('/audit_events', current_user)
get api("/groups/#{group.id}/audit_events", current_user)
get api("/projects/#{project.id}/audit_events", current_user)
end
end
it 'tracks 3 separate events' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).exactly(3).times
.with(an_instance_of(String), an_instance_of(String))
subject
end
it 'reports one unique event' do
subject
expect(Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: 'i_compliance_audit_events_api', start_date: 2.months.ago, end_date: Date.current)).to eq(1)
end
end
end
end
......@@ -83,6 +83,10 @@ module Gitlab
def self.coverage_report_view?(project)
::Feature.enabled?(:coverage_report_view, project)
end
def self.expose_mr_description_predefined_variable?
::Feature.enabled?(:ci_expose_mr_description_predefined_variable, default_enabled: true)
end
end
end
end
......
......@@ -16,11 +16,6 @@
category: compliance
redis_slot: compliance
aggregation: weekly
- name: i_compliance_audit_events_api
category: compliance
redis_slot: compliance
expiry: 42
aggregation: weekly
# Analytics category
- name: g_analytics_contribution
category: analytics
......
......@@ -1069,7 +1069,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
'g_compliance_audit_events' => 123,
'i_compliance_credential_inventory' => 123,
'i_compliance_audit_events' => 123,
'i_compliance_audit_events_api' => 123,
'compliance_unique_visits_for_any_target' => 543,
'compliance_unique_visits_for_any_target_monthly' => 987
}
......
......@@ -759,6 +759,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME' => merge_request.source_branch.to_s,
'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA' => pipeline.source_sha.to_s,
'CI_MERGE_REQUEST_TITLE' => merge_request.title,
'CI_MERGE_REQUEST_DESCRIPTION' => merge_request.description,
'CI_MERGE_REQUEST_ASSIGNEES' => merge_request.assignee_username_list,
'CI_MERGE_REQUEST_MILESTONE' => milestone.title,
'CI_MERGE_REQUEST_LABELS' => labels.map(&:title).sort.join(','),
......
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