Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
b296ffa543
commit
537882ad40
39 changed files with 271 additions and 76 deletions
|
@ -312,7 +312,6 @@ module ApplicationSettingsHelper
|
|||
:snowplow_cookie_domain,
|
||||
:snowplow_enabled,
|
||||
:snowplow_app_id,
|
||||
:snowplow_iglu_registry_url,
|
||||
:push_event_hooks_limit,
|
||||
:push_event_activities_limit,
|
||||
:custom_http_clone_url_root,
|
||||
|
|
|
@ -9,6 +9,7 @@ class ApplicationSetting < ApplicationRecord
|
|||
|
||||
ignore_column :namespace_storage_size_limit, remove_with: '13.5', remove_after: '2020-09-22'
|
||||
ignore_column :instance_statistics_visibility_private, remove_with: '13.6', remove_after: '2020-10-22'
|
||||
ignore_column :snowplow_iglu_registry_url, remove_with: '13.6', remove_after: '2020-11-22'
|
||||
|
||||
GRAFANA_URL_ERROR_MESSAGE = 'Please check your Grafana URL setting in ' \
|
||||
'Admin Area > Settings > Metrics and profiling > Metrics - Grafana'
|
||||
|
@ -134,11 +135,6 @@ class ApplicationSetting < ApplicationRecord
|
|||
hostname: true,
|
||||
if: :snowplow_enabled
|
||||
|
||||
validates :snowplow_iglu_registry_url,
|
||||
addressable_url: true,
|
||||
allow_blank: true,
|
||||
if: :snowplow_enabled
|
||||
|
||||
validates :max_attachment_size,
|
||||
presence: true,
|
||||
numericality: { only_integer: true, greater_than: 0 }
|
||||
|
|
|
@ -131,7 +131,6 @@ module ApplicationSettingImplementation
|
|||
snowplow_collector_hostname: nil,
|
||||
snowplow_cookie_domain: nil,
|
||||
snowplow_enabled: false,
|
||||
snowplow_iglu_registry_url: nil,
|
||||
sourcegraph_enabled: false,
|
||||
sourcegraph_public_only: true,
|
||||
sourcegraph_url: nil,
|
||||
|
|
|
@ -8,6 +8,10 @@ class GroupDeployKey < Key
|
|||
|
||||
validates :user, presence: true
|
||||
|
||||
scope :for_groups, ->(group_ids) do
|
||||
joins(:group_deploy_keys_groups).where(group_deploy_keys_groups: { group_id: group_ids }).uniq
|
||||
end
|
||||
|
||||
def type
|
||||
'DeployKey'
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@ class ProductAnalyticsEvent < ApplicationRecord
|
|||
where('collector_tstamp BETWEEN ? AND ? ', today - duration + 1, today + 1)
|
||||
}
|
||||
|
||||
scope :by_category_and_action, ->(category, action) { where(se_category: category, se_action: action) }
|
||||
|
||||
def self.count_by_graph(graph, days)
|
||||
group(graph).timerange(days).count
|
||||
end
|
||||
|
|
|
@ -2526,6 +2526,12 @@ class Project < ApplicationRecord
|
|||
ci_config_path.presence || Ci::Pipeline::DEFAULT_CONFIG_PATH
|
||||
end
|
||||
|
||||
def enabled_group_deploy_keys
|
||||
return GroupDeployKey.none unless group
|
||||
|
||||
GroupDeployKey.for_groups(group.self_and_ancestors_ids)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_service(services, name)
|
||||
|
|
|
@ -25,8 +25,5 @@
|
|||
.form-group
|
||||
= f.label :snowplow_cookie_domain, _('Cookie domain'), class: 'label-light'
|
||||
= f.text_field :snowplow_cookie_domain, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :snowplow_iglu_registry_url, _('Iglu registry URL (optional)'), class: 'label-light'
|
||||
= f.text_field :snowplow_iglu_registry_url, class: 'form-control'
|
||||
|
||||
= f.submit _('Save changes'), class: 'btn btn-success'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Make the auto_link_user OmniAuth setting configurable by provider
|
||||
merge_request: 41133
|
||||
author:
|
||||
type: added
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Remove application settings for Snowplow iglu registry url
|
||||
merge_request: 41556
|
||||
author:
|
||||
type: removed
|
5
changelogs/unreleased/app-logger-10.yml
Normal file
5
changelogs/unreleased/app-logger-10.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Use applogger in some files in lib/gitlab
|
||||
merge_request: 41058
|
||||
author: Rajendra Kadam
|
||||
type: other
|
5
changelogs/unreleased/app-logger-14.yml
Normal file
5
changelogs/unreleased/app-logger-14.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Use applogger in lib/gitlab/
|
||||
merge_request: 41071
|
||||
author: Rajendra Kadam
|
||||
type: other
|
|
@ -890,8 +890,10 @@ production: &base
|
|||
|
||||
# Allow users with existing accounts to sign in and auto link their account via OmniAuth
|
||||
# login, without having to do a manual login first and manually add OmniAuth. Links on email.
|
||||
# Define the allowed providers using an array, e.g. ["saml", "twitter"], or as true/false to
|
||||
# allow all providers or none.
|
||||
# (default: false)
|
||||
auto_link_user: false
|
||||
auto_link_user: ["saml", "twitter"]
|
||||
|
||||
# Set different Omniauth providers as external so that all users creating accounts
|
||||
# via these providers will not be able to have access to internal projects. You
|
||||
|
|
|
@ -7,7 +7,8 @@ Gitlab::Seeder.quiet do
|
|||
username: 'root',
|
||||
password: '5iveL!fe',
|
||||
admin: true,
|
||||
confirmed_at: DateTime.now
|
||||
confirmed_at: DateTime.now,
|
||||
password_expires_at: DateTime.now
|
||||
)
|
||||
|
||||
print '.'
|
||||
|
|
|
@ -109,7 +109,6 @@ We recommend using the [consolidated object storage settings](../object_storage.
|
|||
|
||||
```ruby
|
||||
gitlab_rails['packages_enabled'] = true
|
||||
gitlab_rails['packages_storage_path'] = "/var/opt/gitlab/gitlab-rails/shared/packages"
|
||||
gitlab_rails['packages_object_store_enabled'] = true
|
||||
gitlab_rails['packages_object_store_remote_directory'] = "packages" # The bucket name.
|
||||
gitlab_rails['packages_object_store_direct_upload'] = false # Use Object Storage directly for uploads instead of background uploads if enabled (Default: false).
|
||||
|
@ -123,6 +122,8 @@ We recommend using the [consolidated object storage settings](../object_storage.
|
|||
#'region' => 'eu-west-1',
|
||||
#'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
|
||||
#'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY',
|
||||
## If an IAM profile is being used with AWS, omit the aws_access_key_id and aws_secret_access_key and uncomment
|
||||
#'use_iam_profile' => true,
|
||||
##
|
||||
## If the provider is other than AWS (an S3-compatible one), uncomment the following
|
||||
##
|
||||
|
|
|
@ -343,7 +343,6 @@ are listed in the descriptions of the relevant settings.
|
|||
| `snowplow_collector_hostname` | string | required by: `snowplow_enabled` | The Snowplow collector hostname. (for example, `snowplow.trx.gitlab.net`) |
|
||||
| `snowplow_cookie_domain` | string | no | The Snowplow cookie domain. (for example, `.gitlab.com`) |
|
||||
| `snowplow_enabled` | boolean | no | Enable snowplow tracking. |
|
||||
| `snowplow_iglu_registry_url` | string | no | The Snowplow base Iglu Schema Registry URL to use for custom context and self describing events'|
|
||||
| `sourcegraph_enabled` | boolean | no | Enables Sourcegraph integration. Default is `false`. **If enabled, requires** `sourcegraph_url`. |
|
||||
| `sourcegraph_public_only` | boolean | no | Blocks Sourcegraph from being loaded on private and internal projects. Default is `true`. |
|
||||
| `sourcegraph_url` | string | required by: `sourcegraph_enabled` | The Sourcegraph instance URL for integration. |
|
||||
|
|
|
@ -144,19 +144,20 @@ The chosen OmniAuth provider is now active and can be used to sign in to GitLab
|
|||
|
||||
> [Introduced in GitLab 13.4.](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36664)
|
||||
|
||||
You can automatically link OmniAuth users with existing GitLab users if their email addresses match by adding the following setting:
|
||||
You can automatically link OmniAuth users with existing GitLab users if their email addresses match.
|
||||
For example, the following setting is used to enable the auto link feature for both a SAML provider and the Twitter OAuth provider:
|
||||
|
||||
**For Omnibus installations**
|
||||
|
||||
```ruby
|
||||
gitlab_rails['omniauth_auto_link_user'] = true
|
||||
gitlab_rails['omniauth_auto_link_user'] = ["saml", "twitter"]
|
||||
```
|
||||
|
||||
**For installations from source**
|
||||
|
||||
```yaml
|
||||
omniauth:
|
||||
auto_link_user: true
|
||||
auto_link_user: ["saml", "twitter"]
|
||||
```
|
||||
|
||||
## Configure OmniAuth Providers as External
|
||||
|
|
|
@ -143,7 +143,6 @@ module API
|
|||
optional :local_markdown_version, type: Integer, desc: 'Local markdown version, increase this value when any cached markdown should be invalidated'
|
||||
optional :allow_local_requests_from_hooks_and_services, type: Boolean, desc: 'Deprecated: Use :allow_local_requests_from_web_hooks_and_services instead. Allow requests to the local network from hooks and services.' # support legacy names, can be removed in v5
|
||||
optional :snowplow_enabled, type: Grape::API::Boolean, desc: 'Enable Snowplow tracking'
|
||||
optional :snowplow_iglu_registry_url, type: String, desc: 'The Snowplow base Iglu Schema Registry URL to use for custom context and self describing events'
|
||||
given snowplow_enabled: ->(val) { val } do
|
||||
requires :snowplow_collector_hostname, type: String, desc: 'The Snowplow collector hostname'
|
||||
optional :snowplow_cookie_domain, type: String, desc: 'The Snowplow cookie domain'
|
||||
|
|
|
@ -117,7 +117,6 @@ module Gitlab
|
|||
|
||||
private
|
||||
|
||||
# rubocop:disable Gitlab/RailsLogger
|
||||
def rate_limit!(rate_limiter, success:, login:)
|
||||
return if skip_rate_limit?(login: login)
|
||||
|
||||
|
@ -132,12 +131,11 @@ module Gitlab
|
|||
# This returns true when the failures are over the threshold and the IP
|
||||
# is banned.
|
||||
if rate_limiter.register_fail!
|
||||
Rails.logger.info "IP #{rate_limiter.ip} failed to login " \
|
||||
Gitlab::AppLogger.info "IP #{rate_limiter.ip} failed to login " \
|
||||
"as #{login} but has been temporarily banned from Git auth"
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Gitlab/RailsLogger
|
||||
|
||||
def skip_rate_limit?(login:)
|
||||
CI_JOB_USER == login
|
||||
|
|
|
@ -273,7 +273,11 @@ module Gitlab
|
|||
end
|
||||
|
||||
def auto_link_user?
|
||||
Gitlab.config.omniauth.auto_link_user
|
||||
auto_link = Gitlab.config.omniauth.auto_link_user
|
||||
return auto_link if [true, false].include?(auto_link)
|
||||
|
||||
auto_link = Array(auto_link)
|
||||
auto_link.include?(auth_hash.provider)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -335,7 +335,7 @@ module Gitlab
|
|||
end
|
||||
rescue Prometheus::Client::LabelSetValidator::LabelSetError => err
|
||||
# Ensure that errors in recording these metrics don't affect the operation of the application
|
||||
Rails.logger.error("Unable to observe database transaction duration: #{err}") # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.error("Unable to observe database transaction duration: #{err}")
|
||||
end
|
||||
|
||||
# MonkeyPatch for ActiveRecord::Base for adding observability
|
||||
|
|
|
@ -7,7 +7,7 @@ module Gitlab
|
|||
def self.delivering_email(message)
|
||||
message.perform_deliveries = false
|
||||
|
||||
Rails.logger.info "Emails disabled! Interceptor prevented sending mail #{message.subject}" # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.info "Emails disabled! Interceptor prevented sending mail #{message.subject}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ module Gitlab
|
|||
begin
|
||||
CharlockHolmes::Converter.convert(message, detect[:encoding], 'UTF-8')
|
||||
rescue ArgumentError => e
|
||||
Rails.logger.warn("Ignoring error converting #{detect[:encoding]} into UTF8: #{e.message}") # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.warn("Ignoring error converting #{detect[:encoding]} into UTF8: #{e.message}")
|
||||
|
||||
''
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module Gitlab
|
|||
# This will still fail if the file is corrupted (e.g. 0 bytes)
|
||||
raw_repository.write_ref(keep_around_ref_name(sha), sha)
|
||||
rescue Gitlab::Git::CommandError => ex
|
||||
Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -955,7 +955,7 @@ module Gitlab
|
|||
gitaly_repository_client.cleanup if exists?
|
||||
end
|
||||
rescue Gitlab::Git::CommandError => e # Don't fail if we can't cleanup
|
||||
Rails.logger.error("Unable to clean repository on storage #{storage} with relative path #{relative_path}: #{e.message}") # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.error("Unable to clean repository on storage #{storage} with relative path #{relative_path}: #{e.message}")
|
||||
Gitlab::Metrics.counter(
|
||||
:failed_repository_cleanup_total,
|
||||
'Number of failed repository cleanup events'
|
||||
|
|
|
@ -62,28 +62,24 @@ module Gitlab
|
|||
# Flag a project to be migrated to Hashed Storage
|
||||
#
|
||||
# @param [Project] project that will be migrated
|
||||
# rubocop:disable Gitlab/RailsLogger
|
||||
def migrate(project)
|
||||
Rails.logger.info "Starting storage migration of #{project.full_path} (ID=#{project.id})..."
|
||||
Gitlab::AppLogger.info "Starting storage migration of #{project.full_path} (ID=#{project.id})..."
|
||||
|
||||
project.migrate_to_hashed_storage!
|
||||
rescue => err
|
||||
Rails.logger.error("#{err.message} migrating storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}")
|
||||
Gitlab::AppLogger.error("#{err.message} migrating storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}")
|
||||
end
|
||||
# rubocop:enable Gitlab/RailsLogger
|
||||
|
||||
# Flag a project to be rolled-back to Legacy Storage
|
||||
#
|
||||
# @param [Project] project that will be rolled-back
|
||||
# rubocop:disable Gitlab/RailsLogger
|
||||
def rollback(project)
|
||||
Rails.logger.info "Starting storage rollback of #{project.full_path} (ID=#{project.id})..."
|
||||
Gitlab::AppLogger.info "Starting storage rollback of #{project.full_path} (ID=#{project.id})..."
|
||||
|
||||
project.rollback_to_legacy_storage!
|
||||
rescue => err
|
||||
Rails.logger.error("#{err.message} rolling-back storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}")
|
||||
Gitlab::AppLogger.error("#{err.message} rolling-back storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}")
|
||||
end
|
||||
# rubocop:enable Gitlab/RailsLogger
|
||||
|
||||
# Returns whether we have any pending storage migration
|
||||
#
|
||||
|
|
|
@ -24,7 +24,7 @@ module Gitlab
|
|||
result, elapsed = with_timing(&method(:check))
|
||||
return if result.nil?
|
||||
|
||||
Rails.logger.error("#{human_name} check returned unexpected result #{result}") unless successful?(result) # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.error("#{human_name} check returned unexpected result #{result}") unless successful?(result)
|
||||
[
|
||||
metric("#{metric_prefix}_timeout", result.is_a?(Timeout::Error) ? 1 : 0),
|
||||
metric("#{metric_prefix}_success", successful?(result) ? 1 : 0),
|
||||
|
|
|
@ -21,7 +21,7 @@ module Gitlab
|
|||
def safe_sample
|
||||
sample
|
||||
rescue => e
|
||||
Rails.logger.warn("#{self.class}: #{e}, stopping") # rubocop:disable Gitlab/RailsLogger
|
||||
Gitlab::AppLogger.warn("#{self.class}: #{e}, stopping")
|
||||
stop
|
||||
end
|
||||
|
||||
|
|
|
@ -47,8 +47,7 @@ module Gitlab
|
|||
cookie_domain: Gitlab::CurrentSettings.snowplow_cookie_domain,
|
||||
app_id: Gitlab::CurrentSettings.snowplow_app_id,
|
||||
form_tracking: additional_features,
|
||||
link_click_tracking: additional_features,
|
||||
iglu_registry_url: Gitlab::CurrentSettings.snowplow_iglu_registry_url
|
||||
link_click_tracking: additional_features
|
||||
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
|
||||
end
|
||||
|
||||
|
|
|
@ -166,7 +166,8 @@ module Gitlab
|
|||
user_preferences_usage,
|
||||
ingress_modsecurity_usage,
|
||||
container_expiration_policies_usage,
|
||||
service_desk_counts
|
||||
service_desk_counts,
|
||||
snowplow_event_counts
|
||||
).tap do |data|
|
||||
data[:snippets] = data[:personal_snippets] + data[:project_snippets]
|
||||
end
|
||||
|
@ -174,6 +175,19 @@ module Gitlab
|
|||
end
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
|
||||
def snowplow_event_counts(time_period: {})
|
||||
return {} unless report_snowplow_events?
|
||||
|
||||
{
|
||||
promoted_issues: count(
|
||||
self_monitoring_project
|
||||
.product_analytics_events
|
||||
.by_category_and_action('epics', 'promote')
|
||||
.where(time_period)
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
def system_usage_data_monthly
|
||||
{
|
||||
counts_monthly: {
|
||||
|
@ -185,7 +199,9 @@ module Gitlab
|
|||
packages: count(::Packages::Package.where(last_28_days_time_period)),
|
||||
personal_snippets: count(PersonalSnippet.where(last_28_days_time_period)),
|
||||
project_snippets: count(ProjectSnippet.where(last_28_days_time_period))
|
||||
}.tap do |data|
|
||||
}.merge(
|
||||
snowplow_event_counts(time_period: last_28_days_time_period(column: :collector_tstamp))
|
||||
).tap do |data|
|
||||
data[:snippets] = data[:personal_snippets] + data[:project_snippets]
|
||||
end
|
||||
}
|
||||
|
@ -452,8 +468,8 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def last_28_days_time_period
|
||||
{ created_at: 28.days.ago..Time.current }
|
||||
def last_28_days_time_period(column: :created_at)
|
||||
{ column => 28.days.ago..Time.current }
|
||||
end
|
||||
|
||||
# Source: https://gitlab.com/gitlab-data/analytics/blob/master/transform/snowflake-dbt/data/ping_metrics_to_stage_mapping_data.csv
|
||||
|
@ -687,6 +703,10 @@ module Gitlab
|
|||
}
|
||||
end
|
||||
|
||||
def report_snowplow_events?
|
||||
self_monitoring_project && Feature.enabled?(:product_analytics, self_monitoring_project)
|
||||
end
|
||||
|
||||
def distinct_count_service_desk_enabled_projects(time_period)
|
||||
project_creator_id_start = user_minimum_id
|
||||
project_creator_id_finish = user_maximum_id
|
||||
|
@ -776,6 +796,10 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def self_monitoring_project
|
||||
Gitlab::CurrentSettings.self_monitoring_project
|
||||
end
|
||||
|
||||
def clear_memoized
|
||||
clear_memoization(:issue_minimum_id)
|
||||
clear_memoization(:issue_maximum_id)
|
||||
|
|
|
@ -12999,9 +12999,6 @@ msgstr ""
|
|||
msgid "If your HTTP repository is not publicly accessible, add your credentials."
|
||||
msgstr ""
|
||||
|
||||
msgid "Iglu registry URL (optional)"
|
||||
msgstr ""
|
||||
|
||||
msgid "Ignore"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -202,7 +202,56 @@ RSpec.describe Gitlab::Auth::OAuth::User do
|
|||
include_examples "to verify compliance with allow_single_sign_on"
|
||||
end
|
||||
|
||||
context "with auto_link_user enabled" do
|
||||
context "with auto_link_user enabled for a different provider" do
|
||||
before do
|
||||
stub_omniauth_config(auto_link_user: ['saml'])
|
||||
end
|
||||
|
||||
context "and a current GitLab user with a matching email" do
|
||||
let!(:existing_user) { create(:user, email: 'john@mail.com', username: 'john') }
|
||||
|
||||
it "adds the OmniAuth identity to the GitLab user account" do
|
||||
oauth_user.save
|
||||
|
||||
expect(gl_user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "and no current GitLab user with a matching email" do
|
||||
include_examples "to verify compliance with allow_single_sign_on"
|
||||
end
|
||||
end
|
||||
|
||||
context "with auto_link_user enabled for the correct provider" do
|
||||
before do
|
||||
stub_omniauth_config(auto_link_user: ['twitter'])
|
||||
end
|
||||
|
||||
context "and a current GitLab user with a matching email" do
|
||||
let!(:existing_user) { create(:user, email: 'john@mail.com', username: 'john') }
|
||||
|
||||
it "adds the OmniAuth identity to the GitLab user account" do
|
||||
oauth_user.save
|
||||
|
||||
expect(gl_user).to be_valid
|
||||
expect(gl_user.username).to eql 'john'
|
||||
expect(gl_user.email).to eql 'john@mail.com'
|
||||
expect(gl_user.identities.length).to be 1
|
||||
identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
|
||||
expect(identities_as_hash).to match_array(
|
||||
[
|
||||
{ provider: 'twitter', extern_uid: uid }
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "and no current GitLab user with a matching email" do
|
||||
include_examples "to verify compliance with allow_single_sign_on"
|
||||
end
|
||||
end
|
||||
|
||||
context "with auto_link_user enabled for all providers" do
|
||||
before do
|
||||
stub_omniauth_config(auto_link_user: true)
|
||||
end
|
||||
|
@ -421,7 +470,7 @@ RSpec.describe Gitlab::Auth::OAuth::User do
|
|||
|
||||
context "with both auto_link_user and auto_link_ldap_user enabled" do
|
||||
before do
|
||||
stub_omniauth_config(auto_link_user: true, auto_link_ldap_user: true)
|
||||
stub_omniauth_config(auto_link_user: ['twitter'], auto_link_ldap_user: true)
|
||||
end
|
||||
|
||||
context "and at least one LDAP provider is defined" do
|
||||
|
|
|
@ -9,7 +9,6 @@ RSpec.describe Gitlab::Tracking do
|
|||
stub_application_setting(snowplow_collector_hostname: 'gitfoo.com')
|
||||
stub_application_setting(snowplow_cookie_domain: '.gitfoo.com')
|
||||
stub_application_setting(snowplow_app_id: '_abc123_')
|
||||
stub_application_setting(snowplow_iglu_registry_url: 'https://example.org')
|
||||
end
|
||||
|
||||
describe '.snowplow_options' do
|
||||
|
@ -20,8 +19,7 @@ RSpec.describe Gitlab::Tracking do
|
|||
cookieDomain: '.gitfoo.com',
|
||||
appId: '_abc123_',
|
||||
formTracking: true,
|
||||
linkClickTracking: true,
|
||||
igluRegistryUrl: 'https://example.org'
|
||||
linkClickTracking: true
|
||||
}
|
||||
|
||||
expect(subject.snowplow_options(nil)).to match(expected_fields)
|
||||
|
|
|
@ -12,14 +12,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
|||
|
||||
describe '.uncached_data' do
|
||||
describe '.usage_activity_by_stage' do
|
||||
it 'includes usage_activity_by_stage data' do
|
||||
uncached_data = described_class.uncached_data
|
||||
subject { described_class.uncached_data }
|
||||
|
||||
expect(uncached_data).to include(:usage_activity_by_stage)
|
||||
expect(uncached_data).to include(:usage_activity_by_stage_monthly)
|
||||
expect(uncached_data[:usage_activity_by_stage])
|
||||
it 'includes usage_activity_by_stage data' do
|
||||
is_expected.to include(:usage_activity_by_stage)
|
||||
is_expected.to include(:usage_activity_by_stage_monthly)
|
||||
expect(subject[:usage_activity_by_stage])
|
||||
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
|
||||
expect(uncached_data[:usage_activity_by_stage_monthly])
|
||||
expect(subject[:usage_activity_by_stage_monthly])
|
||||
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
|
||||
end
|
||||
|
||||
|
@ -34,15 +34,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
|||
expect(described_class).to receive(:clear_memoization).with(key)
|
||||
end
|
||||
|
||||
described_class.uncached_data
|
||||
subject
|
||||
end
|
||||
|
||||
it 'merge_requests_users is included only in montly counters' do
|
||||
uncached_data = described_class.uncached_data
|
||||
|
||||
expect(uncached_data[:usage_activity_by_stage][:create])
|
||||
expect(subject[:usage_activity_by_stage][:create])
|
||||
.not_to include(:merge_requests_users)
|
||||
expect(uncached_data[:usage_activity_by_stage_monthly][:create])
|
||||
expect(subject[:usage_activity_by_stage_monthly][:create])
|
||||
.to include(:merge_requests_users)
|
||||
end
|
||||
end
|
||||
|
@ -401,10 +399,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
|||
expect(UsageDataHelpers::COUNTS_KEYS - count_data.keys).to be_empty
|
||||
end
|
||||
|
||||
it 'gathers usage counts monthly hash' do
|
||||
expect(subject[:counts_monthly]).to be_an(Hash)
|
||||
end
|
||||
|
||||
it 'gathers usage counts correctly' do
|
||||
count_data = subject[:counts]
|
||||
|
||||
|
@ -492,10 +486,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
|||
)
|
||||
end
|
||||
|
||||
it 'gathers topology data' do
|
||||
expect(subject.keys).to include(:topology)
|
||||
end
|
||||
|
||||
context 'with existing container expiration policies' do
|
||||
let_it_be(:disabled) { create(:container_expiration_policy, enabled: false) }
|
||||
let_it_be(:enabled) { create(:container_expiration_policy, enabled: true) }
|
||||
|
@ -1175,4 +1165,46 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
|||
service_desk_issues: 2)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.snowplow_event_counts' do
|
||||
context 'when self-monitoring project exists' do
|
||||
let_it_be(:project) { create(:project) }
|
||||
|
||||
before do
|
||||
stub_application_setting(self_monitoring_project: project)
|
||||
end
|
||||
|
||||
context 'and product_analytics FF is enabled for it' do
|
||||
before do
|
||||
stub_feature_flags(product_analytics: project)
|
||||
|
||||
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote')
|
||||
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 28.days.ago)
|
||||
end
|
||||
|
||||
it 'returns promoted_issues for the time period' do
|
||||
expect(described_class.snowplow_event_counts[:promoted_issues]).to eq(2)
|
||||
expect(described_class.snowplow_event_counts(
|
||||
time_period: described_class.last_28_days_time_period(column: :collector_tstamp)
|
||||
)[:promoted_issues]).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and product_analytics FF is disabled' do
|
||||
before do
|
||||
stub_feature_flags(product_analytics: false)
|
||||
end
|
||||
|
||||
it 'returns an empty hash' do
|
||||
expect(described_class.snowplow_event_counts).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when self-monitoring project does not exist' do
|
||||
it 'returns an empty hash' do
|
||||
expect(described_class.snowplow_event_counts).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -191,14 +191,10 @@ RSpec.describe ApplicationSetting do
|
|||
it { is_expected.not_to allow_value(nil).for(:snowplow_collector_hostname) }
|
||||
it { is_expected.to allow_value("snowplow.gitlab.com").for(:snowplow_collector_hostname) }
|
||||
it { is_expected.not_to allow_value('/example').for(:snowplow_collector_hostname) }
|
||||
it { is_expected.to allow_value('https://example.org').for(:snowplow_iglu_registry_url) }
|
||||
it { is_expected.not_to allow_value('not-a-url').for(:snowplow_iglu_registry_url) }
|
||||
it { is_expected.to allow_value(nil).for(:snowplow_iglu_registry_url) }
|
||||
end
|
||||
|
||||
context 'when snowplow is not enabled' do
|
||||
it { is_expected.to allow_value(nil).for(:snowplow_collector_hostname) }
|
||||
it { is_expected.to allow_value(nil).for(:snowplow_iglu_registry_url) }
|
||||
end
|
||||
|
||||
context "when user accepted let's encrypt terms of service" do
|
||||
|
|
|
@ -82,4 +82,25 @@ RSpec.describe GroupDeployKey do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.for_groups' do
|
||||
context 'when group deploy keys are enabled for some groups' do
|
||||
let_it_be(:group1) { create(:group) }
|
||||
let_it_be(:group2) { create(:group) }
|
||||
let_it_be(:group3) { create(:group) }
|
||||
let_it_be(:gdk1) { create(:group_deploy_key) }
|
||||
let_it_be(:gdk2) { create(:group_deploy_key) }
|
||||
let_it_be(:gdk3) { create(:group_deploy_key) }
|
||||
|
||||
it 'returns these group deploy keys' do
|
||||
gdk1.groups << group1
|
||||
gdk1.groups << group2
|
||||
gdk2.groups << group3
|
||||
gdk3.groups << group2
|
||||
|
||||
expect(described_class.for_groups([group1.id, group3.id])).to contain_exactly(gdk1, gdk2)
|
||||
expect(described_class.for_groups([group2.id])).to contain_exactly(gdk1, gdk3)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,4 +35,15 @@ RSpec.describe ProductAnalyticsEvent, type: :model do
|
|||
it { expect(described_class.count_by_graph('platform', 7.days)).to eq({ 'app' => 1, 'web' => 2 }) }
|
||||
it { expect(described_class.count_by_graph('platform', 30.days)).to eq({ 'app' => 1, 'mobile' => 1, 'web' => 2 }) }
|
||||
end
|
||||
|
||||
describe '.by_category_and_action' do
|
||||
let_it_be(:event) { create(:product_analytics_event, se_category: 'catA', se_action: 'actA') }
|
||||
|
||||
before do
|
||||
create(:product_analytics_event, se_category: 'catA', se_action: 'actB')
|
||||
create(:product_analytics_event, se_category: 'catB', se_action: 'actA')
|
||||
end
|
||||
|
||||
it { expect(described_class.by_category_and_action('catA', 'actA')).to match_array([event]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6536,6 +6536,49 @@ RSpec.describe Project do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#enabled_group_deploy_keys' do
|
||||
let_it_be(:project) { create(:project) }
|
||||
|
||||
subject { project.enabled_group_deploy_keys }
|
||||
|
||||
context 'when a project does not have a group' do
|
||||
it { is_expected.to be_empty }
|
||||
end
|
||||
|
||||
context 'when a project has a parent group' do
|
||||
let!(:group) { create(:group, projects: [project]) }
|
||||
|
||||
context 'and this group has a group deploy key enabled' do
|
||||
let!(:group_deploy_key) { create(:group_deploy_key, groups: [group]) }
|
||||
|
||||
it { is_expected.to contain_exactly(group_deploy_key) }
|
||||
|
||||
context 'and this group has parent group which also has a group deploy key enabled' do
|
||||
let(:super_group) { create(:group) }
|
||||
|
||||
it 'returns both group deploy keys' do
|
||||
super_group = create(:group)
|
||||
super_group_deploy_key = create(:group_deploy_key, groups: [super_group])
|
||||
group.update!(parent: super_group)
|
||||
|
||||
expect(subject).to contain_exactly(group_deploy_key, super_group_deploy_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'and another group has a group deploy key enabled' do
|
||||
let_it_be(:group_deploy_key) { create(:group_deploy_key) }
|
||||
|
||||
it 'does not return this group deploy key' do
|
||||
another_group = create(:group)
|
||||
create(:group_deploy_key, groups: [another_group])
|
||||
|
||||
expect(subject).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def finish_job(export_job)
|
||||
export_job.start
|
||||
export_job.finish
|
||||
|
|
|
@ -236,8 +236,7 @@ RSpec.describe API::Settings, 'Settings' do
|
|||
snowplow_collector_hostname: "snowplow.example.com",
|
||||
snowplow_cookie_domain: ".example.com",
|
||||
snowplow_enabled: true,
|
||||
snowplow_app_id: "app_id",
|
||||
snowplow_iglu_registry_url: 'https://example.com'
|
||||
snowplow_app_id: "app_id"
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ module UsageDataHelpers
|
|||
USAGE_DATA_KEYS = %i(
|
||||
active_user_count
|
||||
counts
|
||||
counts_monthly
|
||||
recorded_at
|
||||
edition
|
||||
version
|
||||
|
@ -162,6 +163,7 @@ module UsageDataHelpers
|
|||
web_ide_clientside_preview_enabled
|
||||
ingress_modsecurity_enabled
|
||||
object_store
|
||||
topology
|
||||
).freeze
|
||||
|
||||
def stub_usage_data_connections
|
||||
|
|
Loading…
Reference in a new issue