summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-04 00:08:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-04 00:08:19 +0000
commitda37005e4575681fbdecaed11cf9528b2673b6ea (patch)
treeedd418d904576a1caf28ba7cf0aff3f4c6f0466f
parent71c3596b1dfda5dca5d25357fe92f442647a8f5b (diff)
downloadgitlab-ce-da37005e4575681fbdecaed11cf9528b2673b6ea.tar.gz
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.checksum2
-rw-r--r--Gemfile.lock4
-rw-r--r--app/controllers/concerns/wiki_actions.rb4
-rw-r--r--app/services/event_create_service.rb45
-rw-r--r--doc/administration/docs_self_host.md20
-rw-r--r--doc/user/clusters/agent/gitops/flux_tutorial.md181
-rw-r--r--lib/gitlab/usage_data.rb10
-rw-r--r--lib/gitlab/usage_data_counters/track_unique_events.rb81
-rw-r--r--spec/lib/gitlab/usage_data_counters/track_unique_events_spec.rb72
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb16
-rw-r--r--spec/services/event_create_service_spec.rb51
12 files changed, 267 insertions, 221 deletions
diff --git a/Gemfile b/Gemfile
index f6f87996ae4..15acea5383f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -434,7 +434,7 @@ group :development, :test do
end
group :development, :test, :danger do
- gem 'gitlab-dangerfiles', '~> 3.7.0', require: false
+ gem 'gitlab-dangerfiles', '~> 3.8.0', require: false
end
group :development, :test, :coverage do
diff --git a/Gemfile.checksum b/Gemfile.checksum
index b4f600be0ac..3dda7bedb23 100644
--- a/Gemfile.checksum
+++ b/Gemfile.checksum
@@ -204,7 +204,7 @@
{"name":"gitaly","version":"15.9.0.pre.rc3","platform":"ruby","checksum":"6ac64320a70417131a4b97f5dd45d4e203d60703cc3cba156561e7f8c50a4abe"},
{"name":"gitlab","version":"4.19.0","platform":"ruby","checksum":"3f645e3e195dbc24f0834fbf83e8ccfb2056d8e9712b01a640aad418a6949679"},
{"name":"gitlab-chronic","version":"0.10.5","platform":"ruby","checksum":"f80f18dc699b708870a80685243331290bc10cfeedb6b99c92219722f729c875"},
-{"name":"gitlab-dangerfiles","version":"3.7.0","platform":"ruby","checksum":"35c5bc42e60c575ab5701192ca2384ab414b14c2963602b39e143b1aaeb7e54d"},
+{"name":"gitlab-dangerfiles","version":"3.8.0","platform":"ruby","checksum":"7ef0c3205faa38a2ada19ee5b8e4012ea696611aa02564a4a95eaf3fb26d1a7e"},
{"name":"gitlab-experiment","version":"0.7.1","platform":"ruby","checksum":"166dddb3aa83428bcaa93c35684ed01dc4d61f321fd2ae40b020806dc54a7824"},
{"name":"gitlab-fog-azure-rm","version":"1.7.0","platform":"ruby","checksum":"969c67943c54ad4c259a6acd040493f13922fbdf2211bb4eca00e71505263dc2"},
{"name":"gitlab-labkit","version":"0.30.1","platform":"ruby","checksum":"bdedbd86014c83dfd6a50d20dbc1709697bba2bb9e3666383e5f28cbd312b113"},
diff --git a/Gemfile.lock b/Gemfile.lock
index 028fb1dc681..b4c561b9372 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -568,7 +568,7 @@ GEM
terminal-table (>= 1.5.1)
gitlab-chronic (0.10.5)
numerizer (~> 0.2)
- gitlab-dangerfiles (3.7.0)
+ gitlab-dangerfiles (3.8.0)
danger (>= 8.4.5)
danger-gitlab (>= 8.0.0)
rake
@@ -1684,7 +1684,7 @@ DEPENDENCIES
gettext_i18n_rails_js (~> 1.3)
gitaly (~> 15.9.0.pre.rc3)
gitlab-chronic (~> 0.10.5)
- gitlab-dangerfiles (~> 3.7.0)
+ gitlab-dangerfiles (~> 3.8.0)
gitlab-experiment (~> 0.7.1)
gitlab-fog-azure-rm (~> 1.7.0)
gitlab-labkit (~> 0.30.1)
diff --git a/app/controllers/concerns/wiki_actions.rb b/app/controllers/concerns/wiki_actions.rb
index 0e160ce2ea0..ebcce635945 100644
--- a/app/controllers/concerns/wiki_actions.rb
+++ b/app/controllers/concerns/wiki_actions.rb
@@ -46,9 +46,7 @@ module WikiActions
end
end
- # NOTE: We want to include wiki page views in the same counter as the other
- # Event-based wiki actions tracked through TrackUniqueEvents, so we use the same event name.
- track_redis_hll_event :show, name: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION.to_s
+ track_redis_hll_event :show, name: 'wiki_action'
helper_method :view_file_button, :diff_file_html_data
diff --git a/app/services/event_create_service.rb b/app/services/event_create_service.rb
index c941febad57..96edaa06fc2 100644
--- a/app/services/event_create_service.rb
+++ b/app/services/event_create_service.rb
@@ -28,7 +28,7 @@ class EventCreateService
def open_mr(merge_request, current_user)
create_record_event(merge_request, current_user, :created).tap do
- track_event(event_action: :created, event_target: MergeRequest, author_id: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id)
track_snowplow_event(
action: :created,
project: merge_request.project,
@@ -41,7 +41,7 @@ class EventCreateService
def close_mr(merge_request, current_user)
create_record_event(merge_request, current_user, :closed).tap do
- track_event(event_action: :closed, event_target: MergeRequest, author_id: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id)
track_snowplow_event(
action: :closed,
project: merge_request.project,
@@ -58,7 +58,7 @@ class EventCreateService
def merge_mr(merge_request, current_user)
create_record_event(merge_request, current_user, :merged).tap do
- track_event(event_action: :merged, event_target: MergeRequest, author_id: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id)
track_snowplow_event(
action: :merged,
project: merge_request.project,
@@ -88,7 +88,7 @@ class EventCreateService
def leave_note(note, current_user)
create_record_event(note, current_user, :commented).tap do
if note.is_a?(DiffNote) && note.for_merge_request?
- track_event(event_action: :commented, event_target: MergeRequest, author_id: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id)
track_snowplow_event(
action: :commented,
project: note.project,
@@ -128,12 +128,17 @@ class EventCreateService
records = create.zip([:created].cycle) + update.zip([:updated].cycle)
return [] if records.empty?
- event_meta = { user: current_user, label: DEGIGN_EVENT_LABEL, property: Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION }
+ event_meta = { user: current_user, label: DEGIGN_EVENT_LABEL, property: :design_action }
track_snowplow_event(action: :create, project: create.first.project, **event_meta) if create.any?
track_snowplow_event(action: :update, project: update.first.project, **event_meta) if update.any?
- create_record_events(records, current_user)
+ inserted_events = create_record_events(records, current_user)
+
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:design_action, values: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: current_user.id)
+
+ inserted_events
end
def destroy_designs(designs, current_user)
@@ -144,9 +149,15 @@ class EventCreateService
project: designs.first.project,
user: current_user,
label: DEGIGN_EVENT_LABEL,
- property: Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION
+ property: :design_action
)
- create_record_events(designs.zip([:destroyed].cycle), current_user)
+
+ inserted_events = create_record_events(designs.zip([:destroyed].cycle), current_user)
+
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:design_action, values: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: current_user.id)
+
+ inserted_events
end
# Create a new wiki page event
@@ -163,7 +174,8 @@ class EventCreateService
def wiki_event(wiki_page_meta, author, action, fingerprint)
raise IllegalActionError, action unless Event::WIKI_ACTIONS.include?(action)
- track_event(event_action: action, event_target: wiki_page_meta.class, author_id: author.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:wiki_action, values: author.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: author.id)
duplicate = Event.for_wiki_meta(wiki_page_meta).for_fingerprint(fingerprint).first
return duplicate if duplicate.present?
@@ -205,13 +217,7 @@ class EventCreateService
.merge(action: action, fingerprint: fingerprint, target_id: record.id, target_type: record.class.name)
end
- result = Event.insert_all(attribute_sets, returning: %w[id])
-
- tuples.each do |record, status, _|
- track_event(event_action: status, event_target: record.class, author_id: current_user.id)
- end
-
- result
+ Event.insert_all(attribute_sets, returning: %w[id])
end
def create_push_event(service_class, project, current_user, push_data)
@@ -226,7 +232,8 @@ class EventCreateService
new_event
end
- track_event(event_action: :pushed, event_target: Project, author_id: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:project_action, values: current_user.id)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: current_user.id)
namespace = project.namespace
Gitlab::Tracking.event(
@@ -273,10 +280,6 @@ class EventCreateService
{ resource_parent_attr => resource_parent.id }
end
- def track_event(...)
- Gitlab::UsageDataCounters::TrackUniqueEvents.track_event(...)
- end
-
def track_snowplow_event(action:, project:, user:, label:, property:)
Gitlab::Tracking.event(
self.class.to_s,
diff --git a/doc/administration/docs_self_host.md b/doc/administration/docs_self_host.md
index 97eff35da91..095baafab70 100644
--- a/doc/administration/docs_self_host.md
+++ b/doc/administration/docs_self_host.md
@@ -22,7 +22,7 @@ To host the GitLab product documentation, you can use:
- GitLab Pages
- Your own web server
-After you create a website by using one of these methods, you redirect the UI links
+After you create a website by using one of these methods, redirect the UI links
in the product to point to your website.
NOTE:
@@ -41,7 +41,7 @@ In the following example, we expose this on the host under the same port.
Make sure you either:
- Allow port `4000` in your firewall.
-- Use a different port. In following examples, replace the leftmost `4000` with the port different port.
+- Use a different port. In following examples, replace the leftmost `4000` with a different port number.
To run the GitLab product documentation website in a Docker container:
@@ -74,7 +74,7 @@ To run the GitLab product documentation website in a Docker container:
docker-compose up -d
```
-1. Visit `http://0.0.0.0:4000` to view the documentation website and verify
+1. Visit `http://0.0.0.0:4000` to view the documentation website and verify that
it works.
1. [Redirect the help links to the new Docs site](#redirect-the-help-links-to-the-new-docs-site).
@@ -84,7 +84,7 @@ You can use GitLab Pages to host the GitLab product documentation.
Prerequisite:
-- Ensure the Pages site URL does not use a subfolder. Because of how the docs
+- Ensure the Pages site URL does not use a subfolder. Because of the way the docs
site is pre-compiled, the CSS and JavaScript files are relative to the
main domain or subdomain. For example, URLs like `https://example.com/docs/`
are not supported.
@@ -177,7 +177,11 @@ documentation URL requests as needed. For example, if your GitLab version is
- When you select the link, you are redirected to
`http://0.0.0.0:4000/14.5/ee/user/admin_area/settings/help_page/#destination-requirements`.
-To test the setting, select a **Learn more** link in the GitLab application.
+To test the setting, in GitLab, select a **Learn more** link. For example:
+
+1. On the top bar, in the upper-right corner, select your avatar.
+1. Select **Preferences**.
+1. In the **Syntax highlighting theme** section, select **Learn more**.
## Upgrade the product documentation to a later version
@@ -187,7 +191,7 @@ Upgrading the Docs site to a later version requires downloading the newer Docker
To upgrade to a later version [using Docker](#self-host-the-product-documentation-with-docker):
-- If you use plain Docker:
+- If you use Docker:
1. Stop the running container:
@@ -207,7 +211,7 @@ To upgrade to a later version [using Docker](#self-host-the-product-documentatio
docker run --detach --name gitlab_docs -it --rm -p 4000:4000 registry.gitlab.com/gitlab-org/gitlab-docs:14.6
```
-- If you use Docker compose:
+- If you use Docker Compose:
1. Change the version in `docker-compose.yaml`, for example 14.6:
@@ -231,7 +235,7 @@ To upgrade to a later version [using Docker](#self-host-the-product-documentatio
To upgrade to a later version [using GitLab Pages](#self-host-the-product-documentation-with-gitlab-pages):
-1. Edit your existing `.gitlab-ci.yml` file, and replace the `image`'s version number:
+1. Edit your existing `.gitlab-ci.yml` file, and replace the `image` version number:
```yaml
image: registry.gitlab.com/gitlab-org/gitlab-docs:14.5
diff --git a/doc/user/clusters/agent/gitops/flux_tutorial.md b/doc/user/clusters/agent/gitops/flux_tutorial.md
new file mode 100644
index 00000000000..b3d71e66dea
--- /dev/null
+++ b/doc/user/clusters/agent/gitops/flux_tutorial.md
@@ -0,0 +1,181 @@
+---
+stage: Configure
+group: Configure
+info: A tutorial using Flux with Project Access Tokens
+---
+
+# Tutorial: Set up Flux for GitOps **(FREE)**
+
+This tutorial teaches you how to set up Flux for GitOps. You'll set up a sample project,
+complete a bootstrap Flux installation, and authenticate your installation with a project access token.
+
+You can find the fully configured tutorial project [in this GitLab repository](https://gitlab.com/gitlab-org/configure/examples/flux/flux-config). It works in conjunction with [this repository](https://gitlab.com/gitlab-org/configure/examples/flux/web-app-manifests/-/tree/main), which contains the example Kubernetes manifests.
+
+To set up Flux with a project access token:
+
+1. [Create the Flux repository](#create-the-flux-repository)
+1. [Create the Kubernetes manifest repository](#create-the-kubernetes-manifest-repository)
+1. [Configure Flux to sync your manifests](#configure-flux-to-sync-your-manifests)
+1. [Verify your configuration](#verify-your-configuration)
+
+Prerequisites:
+
+- On GitLab SaaS, you must have the Premium or Ultimate tier. On self-managed instances, you can have any tier.
+- You must have a Kubernetes cluster running.
+
+## Create the Flux repository
+
+To start, create a Git repository, install Flux, and authenticate Flux with your repo:
+
+1. Make sure your `kubectl` is configured to access your cluster.
+1. [Install the Flux CLI](https://fluxcd.io/flux/installation/#install-the-flux-cli).
+1. In GitLab, create a new empty project called `flux-config`.
+1. In the `flux-config` project, create a [project access token](../../../project/settings/project_access_tokens.md#create-a-project-access-token) with the following settings:
+
+ - From the **Select a role** dropdown list, select **Maintainer**.
+ - Under **Select scopes**, select the **API** and **write_repository** checkboxes.
+
+ Name the project token `flux-project-access-token`.
+
+1. From your shell, export a `GITLAB_TOKEN` environment variable with the value of your project access token.
+ For example, `export GITLAB_TOKEN=<flux-project-access-token>`.
+1. Run the `bootstrap` command. The exact command depends on whether you are
+ creating the Flux repository under a GitLab user, group, or subgroup. For more information,
+ see the [Flux bootstrap documentation](https://fluxcd.io/flux/installation/#gitlab-and-gitlab-enterprise).
+
+ In this tutorial, you're working with a public project in a subgroup. The bootstrap command looks like this:
+
+ ```shell
+ flux bootstrap gitlab \
+ --owner=gitlab-org/configure/examples/flux \
+ --repository=flux-config \
+ --branch=main \
+ --path=clusters/my-cluster
+ ```
+
+ This command installs Flux on the Kubernetes cluster and configures it to manage itself from the repository `flux-config`.
+
+Great work! You now have a repository, a project access token, and a Flux bootstrap installation authenticated to your repo. Any updates to your repo are automatically synced to the cluster.
+
+## Create the Kubernetes manifest repository
+
+Next, create a repository for your Kubernetes manifests:
+
+1. In GitLab, create a new repository called `web-app-manifests`.
+1. Add a file to `web-app-manifests` named `nginx-deployment.yaml` with the following contents:
+
+```yaml
+apiVersion: apps/v1
+
+kind: Deployment
+
+metadata:
+ name: nginx-deployment
+ labels:
+ app: nginx
+spec:
+ replicas: 3
+ selector:
+ matchLabels:
+ app: nginx
+ template:
+ metadata:
+ labels:
+ app: nginx
+ spec:
+ containers:
+ - name: nginx
+ image: nginx:1.14.2
+ ports:
+ - containerPort: 80
+```
+
+1. In the new repository, [create a deploy token](../../../project/deploy_tokens/index.md#create-a-deploy-token) with only the **read_repository** scope.
+1. Store your deploy token username and password somewhere safe.
+1. In Flux CLI, create a secret with your deploy token and point the secret to the new repository. For example:
+
+ ```shell
+ flux create secret git flux-deploy-authentication \
+ --url=https://gitlab.com/gitlab-org/configure/examples/flux/web-app-manifests \
+ --namespace=default \
+ --username=<token-user-name> \
+ --password=<token-password>
+ ```
+
+1. To check if your secret was generated successfully, run:
+
+ ```shell
+ kubectl -n default get secrets flux-deploy-authentication -o yaml
+ ```
+
+ Under `data`, you should see base64-encoded values associated with your token username and password.
+
+Congratulations! You now have a manifest repository, a deploy token, and a secret generated directly on your cluster.
+
+### Configure Flux to sync your manifests
+
+Next, tell `flux-config` to sync with the `web-app-manifests` repository.
+
+To do so, create a [`GitRepository`](https://fluxcd.io/flux/components/source/gitrepositories/) resource:
+
+1. Clone the `flux-config` repo to your machine.
+1. In your local clone of `flux-config`, add the `GitRepository` file `clusters/my-cluster/web-app-manifests-source.yaml`:
+
+ ```yaml
+ ---
+ apiVersion: source.toolkit.fluxcd.io/v1beta2
+ kind: GitRepository
+ metadata:
+ name: web-app-manifests
+ namespace: default
+ spec:
+ interval: 1m0s
+ ref:
+ branch: main
+ secretRef:
+ name: flux-deploy-authentication
+ url: https://gitlab.com/gitlab-org/configure/examples/flux/web-app-manifests
+ ```
+
+ This file uses `secretRef` to refer back to the deploy token secret you created in the last step.
+
+1. In your local clone of `flux-config`, add the `GitRepository` file `clusters/my-cluster/web-app-manifests-kustomization.yaml`:
+
+ ```yaml
+ ---
+ apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
+ kind: Kustomization
+ metadata:
+ name: nginx-source-kustomization
+ namespace: default
+ spec:
+ interval: 1m0s
+ path: ./
+ prune: true
+ sourceRef:
+ kind: GitRepository
+ name: web-app-manifests
+ namespace: default
+ targetNamespace: default
+ ```
+
+ This file adds a [`Kustomization`](https://fluxcd.io/flux/components/kustomize/kustomization/) resource that tells Flux to sync the manifests from
+ `web-app-manifests` with `kustomize`.
+
+1. Commit the new files and push.
+
+## Verify your configuration
+
+You should see a newly created `nginx-deployment` pod in your cluster.
+
+To check whether the `nginx-deployment` pod is running in the default namespace, run the following:
+
+```shell
+kubectl -n default get pods -n default
+```
+
+If you want to see the deployment sync again, try updating the number of replicas in the
+`nginx-deployment.yaml` file and push to your `main` branch. If all is working well, it
+should sync to the cluster.
+
+Excellent work! You've successfully set up a complete Flux project.
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index f45663b41b0..97d62c91d0d 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -385,13 +385,11 @@ module Gitlab
end
def merge_requests_users(time_period)
- counter = Gitlab::UsageDataCounters::TrackUniqueEvents
-
redis_usage_data do
- counter.count_unique_events(
- event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::MERGE_REQUEST_ACTION,
- date_from: time_period[:created_at].first,
- date_to: time_period[:created_at].last
+ Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
+ event_names: :merge_request_action,
+ start_date: time_period[:created_at].first,
+ end_date: time_period[:created_at].last
)
end
end
diff --git a/lib/gitlab/usage_data_counters/track_unique_events.rb b/lib/gitlab/usage_data_counters/track_unique_events.rb
deleted file mode 100644
index 20da9665876..00000000000
--- a/lib/gitlab/usage_data_counters/track_unique_events.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module UsageDataCounters
- module TrackUniqueEvents
- WIKI_ACTION = :wiki_action
- DESIGN_ACTION = :design_action
- PUSH_ACTION = :project_action
- MERGE_REQUEST_ACTION = :merge_request_action
-
- GIT_WRITE_ACTIONS = [WIKI_ACTION, DESIGN_ACTION, PUSH_ACTION].freeze
- GIT_WRITE_ACTION = :git_write_action
-
- ACTION_TRANSFORMATIONS = HashWithIndifferentAccess.new({
- wiki: {
- created: WIKI_ACTION,
- updated: WIKI_ACTION,
- destroyed: WIKI_ACTION
- },
- design: {
- created: DESIGN_ACTION,
- updated: DESIGN_ACTION,
- destroyed: DESIGN_ACTION
- },
- project: {
- pushed: PUSH_ACTION
- },
- merge_request: {
- closed: MERGE_REQUEST_ACTION,
- merged: MERGE_REQUEST_ACTION,
- created: MERGE_REQUEST_ACTION,
- commented: MERGE_REQUEST_ACTION
- }
- }).freeze
-
- class << self
- def track_event(event_action:, event_target:, author_id:, time: Time.zone.now)
- return unless valid_target?(event_target)
- return unless valid_action?(event_action)
-
- transformed_target = transform_target(event_target)
- transformed_action = transform_action(event_action, transformed_target)
-
- return unless Gitlab::UsageDataCounters::HLLRedisCounter.known_event?(transformed_action.to_s)
-
- Gitlab::UsageDataCounters::HLLRedisCounter.track_event(transformed_action.to_s, values: author_id, time: time)
-
- track_git_write_action(author_id, transformed_action, time)
- end
-
- def count_unique_events(event_action:, date_from:, date_to:)
- Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: event_action.to_s, start_date: date_from, end_date: date_to)
- end
-
- private
-
- def transform_action(event_action, event_target)
- ACTION_TRANSFORMATIONS.dig(event_target, event_action) || event_action
- end
-
- def transform_target(event_target)
- Event::TARGET_TYPES.key(event_target)
- end
-
- def valid_target?(target)
- Event::TARGET_TYPES.value?(target)
- end
-
- def valid_action?(action)
- Event.actions.key?(action)
- end
-
- def track_git_write_action(author_id, transformed_action, time)
- return unless GIT_WRITE_ACTIONS.include?(transformed_action)
-
- Gitlab::UsageDataCounters::HLLRedisCounter.track_event(GIT_WRITE_ACTION, values: author_id, time: time)
- end
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/usage_data_counters/track_unique_events_spec.rb b/spec/lib/gitlab/usage_data_counters/track_unique_events_spec.rb
deleted file mode 100644
index d1144dd0bc5..00000000000
--- a/spec/lib/gitlab/usage_data_counters/track_unique_events_spec.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::UsageDataCounters::TrackUniqueEvents, :clean_gitlab_redis_shared_state do
- subject(:track_unique_events) { described_class }
-
- let(:time) { Time.zone.now }
-
- def track_event(params)
- track_unique_events.track_event(**params)
- end
-
- def count_unique(params)
- track_unique_events.count_unique_events(**params)
- end
-
- context 'tracking an event' do
- context 'when tracking successfully' do
- context 'when the application setting is enabled' do
- context 'when the target and the action is valid' do
- before do
- stub_application_setting(usage_ping_enabled: true)
- end
-
- it 'tracks and counts the events as expected' do
- project = Event::TARGET_TYPES[:project]
- design = Event::TARGET_TYPES[:design]
- wiki = Event::TARGET_TYPES[:wiki]
-
- expect(track_event(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy
- expect(track_event(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy
- expect(track_event(event_action: :pushed, event_target: project, author_id: 2)).to be_truthy
- expect(track_event(event_action: :pushed, event_target: project, author_id: 3)).to be_truthy
- expect(track_event(event_action: :pushed, event_target: project, author_id: 4, time: time - 3.days)).to be_truthy
-
- expect(track_event(event_action: :destroyed, event_target: design, author_id: 3)).to be_truthy
- expect(track_event(event_action: :created, event_target: design, author_id: 4)).to be_truthy
- expect(track_event(event_action: :updated, event_target: design, author_id: 5)).to be_truthy
-
- expect(track_event(event_action: :destroyed, event_target: wiki, author_id: 5)).to be_truthy
- expect(track_event(event_action: :created, event_target: wiki, author_id: 3)).to be_truthy
- expect(track_event(event_action: :updated, event_target: wiki, author_id: 4)).to be_truthy
-
- expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(3)
- expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: Date.tomorrow)).to eq(4)
- expect(count_unique(event_action: described_class::DESIGN_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3)
- expect(count_unique(event_action: described_class::WIKI_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3)
- expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: time - 2.days)).to eq(1)
- end
- end
- end
- end
-
- context 'when tracking unsuccessfully' do
- using RSpec::Parameterized::TableSyntax
-
- where(:target, :action) do
- Project | :invalid_action
- :invalid_target | :pushed
- Project | :created
- end
-
- with_them do
- it 'returns the expected values' do
- expect(track_event(event_action: action, event_target: target, author_id: 2)).to be_nil
- expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(0)
- end
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index a2461545a56..53d7e3c1eac 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -1044,16 +1044,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures, feature_category: :servic
let(:time) { Time.current }
before do
- counter = Gitlab::UsageDataCounters::TrackUniqueEvents
- merge_request = Event::TARGET_TYPES[:merge_request]
- design = Event::TARGET_TYPES[:design]
-
- counter.track_event(event_action: :commented, event_target: merge_request, author_id: 1, time: time)
- counter.track_event(event_action: :opened, event_target: merge_request, author_id: 1, time: time)
- counter.track_event(event_action: :merged, event_target: merge_request, author_id: 2, time: time)
- counter.track_event(event_action: :closed, event_target: merge_request, author_id: 3, time: time)
- counter.track_event(event_action: :opened, event_target: merge_request, author_id: 4, time: time - 3.days)
- counter.track_event(event_action: :created, event_target: design, author_id: 5, time: time)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: 1, time: time)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: 1, time: time)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: 2, time: time)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: 3, time: time)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: 4, time: time - 3.days)
+ Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:design_action, values: 5, time: time)
end
it 'returns the distinct count of users using merge requests (via events table) within the specified time period' do
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index 47f1b7d9b64..6805f14133e 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -12,10 +12,20 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
shared_examples 'it records the event in the event counter' do
specify do
- tracking_params = { event_action: event_action, date_from: Date.yesterday, date_to: Date.today }
+ tracking_params = { event_names: event_action, start_date: Date.yesterday, end_date: Date.today }
expect { subject }
- .to change { Gitlab::UsageDataCounters::TrackUniqueEvents.count_unique_events(**tracking_params) }
+ .to change { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(**tracking_params) }
+ .by(1)
+ end
+ end
+
+ shared_examples 'it records a git write event' do
+ specify do
+ tracking_params = { event_names: 'git_write_action', start_date: Date.yesterday, end_date: Date.today }
+
+ expect { subject }
+ .to change { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(**tracking_params) }
.by(1)
end
end
@@ -65,7 +75,7 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::MERGE_REQUEST_ACTION }
+ let(:event_action) { :merge_request_action }
end
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
@@ -94,7 +104,7 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::MERGE_REQUEST_ACTION }
+ let(:event_action) { :merge_request_action }
end
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
@@ -123,7 +133,7 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::MERGE_REQUEST_ACTION }
+ let(:event_action) { :merge_request_action }
end
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
@@ -273,8 +283,10 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION }
+ let(:event_action) { :wiki_action }
end
+
+ it_behaves_like "it records a git write event"
end
(Event.actions.keys - Event::WIKI_ACTIONS).each do |bad_action|
@@ -309,9 +321,11 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
it_behaves_like 'service for creating a push event', PushEventPayloadService
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION }
+ let(:event_action) { :project_action }
end
+ it_behaves_like "it records a git write event"
+
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
let(:category) { described_class.to_s }
let(:action) { :push }
@@ -335,9 +349,11 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
it_behaves_like 'service for creating a push event', BulkPushEventPayloadService
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION }
+ let(:event_action) { :project_action }
end
+ it_behaves_like "it records a git write event"
+
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
let(:category) { described_class.to_s }
let(:action) { :push }
@@ -397,14 +413,16 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION }
+ let(:event_action) { :design_action }
end
+ it_behaves_like "it records a git write event"
+
describe 'Snowplow tracking' do
let(:project) { design.project }
let(:namespace) { project.namespace }
let(:category) { described_class.name }
- let(:property) { Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION.to_s }
+ let(:property) { :design_action.to_s }
let(:label) { ::EventCreateService::DEGIGN_EVENT_LABEL }
context 'for create event' do
@@ -444,9 +462,11 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
it_behaves_like "it records the event in the event counter" do
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION }
+ let(:event_action) { :design_action }
end
+ it_behaves_like "it records a git write event"
+
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
subject(:design_service) { service.destroy_designs([design], author) }
@@ -455,7 +475,7 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
let(:category) { described_class.name }
let(:action) { 'destroy' }
let(:user) { author }
- let(:property) { Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION.to_s }
+ let(:property) { :design_action.to_s }
let(:label) { ::EventCreateService::DEGIGN_EVENT_LABEL }
end
end
@@ -466,7 +486,7 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
let(:note) { create(:note) }
let(:author) { create(:user) }
- let(:event_action) { Gitlab::UsageDataCounters::TrackUniqueEvents::MERGE_REQUEST_ACTION }
+ let(:event_action) { :merge_request_action }
it { expect(leave_note).to be_truthy }
@@ -496,10 +516,9 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
context 'when it is not a diff note' do
it 'does not change the unique action counter' do
- counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
- tracking_params = { event_action: event_action, date_from: Date.yesterday, date_to: Date.today }
+ tracking_params = { event_names: event_action, start_date: Date.yesterday, end_date: Date.today }
- expect { subject }.not_to change { counter_class.count_unique_events(**tracking_params) }
+ expect { subject }.not_to change { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(**tracking_params) }
end
end
end