Commit 61130880 authored by Markus Koller's avatar Markus Koller

Track wiki page views in usage data

This adds a new `view` event in `WikiPageCounter` and increases it every
time a wiki page is rendered.
parent 5a27361c
...@@ -67,6 +67,8 @@ module WikiActions ...@@ -67,6 +67,8 @@ module WikiActions
@ref = params[:version_id] @ref = params[:version_id]
@path = page.path @path = page.path
Gitlab::UsageDataCounters::WikiPageCounter.count(:view)
render 'shared/wikis/show' render 'shared/wikis/show'
elsif file_blob elsif file_blob
send_blob(wiki.repository, file_blob) send_blob(wiki.repository, file_blob)
......
---
title: Track wiki page views in usage data
merge_request: 38784
author:
type: changed
...@@ -230,9 +230,10 @@ An event dictionary is a single source of truth that outlines what events and pr ...@@ -230,9 +230,10 @@ An event dictionary is a single source of truth that outlines what events and pr
| `merge_requests` | `counts` | | | | | | `merge_requests` | `counts` | | | | |
| `merge_requests_users` | `counts` | | | | | | `merge_requests_users` | `counts` | | | | |
| `notes` | `counts` | | | | | | `notes` | `counts` | | | | |
| `wiki_pages_create` | `counts` | | | | | | `wiki_pages_view` | `counts` | `create` | | CE+EE | Number of viewed wiki pages |
| `wiki_pages_update` | `counts` | | | | | | `wiki_pages_create` | `counts` | `create` | | CE+EE | Number of created wiki pages |
| `wiki_pages_delete` | `counts` | | | | | | `wiki_pages_update` | `counts` | `create` | | CE+EE | Number of updated wiki pages |
| `wiki_pages_delete` | `counts` | `create` | | CE+EE | Number of deleted wiki pages |
| `web_ide_commits` | `counts` | | | | | | `web_ide_commits` | `counts` | | | | |
| `web_ide_views` | `counts` | | | | | | `web_ide_views` | `counts` | | | | |
| `web_ide_merge_requests` | `counts` | | | | | | `web_ide_merge_requests` | `counts` | | | | |
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Gitlab::UsageDataCounters module Gitlab::UsageDataCounters
class WikiPageCounter < BaseCounter class WikiPageCounter < BaseCounter
KNOWN_EVENTS = %w[create update delete].freeze KNOWN_EVENTS = %w[view create update delete].freeze
PREFIX = 'wiki_pages' PREFIX = 'wiki_pages'
end end
end end
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::WikiPageCounter do RSpec.describe Gitlab::UsageDataCounters::WikiPageCounter do
it_behaves_like 'a redis usage counter', 'Wiki Page', :view
it_behaves_like 'a redis usage counter', 'Wiki Page', :create it_behaves_like 'a redis usage counter', 'Wiki Page', :create
it_behaves_like 'a redis usage counter', 'Wiki Page', :update it_behaves_like 'a redis usage counter', 'Wiki Page', :update
it_behaves_like 'a redis usage counter', 'Wiki Page', :delete it_behaves_like 'a redis usage counter', 'Wiki Page', :delete
it_behaves_like 'a redis usage counter with totals', :wiki_pages, it_behaves_like 'a redis usage counter with totals', :wiki_pages,
view: 8,
create: 5, create: 5,
update: 3, update: 3,
delete: 2 delete: 2
......
...@@ -161,6 +161,14 @@ RSpec.shared_examples 'wiki controller actions' do ...@@ -161,6 +161,14 @@ RSpec.shared_examples 'wiki controller actions' do
expect(assigns(:sidebar_limited)).to be(false) expect(assigns(:sidebar_limited)).to be(false)
end end
it 'increases the page view counter' do
expect do
subject
expect(response).to have_gitlab_http_status(:ok)
end.to change { Gitlab::UsageDataCounters::WikiPageCounter.read(:view) }.by(1)
end
context 'when page content encoding is invalid' do context 'when page content encoding is invalid' do
it 'sets flash error' do it 'sets flash error' do
allow(controller).to receive(:valid_encoding?).and_return(false) allow(controller).to receive(:valid_encoding?).and_return(false)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment