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
20531aa0
Commit
20531aa0
authored
Mar 25, 2021
by
Rajendra Kadam
Committed by
Alper Akgun
Mar 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API get handler for usage data queries
Add specs for the API calls
parent
4ee871cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
0 deletions
+103
-0
config/feature_flags/ops/usage_data_queries_api.yml
config/feature_flags/ops/usage_data_queries_api.yml
+8
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/usage_data_queries.rb
lib/api/usage_data_queries.rb
+27
-0
spec/requests/api/usage_data_queries_spec.rb
spec/requests/api/usage_data_queries_spec.rb
+67
-0
No files found.
config/feature_flags/ops/usage_data_queries_api.yml
0 → 100644
View file @
20531aa0
---
name
:
usage_data_queries_api
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57016
rollout_issue_url
:
milestone
:
'
13.11'
type
:
ops
group
:
group::product intelligence
default_enabled
:
false
lib/api/api.rb
View file @
20531aa0
...
@@ -293,6 +293,7 @@ module API
...
@@ -293,6 +293,7 @@ module API
mount
::
API
::
Triggers
mount
::
API
::
Triggers
mount
::
API
::
Unleash
mount
::
API
::
Unleash
mount
::
API
::
UsageData
mount
::
API
::
UsageData
mount
::
API
::
UsageDataQueries
mount
::
API
::
UserCounts
mount
::
API
::
UserCounts
mount
::
API
::
Users
mount
::
API
::
Users
mount
::
API
::
Variables
mount
::
API
::
Variables
...
...
lib/api/usage_data_queries.rb
0 → 100644
View file @
20531aa0
# frozen_string_literal: true
module
API
class
UsageDataQueries
<
::
API
::
Base
before
{
authenticated_as_admin!
}
feature_category
:usage_ping
namespace
'usage_data'
do
before
do
not_found!
unless
Feature
.
enabled?
(
:usage_data_queries_api
,
default_enabled:
false
,
type: :ops
)
end
desc
'Get raw SQL queries for usage data SQL metrics'
do
detail
'This feature was introduced in GitLab 13.11.'
end
get
'queries'
do
Gitlab
::
QueryLimiting
.
disable!
(
'https://gitlab.com/gitlab-org/gitlab/-/issues/325534'
)
queries
=
Gitlab
::
UsageDataQueries
.
uncached_data
present
queries
end
end
end
end
spec/requests/api/usage_data_queries_spec.rb
0 → 100644
View file @
20531aa0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
API
::
UsageDataQueries
do
include
UsageDataHelpers
let_it_be
(
:admin
)
{
create
(
:user
,
admin:
true
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
before
do
stub_usage_data_connections
end
describe
'GET /usage_data/usage_data_queries'
do
let
(
:endpoint
)
{
'/usage_data/queries'
}
context
'with authentication'
do
before
do
stub_feature_flags
(
usage_data_queries_api:
true
)
end
it
'returns queries if user is admin'
do
get
api
(
endpoint
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'active_user_count'
]).
to
start_with
(
'SELECT COUNT("users"."id") FROM "users"'
)
end
it
'returns forbidden if user is not admin'
do
get
api
(
endpoint
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
'without authentication'
do
before
do
stub_feature_flags
(
usage_data_queries_api:
true
)
end
it
'returns unauthorized'
do
get
api
(
endpoint
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
context
'when feature_flag is disabled'
do
before
do
stub_feature_flags
(
usage_data_queries_api:
false
)
end
it
'returns not_found for admin'
do
get
api
(
endpoint
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'returns forbidden for non-admin'
do
get
api
(
endpoint
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
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