Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ad074737
Commit
ad074737
authored
Jul 09, 2020
by
Dmytro Zaporozhets
Committed by
Markus Koller
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add product analytics event model
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
57645dbd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
app/models/product_analytics_event.rb
app/models/product_analytics_event.rb
+20
-0
db/fixtures/development/27_product_analytics_events.rb
db/fixtures/development/27_product_analytics_events.rb
+56
-0
spec/factories/product_analytics_event.rb
spec/factories/product_analytics_event.rb
+24
-0
spec/models/product_analytics_event_spec.rb
spec/models/product_analytics_event_spec.rb
+17
-0
No files found.
app/models/product_analytics_event.rb
0 → 100644
View file @
ad074737
# frozen_string_literal: true
class
ProductAnalyticsEvent
<
ApplicationRecord
self
.
table_name
=
'product_analytics_events_experimental'
# Ignore that the partition key :project_id is part of the formal primary key
self
.
primary_key
=
:id
belongs_to
:project
# There is no default Rails timestamps in the table.
# collector_tstamp is a timestamp when a collector recorded an event.
scope
:order_by_time
,
->
{
order
(
collector_tstamp: :desc
)
}
# If we decide to change this scope to use date_trunc('day', collector_tstamp),
# we should remember that a btree index on collector_tstamp will be no longer effective.
scope
:timerange
,
->
(
duration
,
today
=
Time
.
zone
.
today
)
{
where
(
'collector_tstamp BETWEEN ? AND ? '
,
today
-
duration
+
1
,
today
+
1
)
}
end
db/fixtures/development/27_product_analytics_events.rb
0 → 100644
View file @
ad074737
# frozen_string_literal: true
Gitlab
::
Seeder
.
quiet
do
# The data set takes approximately 2 minutes to load,
# so its put behind the flag. To seed this data use the flag and the filter:
# SEED_PRODUCT_ANALYTICS_EVENTS=1 FILTER=product_analytics_events rake db:seed_fu
flag
=
'SEED_PRODUCT_ANALYTICS_EVENTS'
if
ENV
[
flag
]
Project
.
all
.
sample
(
2
).
each
do
|
project
|
# Let's generate approx a week of events from now into the past with 1 minute step.
# To add some differentiation we add a random offset of up to 45 seconds.
10000
.
times
do
|
i
|
dvce_created_tstamp
=
DateTime
.
now
-
i
.
minute
-
rand
(
45
).
seconds
# Add a random delay to collector timestamp. Up to 2 seconds.
collector_tstamp
=
dvce_created_tstamp
+
rand
(
3
).
second
ProductAnalyticsEvent
.
create!
(
project_id:
project
.
id
,
platform:
[
"web"
,
"mob"
,
"mob"
,
"app"
].
sample
,
collector_tstamp:
collector_tstamp
,
dvce_created_tstamp:
dvce_created_tstamp
,
event:
nil
,
event_id:
SecureRandom
.
uuid
,
name_tracker:
"sp"
,
v_tracker:
"js-2.14.0"
,
v_collector:
Gitlab
::
VERSION
,
v_etl:
Gitlab
::
VERSION
,
domain_userid:
SecureRandom
.
uuid
,
domain_sessionidx:
4
,
page_url:
"
#{
project
.
web_url
}
/-/product_analytics/test"
,
page_title:
'Test page'
,
page_referrer:
"
#{
project
.
web_url
}
/-/product_analytics/test"
,
br_lang:
[
"en-US"
,
"en-US"
,
"en-GB"
,
"nl"
,
"fi"
].
sample
,
# https://www.andiamo.co.uk/resources/iso-language-codes/
br_features_pdf:
true
,
br_cookies:
[
true
,
true
,
true
,
false
].
sample
,
br_colordepth:
[
"24"
,
"24"
,
"16"
,
"8"
].
sample
,
os_timezone:
[
"America/Los_Angeles"
,
"America/Los_Angeles"
,
"America/Lima"
,
"Asia/Dubai"
,
"Africa/Bangui"
].
sample
,
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
doc_charset:
[
"UTF-8"
,
"UTF-8"
,
"UTF-8"
,
"DOS"
,
"EUC"
].
sample
,
domain_sessionid:
SecureRandom
.
uuid
)
end
unless
Feature
.
enabled?
(
:product_analytics
,
project
)
if
Feature
.
enable
(
:product_analytics
,
project
)
puts
"Product analytics feature was enabled for
#{
project
.
full_path
}
"
end
end
puts
"10K events added to
#{
project
.
full_path
}
"
end
else
puts
"Skipped. Use the `
#{
flag
}
` environment variable to enable."
end
end
spec/factories/product_analytics_event.rb
0 → 100644
View file @
ad074737
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:product_analytics_event
do
project
platform
{
'web'
}
collector_tstamp
{
DateTime
.
now
}
dvce_created_tstamp
{
DateTime
.
now
}
event_id
{
SecureRandom
.
uuid
}
name_tracker
{
'sp'
}
v_tracker
{
'js-2.14.0'
}
v_collector
{
'GitLab 13.1.0-pre'
}
v_etl
{
'GitLab 13.1.0-pre'
}
domain_userid
{
SecureRandom
.
uuid
}
domain_sessionidx
{
4
}
page_url
{
'http://localhost:3333/products/123'
}
br_lang
{
'en-US'
}
br_cookies
{
true
}
br_colordepth
{
'24'
}
os_timezone
{
'America/Los_Angeles'
}
doc_charset
{
'UTF-8'
}
domain_sessionid
{
SecureRandom
.
uuid
}
end
end
spec/models/product_analytics_event_spec.rb
0 → 100644
View file @
ad074737
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
ProductAnalyticsEvent
,
type: :model
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
expect
(
described_class
).
to
respond_to
(
:order_by_time
)
}
describe
'.timerange'
do
let_it_be
(
:event_1
)
{
create
(
:product_analytics_event
,
collector_tstamp:
Time
.
zone
.
now
-
1
.
day
)
}
let_it_be
(
:event_2
)
{
create
(
:product_analytics_event
,
collector_tstamp:
Time
.
zone
.
now
-
5
.
days
)
}
let_it_be
(
:event_3
)
{
create
(
:product_analytics_event
,
collector_tstamp:
Time
.
zone
.
now
-
15
.
days
)
}
it
{
expect
(
described_class
.
timerange
(
3
.
days
)).
to
match_array
([
event_1
])
}
it
{
expect
(
described_class
.
timerange
(
7
.
days
)).
to
match_array
([
event_1
,
event_2
])
}
it
{
expect
(
described_class
.
timerange
(
30
.
days
)).
to
match_array
([
event_1
,
event_2
,
event_3
])
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment