Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GITALY_SERVER_VERSION2
-rw-r--r--app/models/authentication_event.rb9
-rw-r--r--changelogs/unreleased/dblessing-auth-events-usage-ping.yml5
-rw-r--r--db/migrate/20200916151442_add_result_index_to_authentication_events.rb18
-rw-r--r--db/schema_migrations/202009161514421
-rw-r--r--db/structure.sql2
-rw-r--r--doc/README.md2
-rw-r--r--doc/api/issue_links.md7
-rw-r--r--doc/ci/examples/laravel_with_gitlab_and_envoy/index.md4
-rw-r--r--doc/user/packages/container_registry/img/container_registry_group_repositories_v13_1.pngbin45865 -> 0 bytes
-rw-r--r--doc/user/packages/container_registry/img/container_registry_hover_path_13_4.pngbin0 -> 13597 bytes
-rw-r--r--doc/user/packages/container_registry/img/container_registry_repositories_v13_1.pngbin46734 -> 0 bytes
-rw-r--r--doc/user/packages/container_registry/img/container_registry_repositories_with_quickstart_v13_1.pngbin51791 -> 0 bytes
-rw-r--r--doc/user/packages/container_registry/img/container_registry_repository_details_v13.0.pngbin32673 -> 0 bytes
-rw-r--r--doc/user/packages/container_registry/index.md125
-rw-r--r--doc/user/permissions.md4
-rw-r--r--doc/user/project/issues/index.md5
-rw-r--r--doc/user/project/issues/issue_data_and_actions.md4
-rw-r--r--doc/user/project/issues/related_issues.md23
-rw-r--r--lib/gitlab/usage_data.rb35
-rw-r--r--spec/factories/authentication_event.rb11
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb21
-rw-r--r--spec/models/authentication_event_spec.rb31
23 files changed, 202 insertions, 107 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION
index 4f2b3edfe93..c889f2b5521 100644
--- a/GITALY_SERVER_VERSION
+++ b/GITALY_SERVER_VERSION
@@ -1 +1 @@
-8d14377ab5b3914033f85ec3572e0ba65749a6e0
+2f16d97afa2e8accb4144f04e2e1e90bf4d1e9fb
diff --git a/app/models/authentication_event.rb b/app/models/authentication_event.rb
index 1ac3c5fbd9c..16b132c7ed5 100644
--- a/app/models/authentication_event.rb
+++ b/app/models/authentication_event.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class AuthenticationEvent < ApplicationRecord
+ include UsageStatistics
+
belongs_to :user, optional: true
validates :provider, :user_name, :result, presence: true
@@ -9,4 +11,11 @@ class AuthenticationEvent < ApplicationRecord
failed: 0,
success: 1
}
+
+ scope :for_provider, ->(provider) { where(provider: provider) }
+ scope :ldap, -> { where('provider LIKE ?', 'ldap%')}
+
+ def self.providers
+ distinct.pluck(:provider)
+ end
end
diff --git a/changelogs/unreleased/dblessing-auth-events-usage-ping.yml b/changelogs/unreleased/dblessing-auth-events-usage-ping.yml
new file mode 100644
index 00000000000..26117006f1c
--- /dev/null
+++ b/changelogs/unreleased/dblessing-auth-events-usage-ping.yml
@@ -0,0 +1,5 @@
+---
+title: Report auth events in manage stage usage ping
+merge_request: 39747
+author:
+type: added
diff --git a/db/migrate/20200916151442_add_result_index_to_authentication_events.rb b/db/migrate/20200916151442_add_result_index_to_authentication_events.rb
new file mode 100644
index 00000000000..13b0521038e
--- /dev/null
+++ b/db/migrate/20200916151442_add_result_index_to_authentication_events.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddResultIndexToAuthenticationEvents < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_authentication_events_on_provider_user_id_created_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :authentication_events, [:provider, :user_id, :created_at], where: 'result = 1', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :authentication_events, INDEX_NAME
+ end
+end
diff --git a/db/schema_migrations/20200916151442 b/db/schema_migrations/20200916151442
new file mode 100644
index 00000000000..36b2a4e9962
--- /dev/null
+++ b/db/schema_migrations/20200916151442
@@ -0,0 +1 @@
+aef52404e6ce83d5d4b3de65ad00b665334f5ff2e5b7b6c3c622f79313657f26 \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 753f44a0180..67738c8623e 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -19478,6 +19478,8 @@ CREATE UNIQUE INDEX index_atlassian_identities_on_extern_uid ON atlassian_identi
CREATE INDEX index_authentication_events_on_provider ON authentication_events USING btree (provider);
+CREATE INDEX index_authentication_events_on_provider_user_id_created_at ON authentication_events USING btree (provider, user_id, created_at) WHERE (result = 1);
+
CREATE INDEX index_authentication_events_on_user_id ON authentication_events USING btree (user_id);
CREATE INDEX index_award_emoji_on_awardable_type_and_awardable_id ON award_emoji USING btree (awardable_type, awardable_id);
diff --git a/doc/README.md b/doc/README.md
index 52123c1db66..43311451f06 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -121,7 +121,7 @@ The following documentation relates to the DevOps **Plan** stage:
| [Milestones](user/project/milestones/index.md) | Set milestones for delivery of issues and merge requests, with optional due date. |
| [Project Issue Board](user/project/issue_board.md) | Display issues on a Scrum or Kanban board. |
| [Quick Actions](user/project/quick_actions.md) | Shortcuts for common actions on issues or merge requests, replacing the need to click buttons or use dropdowns in GitLab's UI. |
-| [Related Issues](user/project/issues/related_issues.md) **(STARTER)** | Create a relationship between issues. |
+| [Related Issues](user/project/issues/related_issues.md) | Create a relationship between issues. |
| [Requirements Management](user/project/requirements/index.md) **(ULTIMATE)** | Check your products against a set of criteria. |
| [Roadmap](user/group/roadmap/index.md) **(ULTIMATE)** | Visualize epic timelines. |
| [Service Desk](user/project/service_desk.md) | A simple way to allow people to create issues in your GitLab instance without needing their own user account. |
diff --git a/doc/api/issue_links.md b/doc/api/issue_links.md
index b6502bf099c..22eb9aeaf7b 100644
--- a/doc/api/issue_links.md
+++ b/doc/api/issue_links.md
@@ -1,8 +1,11 @@
-# Issue links API **(STARTER)**
+# Issue links API **(CORE)**
+
+> The simple "relates to" relationship [moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212329) to [GitLab Core](https://about.gitlab.com/pricing/) in 13.4.
## List issue relations
-Get a list of related issues of a given issue, sorted by the relationship creation datetime (ascending).
+Get a list of a given issue's [related issues](../user/project/issues/related_issues.md),
+sorted by the relationship creation datetime (ascending).
Issues will be filtered according to the user authorizations.
```plaintext
diff --git a/doc/ci/examples/laravel_with_gitlab_and_envoy/index.md b/doc/ci/examples/laravel_with_gitlab_and_envoy/index.md
index 8927c5c3480..1832606550e 100644
--- a/doc/ci/examples/laravel_with_gitlab_and_envoy/index.md
+++ b/doc/ci/examples/laravel_with_gitlab_and_envoy/index.md
@@ -441,9 +441,9 @@ On your GitLab project repository navigate to the **Registry** tab.
![container registry page empty image](img/container_registry_page_empty_image.png)
-You may need to [enable Container Registry](../../../user/packages/container_registry/index.md#enable-the-container-registry-for-your-project) to your project to see this tab. You'll find it under your project's **Settings > General > Visibility, project features, permissions**.
+You may need to enable the Container Registry for your project to see this tab. You'll find it under your project's **Settings > General > Visibility, project features, permissions**.
-To start using Container Registry on our machine, we first need to login to the GitLab registry using our GitLab username and password:
+To start using Container Registry on our machine, we first need to sign in to the GitLab registry using our GitLab username and password:
```shell
docker login registry.gitlab.com
diff --git a/doc/user/packages/container_registry/img/container_registry_group_repositories_v13_1.png b/doc/user/packages/container_registry/img/container_registry_group_repositories_v13_1.png
deleted file mode 100644
index bbbba44eb9b..00000000000
--- a/doc/user/packages/container_registry/img/container_registry_group_repositories_v13_1.png
+++ /dev/null
Binary files differ
diff --git a/doc/user/packages/container_registry/img/container_registry_hover_path_13_4.png b/doc/user/packages/container_registry/img/container_registry_hover_path_13_4.png
new file mode 100644
index 00000000000..2d16c11fe61
--- /dev/null
+++ b/doc/user/packages/container_registry/img/container_registry_hover_path_13_4.png
Binary files differ
diff --git a/doc/user/packages/container_registry/img/container_registry_repositories_v13_1.png b/doc/user/packages/container_registry/img/container_registry_repositories_v13_1.png
deleted file mode 100644
index 13a6d1a4470..00000000000
--- a/doc/user/packages/container_registry/img/container_registry_repositories_v13_1.png
+++ /dev/null
Binary files differ
diff --git a/doc/user/packages/container_registry/img/container_registry_repositories_with_quickstart_v13_1.png b/doc/user/packages/container_registry/img/container_registry_repositories_with_quickstart_v13_1.png
deleted file mode 100644
index 35a02182a77..00000000000
--- a/doc/user/packages/container_registry/img/container_registry_repositories_with_quickstart_v13_1.png
+++ /dev/null
Binary files differ
diff --git a/doc/user/packages/container_registry/img/container_registry_repository_details_v13.0.png b/doc/user/packages/container_registry/img/container_registry_repository_details_v13.0.png
deleted file mode 100644
index 088e80221de..00000000000
--- a/doc/user/packages/container_registry/img/container_registry_repository_details_v13.0.png
+++ /dev/null
Binary files differ
diff --git a/doc/user/packages/container_registry/index.md b/doc/user/packages/container_registry/index.md
index c67f2ab5738..5f89ed40647 100644
--- a/doc/user/packages/container_registry/index.md
+++ b/doc/user/packages/container_registry/index.md
@@ -16,100 +16,44 @@ info: To determine the technical writer assigned to the Stage/Group associated w
> - The group level Container Registry was [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/23315) in GitLab 12.10.
> - Searching by image repository name was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31322) in GitLab 13.0.
-NOTE: **Note:**
-This document is the user guide. To learn how to enable GitLab Container
-Registry across your GitLab instance, visit the
-[administrator documentation](../../../administration/packages/container_registry.md).
-
-With the Docker Container Registry integrated into GitLab, every project can
+With the Docker Container Registry integrated into GitLab, every GitLab project can
have its own space to store its Docker images.
You can read more about Docker Registry at <https://docs.docker.com/registry/introduction/>.
-![Container Registry repositories](img/container_registry_repositories_v13_1.png)
-
-## Enable the Container Registry for your project
-
-CAUTION: **Warning:**
-The Container Registry follows the visibility settings of the project. If the project is public, so is the Container Registry.
-
-If you cannot find the **Packages & Registries > Container Registry** entry under your
-project's sidebar, it is not enabled in your GitLab instance. Ask your
-administrator to enable GitLab Container Registry following the
-[administration documentation](../../../administration/packages/container_registry.md).
-
-If you are using GitLab.com, this is enabled by default so you can start using
-the Registry immediately. Currently there is a soft (10GB) size restriction for
-Registry on GitLab.com, as part of the [repository size limit](../../project/repository/index.md).
-
-Once enabled for your GitLab instance, to enable Container Registry for your
-project:
-
-1. Go to your project's **Settings > General** page.
-1. Expand the **Visibility, project features, permissions** section
- and enable the **Container Registry** feature on your project. For new
- projects this might be enabled by default. For existing projects
- (prior GitLab 8.8), enable it explicitly.
-1. Press **Save changes** for the changes to take effect. You should now be able
- to see the **Packages & Registries > Container Registry** link in the sidebar.
-
-## Control Container Registry from within GitLab
-
-GitLab offers a simple Container Registry management panel. This management panel is available
-for both projects and groups.
-
-### Control Container Registry for your project
-
-Navigate to your project's **{package}** **Packages & Registries > Container Registry**.
-
-![Container Registry project repositories](img/container_registry_repositories_with_quickstart_v13_1.png)
-
-This view allows you to:
-
-- Show all the image repositories that belong to the project.
-- Filter image repositories by their name.
-- [Delete](#delete-images-from-within-gitlab) one or more image repository.
-- Navigate to the image repository details page.
-- Show a **Quick start** dropdown with the most common commands to log in, build and push.
-- Show a banner if the optional [cleanup policy](#cleanup-policy) is enabled for this project.
-
-### Control Container Registry for your group
-
-Navigate to your group's **{package}** **Packages & Registries > Container Registry**.
-
-![Container Registry group repositories](img/container_registry_group_repositories_v13_1.png)
+NOTE: **Note:**
+This document is the user guide. To learn how to enable the Container
+Registry for your GitLab instance, visit the
+[administrator documentation](../../../administration/packages/container_registry.md).
-This view allows you to:
+## View the Container Registry
-- Show all the image repositories of the projects that belong to this group.
-- [Delete](#delete-images-from-within-gitlab) one or more image repositories.
-- Navigate to a specific image repository details page.
+You can view the Container Registry for a project or group.
-### Image Repository details page
+1. Go to your project or group.
+1. Go to **Packages & Registries > Container Registry**.
-Clicking on the name of any image repository navigates to the details.
+You can search, sort, filter, and [delete](#delete-images-from-within-gitlab) containers on this page.
-![Container Registry project repository details](img/container_registry_repository_details_v13.0.png)
+CAUTION: **Warning:**
+If a project is public, so is the Container Registry.
-NOTE: **Note:**
-The following page has the same functionalities both in the **Group level container registry**
-and in the **Project level container registry**.
+## Use images from the Container Registry
-This view:
+To download and run a container image hosted in the GitLab Container Registry:
-- Shows all the image repository details.
-- Shows all the tags of the image repository.
-- Allows you to quickly copy the tag path (by clicking on the clipboard button near the tag name).
-- Allows you to [delete one or more tags](#delete-images-from-within-gitlab).
+1. Copy the link to your container image:
+ - Go to your project or group's **Packages & Registries > Container Registry**
+ and find the image you want.
+ - Next to the image name, click the **Copy** button.
-## Use images from GitLab Container Registry
+ ![Container Registry image URL](img/container_registry_hover_path_13_4.png)
-To download and run a container from images hosted in GitLab Container Registry,
-use `docker run`:
+1. Use `docker run` with the image link:
-```shell
-docker run [options] registry.example.com/group/project/image [arguments]
-```
+ ```shell
+ docker run [options] registry.example.com/group/project/image [arguments]
+ ```
For more information on running Docker containers, visit the
[Docker documentation](https://docs.docker.com/engine/userguide/intro/).
@@ -118,10 +62,10 @@ For more information on running Docker containers, visit the
If you visit the **Packages & Registries > Container Registry** link under your project's
menu, you can see the explicit instructions to login to the Container Registry
-using your GitLab credentials.
+by using your GitLab credentials.
For example if the Registry's URL is `registry.example.com`, then you should be
-able to login with:
+able to log in with:
```shell
docker login registry.example.com
@@ -175,6 +119,10 @@ registry.example.com/group/project/image:latest
registry.example.com/group/project/my/image:rc1
```
+NOTE: **Note:**
+Currently there is a soft (10GB) size restriction for
+the Container Registry on GitLab.com, as part of the [repository size limit](../../project/repository/index.md).
+
## Build and push images using GitLab CI/CD
While you can build and push your images from your local machine, take
@@ -406,8 +354,6 @@ To delete images from within GitLab:
1. In the dialog box, click **Remove tag**.
- ![Container Registry tags](img/container_registry_repository_details_v13.0.png)
-
### Delete images using the API
If you want to automate the process of deleting images, GitLab provides an API. For more
@@ -652,6 +598,19 @@ Container Registry, you must delete all existing images.
- Prior to GitLab 12.10, any tags that use the same image ID as the `latest` tag
are not deleted by the cleanup policy.
+## Disable the Container Registry for a project
+
+The Container Registry is enabled by default.
+
+You can, however, remove the Container Registry for a project:
+
+1. Go to your project's **Settings > General** page.
+1. Expand the **Visibility, project features, permissions** section
+ and disable **Container Registry**.
+1. Click **Save changes**.
+
+The **Packages & Registries > Container Registry** entry is removed from the project's sidebar.
+
## Troubleshooting the GitLab Container Registry
### Docker connection error
diff --git a/doc/user/permissions.md b/doc/user/permissions.md
index eeaa759b193..ecba2d6350f 100644
--- a/doc/user/permissions.md
+++ b/doc/user/permissions.md
@@ -72,7 +72,7 @@ The following table depicts the various user permission levels in a project.
| Set issue weight | | ✓ | ✓ | ✓ | ✓ |
| Lock issue threads | | ✓ | ✓ | ✓ | ✓ |
| Manage issue tracker | | ✓ | ✓ | ✓ | ✓ |
-| Manage related issues **(STARTER)** | | ✓ | ✓ | ✓ | ✓ |
+| Manage related issues | | ✓ | ✓ | ✓ | ✓ |
| Manage labels | | ✓ | ✓ | ✓ | ✓ |
| Create code snippets | | ✓ | ✓ | ✓ | ✓ |
| See a commit status | | ✓ | ✓ | ✓ | ✓ |
@@ -284,7 +284,7 @@ group.
- The [instance level](admin_area/settings/visibility_and_access_controls.md#default-project-creation-protection).
- The [group level](group/index.md#default-project-creation-level).
1. Does not apply to subgroups.
-1. Developers can push commits to the default branch of a new project only if the [default branch protection](group/index.md#changing-the-default-branch-protection-of-a-group) is set to "Partially protected" or "Not protected".
+1. Developers can push commits to the default branch of a new project only if the [default branch protection](group/index.md#changing-the-default-branch-protection-of-a-group) is set to "Partially protected" or "Not protected".
### Subgroup permissions
diff --git a/doc/user/project/issues/index.md b/doc/user/project/issues/index.md
index 060266a478f..434af3a4a49 100644
--- a/doc/user/project/issues/index.md
+++ b/doc/user/project/issues/index.md
@@ -156,12 +156,15 @@ collaborate with your team.
efficiently and with less effort by tracking groups of issues that share a theme, across
projects and milestones.
-### Related issues **(STARTER)**
+### Related issues
You can mark two issues as related, so that when viewing one, the other is always
listed in its [Related Issues](related_issues.md) section. This can help display important
context, such as past work, dependencies, or duplicates.
+Users on [GitLab Starter, GitLab Bronze, and higher tiers](https://about.gitlab.com/pricing/), can
+also mark issues as blocking or blocked by another issue.
+
### Crosslinking issues
You can [cross-link issues](crosslinking_issues.md) by referencing an issue from another
diff --git a/doc/user/project/issues/issue_data_and_actions.md b/doc/user/project/issues/issue_data_and_actions.md
index 5356e6aeb40..5395b0c08a4 100644
--- a/doc/user/project/issues/issue_data_and_actions.md
+++ b/doc/user/project/issues/issue_data_and_actions.md
@@ -36,7 +36,7 @@ You can find all the information for that issue on one screen.
- **15.** [Edit](#edit)
- **16.** [Description](#description)
- **17.** [Mentions](#mentions)
-- **18.** [Related Issues **(STARTER)**](#related-issues)
+- **18.** [Related Issues](#related-issues)
- **19.** [Related Merge Requests](#related-merge-requests)
- **20.** [Award emoji](#award-emoji)
- **21.** [Show all activity](#show-all-activity)
@@ -208,7 +208,7 @@ TIP: **Tip:**
Avoid mentioning `@all` in issues and merge requests, as it sends an email notification
to all the members of that project's group, which can be interpreted as spam.
-### Related Issues **(STARTER)**
+### Related Issues
Issues that were mentioned as [related issues](related_issues.md) are listed here.
You can also click the `+` to add more related issues.
diff --git a/doc/user/project/issues/related_issues.md b/doc/user/project/issues/related_issues.md
index 954e3771722..b040bcf3b03 100644
--- a/doc/user/project/issues/related_issues.md
+++ b/doc/user/project/issues/related_issues.md
@@ -4,33 +4,40 @@ group: Project Management
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
---
-# Related issues **(STARTER)**
+# Related issues **(CORE)**
-> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1797) in [GitLab Starter](https://about.gitlab.com/pricing/) 9.4.
+> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1797) in [GitLab Starter](https://about.gitlab.com/pricing/) 9.4.
+> - The simple "relates to" relationship [moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212329) to [GitLab Core](https://about.gitlab.com/pricing/) in 13.4.
Related issues are a bi-directional relationship between any two issues
and appear in a block below the issue description. Issues can be across groups
and projects.
+You can set any issue as:
+
+- Related to another issue
+- Blocking another issue **(STARTER)**
+- Blocked by another issue **(STARTER)**
+
The relationship only shows up in the UI if the user can see both issues.
When you try to close an issue that has open blockers, a warning is displayed.
TIP: **Tip:**
-To manage related issues through our API, see the [API documentation](../../../api/issue_links.md).
+To manage related issues through our API, visit the [issue links API documentation](../../../api/issue_links.md).
## Adding a related issue
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/2035) in [GitLab Starter](https://about.gitlab.com/pricing/) 12.8.
> - [Improved](https://gitlab.com/gitlab-org/gitlab/-/issues/34239) to warn when attempting to close an issue that is blocked by others in [GitLab Starter](https://about.gitlab.com/pricing/) 13.0.
-> When you try to close an issue with open blockers, you'll see a warning that you can dismiss.
+> When you try to close an issue with open blockers, you see a warning that you can dismiss.
1. Relate one issue to another by clicking the related issues "+" button
in the header of the related issue block.
1. Input the issue reference number or paste in the full URL of the issue.
-1. Select whether the current issue relates to, blocks, or is blocked by the issues being entered.
+1. **(STARTER)** Select whether the current issue relates to, blocks, or is blocked by the issues being entered.
![Adding a related issue](img/related_issues_add_v12_8.png)
@@ -42,11 +49,11 @@ in the header of the related issue block.
- same group: `project#44`
- different group: `group/project#44`
- Valid references will be added to a temporary list that you can review.
+ Valid references are added to a temporary list that you can review.
1. When you have added all the related issues, click **Add** to submit.
-When you have finished adding all related issues, you will be able to see
+When you have finished adding all related issues, you can see
them categorized so their relationships can be better understood visually.
![Related issue block](img/related_issue_block_v12_8.png)
@@ -56,7 +63,7 @@ them categorized so their relationships can be better understood visually.
In the related issues block, click the "x" icon on the right-side of each issue
token that you wish to remove.
-Due to the bi-directional relationship, it will no longer appear in either issue.
+Due to the bi-directional relationship, it no longer appears in either issue.
![Removing a related issue](img/related_issues_remove_v12_8.png)
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index 6bb651bbae5..ea3e2ea064b 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -542,6 +542,7 @@ module Gitlab
groups: distinct_count(::GroupMember.where(time_period), :user_id),
users_created: count(::User.where(time_period), start: user_minimum_id, finish: user_maximum_id),
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' },
+ user_auth_by_provider: distinct_count_user_auth_by_provider(time_period),
projects_imported: {
gitlab_project: projects_imported_count('gitlab_project', time_period),
gitlab: projects_imported_count('gitlab', time_period),
@@ -813,6 +814,7 @@ module Gitlab
clear_memoization(:approval_merge_request_rule_maximum_id)
clear_memoization(:project_minimum_id)
clear_memoization(:project_maximum_id)
+ clear_memoization(:auth_providers)
end
# rubocop: disable CodeReuse/ActiveRecord
@@ -844,6 +846,39 @@ module Gitlab
def projects_imported_count(from, time_period)
distinct_count(::Project.imported_from(from).where(time_period), :creator_id) # rubocop: disable CodeReuse/ActiveRecord
end
+
+ # rubocop:disable CodeReuse/ActiveRecord
+ def distinct_count_user_auth_by_provider(time_period)
+ counts = auth_providers_except_ldap.each_with_object({}) do |provider, hash|
+ hash[provider] = distinct_count(
+ ::AuthenticationEvent.success.for_provider(provider).where(time_period), :user_id)
+ end
+
+ if any_ldap_auth_providers?
+ counts['ldap'] = distinct_count(
+ ::AuthenticationEvent.success.ldap.where(time_period), :user_id
+ )
+ end
+
+ counts
+ end
+ # rubocop:enable CodeReuse/ActiveRecord
+
+ # rubocop:disable UsageData/LargeTable
+ def auth_providers
+ strong_memoize(:auth_providers) do
+ ::AuthenticationEvent.providers
+ end
+ end
+ # rubocop:enable UsageData/LargeTable
+
+ def auth_providers_except_ldap
+ auth_providers.reject { |provider| provider.starts_with?('ldap') }
+ end
+
+ def any_ldap_auth_providers?
+ auth_providers.any? { |provider| provider.starts_with?('ldap') }
+ end
end
end
end
diff --git a/spec/factories/authentication_event.rb b/spec/factories/authentication_event.rb
new file mode 100644
index 00000000000..ff539c6f5c4
--- /dev/null
+++ b/spec/factories/authentication_event.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :authentication_event do
+ user
+ provider { :standard }
+ user_name { 'Jane Doe' }
+ ip_address { '127.0.0.1' }
+ result { :failed }
+ end
+end
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 7c413f3bcca..22c6ef7346b 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -29,7 +29,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
user_minimum_id user_maximum_id unique_visit_service
deployment_minimum_id deployment_maximum_id
approval_merge_request_rule_minimum_id
- approval_merge_request_rule_maximum_id)
+ approval_merge_request_rule_maximum_id
+ auth_providers)
values.each do |key|
expect(described_class).to receive(:clear_memoization).with(key)
end
@@ -167,6 +168,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
describe 'usage_activity_by_stage_manage' do
it 'includes accurate usage_activity_by_stage data' do
+ described_class.clear_memoization(:auth_providers)
+
stub_config(
omniauth:
{ providers: omniauth_providers }
@@ -174,21 +177,29 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
for_defined_days_back do
user = create(:user)
+ user2 = create(:user)
create(:event, author: user)
create(:group_member, user: user)
+ create(:authentication_event, user: user, provider: :ldapmain, result: :success)
+ create(:authentication_event, user: user2, provider: :ldapsecondary, result: :success)
+ create(:authentication_event, user: user2, provider: :group_saml, result: :success)
+ create(:authentication_event, user: user2, provider: :group_saml, result: :success)
+ create(:authentication_event, user: user, provider: :group_saml, result: :failed)
end
expect(described_class.usage_activity_by_stage_manage({})).to include(
events: 2,
groups: 2,
- users_created: 4,
- omniauth_providers: ['google_oauth2']
+ users_created: 6,
+ omniauth_providers: ['google_oauth2'],
+ user_auth_by_provider: { 'group_saml' => 2, 'ldap' => 4 }
)
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
events: 1,
groups: 1,
- users_created: 2,
- omniauth_providers: ['google_oauth2']
+ users_created: 3,
+ omniauth_providers: ['google_oauth2'],
+ user_auth_by_provider: { 'group_saml' => 1, 'ldap' => 2 }
)
end
diff --git a/spec/models/authentication_event_spec.rb b/spec/models/authentication_event_spec.rb
index 56b0111f2c7..7390fde74a6 100644
--- a/spec/models/authentication_event_spec.rb
+++ b/spec/models/authentication_event_spec.rb
@@ -12,4 +12,35 @@ RSpec.describe AuthenticationEvent do
it { is_expected.to validate_presence_of(:user_name) }
it { is_expected.to validate_presence_of(:result) }
end
+
+ describe 'scopes' do
+ let_it_be(:ldap_event) { create(:authentication_event, provider: :ldapmain, result: :failed) }
+ let_it_be(:google_oauth2) { create(:authentication_event, provider: :google_oauth2, result: :success) }
+
+ describe '.for_provider' do
+ it 'returns events only for the specified provider' do
+ expect(described_class.for_provider(:ldapmain)).to match_array ldap_event
+ end
+ end
+
+ describe '.ldap' do
+ it 'returns all events for an LDAP provider' do
+ expect(described_class.ldap).to match_array ldap_event
+ end
+ end
+ end
+
+ describe '.providers' do
+ before do
+ create(:authentication_event, provider: :ldapmain)
+ create(:authentication_event, provider: :google_oauth2)
+ create(:authentication_event, provider: :standard)
+ create(:authentication_event, provider: :standard)
+ create(:authentication_event, provider: :standard)
+ end
+
+ it 'returns an array of distinct providers' do
+ expect(described_class.providers).to match_array %w(ldapmain google_oauth2 standard)
+ end
+ end
end