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
3f9eca59
Commit
3f9eca59
authored
Dec 16, 2020
by
Hordur Freyr Yngvason
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track usage for Terraform State API
parent
ca20f5cf
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
3 deletions
+62
-3
changelogs/unreleased/add-terraform-state-api-usage-tracking.yml
...ogs/unreleased/add-terraform-state-api-usage-tracking.yml
+5
-0
config/feature_flags/development/usage_data_p_terraform_state_api_unique_users.yml
...lopment/usage_data_p_terraform_state_api_unique_users.yml
+8
-0
lib/api/terraform/state.rb
lib/api/terraform/state.rb
+2
-0
lib/gitlab/usage_data_counters/hll_redis_counter.rb
lib/gitlab/usage_data_counters/hll_redis_counter.rb
+1
-1
lib/gitlab/usage_data_counters/known_events/common.yml
lib/gitlab/usage_data_counters/known_events/common.yml
+6
-0
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
.../lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
+2
-1
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+1
-1
spec/requests/api/terraform/state_spec.rb
spec/requests/api/terraform/state_spec.rb
+37
-0
No files found.
changelogs/unreleased/add-terraform-state-api-usage-tracking.yml
0 → 100644
View file @
3f9eca59
---
title
:
Track usage for Terraform State API
merge_request
:
50224
author
:
type
:
added
config/feature_flags/development/usage_data_p_terraform_state_api_unique_users.yml
0 → 100644
View file @
3f9eca59
---
name
:
usage_data_p_terraform_state_api_unique_users
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50224
rollout_issue_url
:
milestone
:
'
13.8'
type
:
development
group
:
group::configure
default_enabled
:
true
lib/api/terraform/state.rb
View file @
3f9eca59
...
@@ -14,6 +14,8 @@ module API
...
@@ -14,6 +14,8 @@ module API
before
do
before
do
authenticate!
authenticate!
authorize!
:read_terraform_state
,
user_project
authorize!
:read_terraform_state
,
user_project
increment_unique_values
(
'p_terraform_state_api_unique_users'
,
current_user
.
id
)
end
end
params
do
params
do
...
...
lib/gitlab/usage_data_counters/hll_redis_counter.rb
View file @
3f9eca59
...
@@ -123,7 +123,7 @@ module Gitlab
...
@@ -123,7 +123,7 @@ module Gitlab
Gitlab
::
Redis
::
HLL
.
add
(
key:
redis_key
(
event
,
time
,
context
),
value:
value
,
expiry:
expiry
(
event
))
Gitlab
::
Redis
::
HLL
.
add
(
key:
redis_key
(
event
,
time
,
context
),
value:
value
,
expiry:
expiry
(
event
))
end
end
# The aray of valid context on which we allow tracking
# The ar
r
ay of valid context on which we allow tracking
def
valid_context_list
def
valid_context_list
Plan
.
all_plans
Plan
.
all_plans
end
end
...
...
lib/gitlab/usage_data_counters/known_events/common.yml
View file @
3f9eca59
...
@@ -440,3 +440,9 @@
...
@@ -440,3 +440,9 @@
category
:
code_review
category
:
code_review
aggregation
:
weekly
aggregation
:
weekly
feature_flag
:
usage_data_i_code_review_mr_single_file_diffs
feature_flag
:
usage_data_i_code_review_mr_single_file_diffs
# Terraform
-
name
:
p_terraform_state_api_unique_users
category
:
terraform
redis_slot
:
terraform
aggregation
:
weekly
feature_flag
:
usage_data_p_terraform_state_api_unique_users
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
View file @
3f9eca59
...
@@ -46,7 +46,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
...
@@ -46,7 +46,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
'container_packages'
,
'container_packages'
,
'tag_packages'
,
'tag_packages'
,
'snippets'
,
'snippets'
,
'code_review'
'code_review'
,
'terraform'
)
)
end
end
end
end
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
3f9eca59
...
@@ -1260,7 +1260,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
...
@@ -1260,7 +1260,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject
{
described_class
.
redis_hll_counters
}
subject
{
described_class
.
redis_hll_counters
}
let
(
:categories
)
{
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
categories
}
let
(
:categories
)
{
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
categories
}
let
(
:ineligible_total_categories
)
{
%w[source_code testing ci_secrets_management incident_management_alerts snippets]
}
let
(
:ineligible_total_categories
)
{
%w[source_code testing ci_secrets_management incident_management_alerts snippets
terraform
]
}
it
'has all known_events'
do
it
'has all known_events'
do
expect
(
subject
).
to
have_key
(
:redis_hll_counters
)
expect
(
subject
).
to
have_key
(
:redis_hll_counters
)
...
...
spec/requests/api/terraform/state_spec.rb
View file @
3f9eca59
...
@@ -21,9 +21,36 @@ RSpec.describe API::Terraform::State do
...
@@ -21,9 +21,36 @@ RSpec.describe API::Terraform::State do
stub_terraform_state_object_storage
stub_terraform_state_object_storage
end
end
shared_examples
'endpoint with unique user tracking'
do
context
'without authentication'
do
let
(
:auth_header
)
{
basic_auth_header
(
'bad'
,
'token'
)
}
before
do
stub_feature_flags
(
usage_data_p_terraform_state_api_unique_users:
false
)
end
it
'does not track unique event'
do
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
receive
(
:track_event
)
request
end
end
context
'with maintainer permissions'
do
let
(
:current_user
)
{
maintainer
}
it_behaves_like
'tracking unique hll events'
,
:usage_data_p_terraform_state_api_unique_users
do
let
(
:target_id
)
{
'p_terraform_state_api_unique_users'
}
let
(
:expected_type
)
{
instance_of
(
Integer
)
}
end
end
end
describe
'GET /projects/:id/terraform/state/:name'
do
describe
'GET /projects/:id/terraform/state/:name'
do
subject
(
:request
)
{
get
api
(
state_path
),
headers:
auth_header
}
subject
(
:request
)
{
get
api
(
state_path
),
headers:
auth_header
}
it_behaves_like
'endpoint with unique user tracking'
context
'without authentication'
do
context
'without authentication'
do
let
(
:auth_header
)
{
basic_auth_header
(
'bad'
,
'token'
)
}
let
(
:auth_header
)
{
basic_auth_header
(
'bad'
,
'token'
)
}
...
@@ -117,6 +144,8 @@ RSpec.describe API::Terraform::State do
...
@@ -117,6 +144,8 @@ RSpec.describe API::Terraform::State do
subject
(
:request
)
{
post
api
(
state_path
),
headers:
auth_header
,
as: :json
,
params:
params
}
subject
(
:request
)
{
post
api
(
state_path
),
headers:
auth_header
,
as: :json
,
params:
params
}
it_behaves_like
'endpoint with unique user tracking'
context
'when terraform state with a given name is already present'
do
context
'when terraform state with a given name is already present'
do
context
'with maintainer permissions'
do
context
'with maintainer permissions'
do
let
(
:current_user
)
{
maintainer
}
let
(
:current_user
)
{
maintainer
}
...
@@ -219,6 +248,8 @@ RSpec.describe API::Terraform::State do
...
@@ -219,6 +248,8 @@ RSpec.describe API::Terraform::State do
describe
'DELETE /projects/:id/terraform/state/:name'
do
describe
'DELETE /projects/:id/terraform/state/:name'
do
subject
(
:request
)
{
delete
api
(
state_path
),
headers:
auth_header
}
subject
(
:request
)
{
delete
api
(
state_path
),
headers:
auth_header
}
it_behaves_like
'endpoint with unique user tracking'
context
'with maintainer permissions'
do
context
'with maintainer permissions'
do
let
(
:current_user
)
{
maintainer
}
let
(
:current_user
)
{
maintainer
}
...
@@ -256,6 +287,8 @@ RSpec.describe API::Terraform::State do
...
@@ -256,6 +287,8 @@ RSpec.describe API::Terraform::State do
subject
(
:request
)
{
post
api
(
"
#{
state_path
}
/lock"
),
headers:
auth_header
,
params:
params
}
subject
(
:request
)
{
post
api
(
"
#{
state_path
}
/lock"
),
headers:
auth_header
,
params:
params
}
it_behaves_like
'endpoint with unique user tracking'
it
'locks the terraform state'
do
it
'locks the terraform state'
do
request
request
...
@@ -305,6 +338,10 @@ RSpec.describe API::Terraform::State do
...
@@ -305,6 +338,10 @@ RSpec.describe API::Terraform::State do
subject
(
:request
)
{
delete
api
(
"
#{
state_path
}
/lock"
),
headers:
auth_header
,
params:
params
}
subject
(
:request
)
{
delete
api
(
"
#{
state_path
}
/lock"
),
headers:
auth_header
,
params:
params
}
it_behaves_like
'endpoint with unique user tracking'
do
let
(
:lock_id
)
{
'irrelevant to this test, just needs to be present'
}
end
context
'with the correct lock id'
do
context
'with the correct lock id'
do
let
(
:lock_id
)
{
'123-456'
}
let
(
:lock_id
)
{
'123-456'
}
...
...
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