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
e1a8aa81
Commit
e1a8aa81
authored
Apr 08, 2020
by
Qingyu Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collect object store config in usage data
parent
593e74a8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
166 additions
and
0 deletions
+166
-0
changelogs/unreleased/208250-collect-object-store-config-in-usage-data.yml
...ased/208250-collect-object-store-config-in-usage-data.yml
+5
-0
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+35
-0
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+72
-0
spec/support/helpers/usage_data_helpers.rb
spec/support/helpers/usage_data_helpers.rb
+54
-0
No files found.
changelogs/unreleased/208250-collect-object-store-config-in-usage-data.yml
0 → 100644
View file @
e1a8aa81
---
title
:
Collect object store config in usage data
merge_request
:
29149
author
:
type
:
added
lib/gitlab/usage_data.rb
View file @
e1a8aa81
...
...
@@ -24,6 +24,7 @@ module Gitlab
.
merge
(
features_usage_data
)
.
merge
(
components_usage_data
)
.
merge
(
cycle_analytics_usage_data
)
.
merge
(
object_store_usage_data
)
end
def
to_json
(
force_refresh:
false
)
...
...
@@ -237,6 +238,40 @@ module Gitlab
'unknown_app_server_type'
end
def
object_store_config
(
component
)
config
=
alt_usage_data
(
fallback:
nil
)
do
Settings
[
component
][
'object_store'
]
end
if
config
{
enabled:
alt_usage_data
{
Settings
[
component
][
'enabled'
]
},
object_store:
{
enabled:
alt_usage_data
{
config
[
'enabled'
]
},
direct_upload:
alt_usage_data
{
config
[
'direct_upload'
]
},
background_upload:
alt_usage_data
{
config
[
'background_upload'
]
},
provider:
alt_usage_data
{
config
[
'connection'
][
'provider'
]
}
}
}
else
{
enabled:
alt_usage_data
{
Settings
[
component
][
'enabled'
]
}
}
end
end
def
object_store_usage_data
{
object_store:
{
artifacts:
object_store_config
(
'artifacts'
),
external_diffs:
object_store_config
(
'external_diffs'
),
lfs:
object_store_config
(
'lfs'
),
uploads:
object_store_config
(
'uploads'
),
packages:
object_store_config
(
'packages'
)
}
}
end
def
ingress_modsecurity_usage
::
Clusters
::
Applications
::
IngressModsecurityUsageService
.
new
.
execute
end
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
e1a8aa81
...
...
@@ -7,6 +7,8 @@ describe Gitlab::UsageData, :aggregate_failures do
before
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:transaction_open?
).
and_return
(
false
)
stub_object_store_settings
end
shared_examples
"usage data execution"
do
...
...
@@ -82,6 +84,16 @@ describe Gitlab::UsageData, :aggregate_failures do
expect
(
count_data
[
:clusters_management_project
]).
to
eq
(
1
)
end
it
'gathers object store usage correctly'
do
expect
(
subject
[
:object_store
]).
to
eq
(
{
artifacts:
{
enabled:
true
,
object_store:
{
enabled:
true
,
direct_upload:
true
,
background_upload:
false
,
provider:
"AWS"
}
},
external_diffs:
{
enabled:
false
},
lfs:
{
enabled:
true
,
object_store:
{
enabled:
false
,
direct_upload:
true
,
background_upload:
false
,
provider:
"AWS"
}
},
uploads:
{
enabled:
nil
,
object_store:
{
enabled:
false
,
direct_upload:
true
,
background_upload:
false
,
provider:
"AWS"
}
},
packages:
{
enabled:
true
,
object_store:
{
enabled:
false
,
direct_upload:
false
,
background_upload:
true
,
provider:
"AWS"
}
}
}
)
end
it
'works when queries time out'
do
allow_any_instance_of
(
ActiveRecord
::
Relation
)
.
to
receive
(
:count
).
and_raise
(
ActiveRecord
::
StatementInvalid
.
new
(
''
))
...
...
@@ -223,6 +235,66 @@ describe Gitlab::UsageData, :aggregate_failures do
end
end
describe
'#object_store_config'
do
let
(
:component
)
{
'lfs'
}
subject
{
described_class
.
object_store_config
(
component
)
}
context
'when object_store is not configured'
do
it
'returns component enable status only'
do
allow
(
Settings
).
to
receive
(
:[]
).
with
(
component
).
and_return
({
'enabled'
=>
false
})
expect
(
subject
).
to
eq
({
enabled:
false
})
end
end
context
'when object_store is configured'
do
it
'returns filtered object store config'
do
allow
(
Settings
).
to
receive
(
:[]
).
with
(
component
)
.
and_return
(
{
'enabled'
=>
true
,
'object_store'
=>
{
'enabled'
=>
true
,
'remote_directory'
=>
component
,
'direct_upload'
=>
true
,
'connection'
=>
{
'provider'
=>
'AWS'
,
'aws_access_key_id'
=>
'minio'
,
'aws_secret_access_key'
=>
'gdk-minio'
,
'region'
=>
'gdk'
,
'endpoint'
=>
'http://127.0.0.1:9000'
,
'path_style'
=>
true
},
'background_upload'
=>
false
,
'proxy_download'
=>
false
}
})
expect
(
subject
).
to
eq
(
{
enabled:
true
,
object_store:
{
enabled:
true
,
direct_upload:
true
,
background_upload:
false
,
provider:
"AWS"
}
})
end
end
context
'when retrieve component setting meets exception'
do
it
'returns -1 for component enable status'
do
allow
(
Settings
).
to
receive
(
:[]
).
with
(
component
).
and_raise
(
StandardError
)
expect
(
subject
).
to
eq
({
enabled:
-
1
})
end
end
end
describe
'#object_store_usage_data'
do
subject
{
described_class
.
object_store_usage_data
}
it
'fetches object store config of five components'
do
%w(artifacts external_diffs lfs uploads packages)
.
each
do
|
component
|
expect
(
described_class
).
to
receive
(
:object_store_config
).
with
(
component
).
and_return
(
"
#{
component
}
_object_store_config"
)
end
expect
(
subject
).
to
eq
(
object_store:
{
artifacts:
'artifacts_object_store_config'
,
external_diffs:
'external_diffs_object_store_config'
,
lfs:
'lfs_object_store_config'
,
uploads:
'uploads_object_store_config'
,
packages:
'packages_object_store_config'
})
end
end
describe
'#cycle_analytics_usage_data'
do
subject
{
described_class
.
cycle_analytics_usage_data
}
...
...
spec/support/helpers/usage_data_helpers.rb
View file @
e1a8aa81
...
...
@@ -153,5 +153,59 @@ module UsageDataHelpers
projects_with_expiration_policy_enabled_with_older_than_set_to_14d
projects_with_expiration_policy_enabled_with_older_than_set_to_30d
projects_with_expiration_policy_enabled_with_older_than_set_to_90d
object_store
)
.
freeze
def
stub_object_store_settings
allow
(
Settings
).
to
receive
(
:[]
).
with
(
'artifacts'
)
.
and_return
(
{
'enabled'
=>
true
,
'object_store'
=>
{
'enabled'
=>
true
,
'remote_directory'
=>
'artifacts'
,
'direct_upload'
=>
true
,
'connection'
=>
{
'provider'
=>
'AWS'
,
'aws_access_key_id'
=>
'minio'
,
'aws_secret_access_key'
=>
'gdk-minio'
,
'region'
=>
'gdk'
,
'endpoint'
=>
'http://127.0.0.1:9000'
,
'path_style'
=>
true
},
'background_upload'
=>
false
,
'proxy_download'
=>
false
}
}
)
allow
(
Settings
).
to
receive
(
:[]
).
with
(
'external_diffs'
).
and_return
({
'enabled'
=>
false
})
allow
(
Settings
).
to
receive
(
:[]
).
with
(
'lfs'
)
.
and_return
(
{
'enabled'
=>
true
,
'object_store'
=>
{
'enabled'
=>
false
,
'remote_directory'
=>
'lfs-objects'
,
'direct_upload'
=>
true
,
'connection'
=>
{
'provider'
=>
'AWS'
,
'aws_access_key_id'
=>
'minio'
,
'aws_secret_access_key'
=>
'gdk-minio'
,
'region'
=>
'gdk'
,
'endpoint'
=>
'http://127.0.0.1:9000'
,
'path_style'
=>
true
},
'background_upload'
=>
false
,
'proxy_download'
=>
false
}
}
)
allow
(
Settings
).
to
receive
(
:[]
).
with
(
'uploads'
)
.
and_return
(
{
'object_store'
=>
{
'enabled'
=>
false
,
'remote_directory'
=>
'uploads'
,
'direct_upload'
=>
true
,
'connection'
=>
{
'provider'
=>
'AWS'
,
'aws_access_key_id'
=>
'minio'
,
'aws_secret_access_key'
=>
'gdk-minio'
,
'region'
=>
'gdk'
,
'endpoint'
=>
'http://127.0.0.1:9000'
,
'path_style'
=>
true
},
'background_upload'
=>
false
,
'proxy_download'
=>
false
}
}
)
allow
(
Settings
).
to
receive
(
:[]
).
with
(
'packages'
)
.
and_return
(
{
'enabled'
=>
true
,
'object_store'
=>
{
'enabled'
=>
false
,
'remote_directory'
=>
'packages'
,
'direct_upload'
=>
false
,
'connection'
=>
{
'provider'
=>
'AWS'
,
'aws_access_key_id'
=>
'minio'
,
'aws_secret_access_key'
=>
'gdk-minio'
,
'region'
=>
'gdk'
,
'endpoint'
=>
'http://127.0.0.1:9000'
,
'path_style'
=>
true
},
'background_upload'
=>
true
,
'proxy_download'
=>
false
}
}
)
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