Commit d4af731f authored by Mark Chao's avatar Mark Chao

Merge branch 'usage-ping-no-sql-api' into 'master'

Add  Non SQL data metrics API [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!57050
parents ffccfad8 e5cddc97
---
name: usage_data_non_sql_metrics
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57050
rollout_issue_url:
milestone: '13.11'
type: ops
group: group::product intelligence
default_enabled: false
......@@ -294,6 +294,7 @@ module API
mount ::API::Unleash
mount ::API::UsageData
mount ::API::UsageDataQueries
mount ::API::UsageDataNonSqlMetrics
mount ::API::UserCounts
mount ::API::Users
mount ::API::Variables
......
# frozen_string_literal: true
module API
class UsageDataNonSqlMetrics < ::API::Base
before { authenticated_as_admin! }
feature_category :usage_ping
namespace 'usage_data' do
before do
not_found! unless Feature.enabled?(:usage_data_non_sql_metrics, default_enabled: :yaml, type: :ops)
end
desc 'Get Non SQL usage ping metrics' do
detail 'This feature was introduced in GitLab 13.11.'
end
get 'non_sql_metrics' do
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/325534')
data = Gitlab::UsageDataNonSqlMetrics.uncached_data
present data
end
end
end
end
......@@ -8,7 +8,7 @@ module API
namespace 'usage_data' do
before do
not_found! unless Feature.enabled?(:usage_data_queries_api, default_enabled: false, type: :ops)
not_found! unless Feature.enabled?(:usage_data_queries_api, default_enabled: :yaml, type: :ops)
end
desc 'Get raw SQL queries for usage data SQL metrics' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::UsageDataNonSqlMetrics 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/non_sql_metrics' do
let(:endpoint) { '/usage_data/non_sql_metrics' }
context 'with authentication' do
before do
stub_feature_flags(usage_data_non_sql_metrics: true)
end
it 'returns non sql metrics if user is admin' do
get api(endpoint, admin)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['counts']).to be_a(Hash)
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_non_sql_metrics: 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_non_sql_metrics: 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
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