diff options
author | Manoj MJ <mmj@gitlab.com> | 2019-09-09 03:38:42 +0000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-09-09 03:38:42 +0000 |
commit | b041321a355b507cd9329e80935e960c2b9114eb (patch) | |
tree | 5013fa7c76955750a869b5a071a1d8d8cecd9686 /lib/api | |
parent | e3763f9cb60e7f1ddf8c40ddc4bf05747e944f9b (diff) | |
download | gitlab-ce-b041321a355b507cd9329e80935e960c2b9114eb.tar.gz |
Application Statistics API
This change implements Application
Statistics API
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 49 | ||||
-rw-r--r-- | lib/api/statistics.rb | 18 |
3 files changed, 68 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index aa6a67d817a..88d411e22a9 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -161,6 +161,7 @@ module API mount ::API::Settings mount ::API::SidekiqMetrics mount ::API::Snippets + mount ::API::Statistics mount ::API::Submodules mount ::API::Subscriptions mount ::API::Suggestions diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f7cd6d35854..c9b3483acaf 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1169,6 +1169,55 @@ module API expose :message, :starts_at, :ends_at, :color, :font end + class ApplicationStatistics < Grape::Entity + include ActionView::Helpers::NumberHelper + include CountHelper + + expose :forks do |counts| + approximate_fork_count_with_delimiters(counts) + end + + expose :issues do |counts| + approximate_count_with_delimiters(counts, ::Issue) + end + + expose :merge_requests do |counts| + approximate_count_with_delimiters(counts, ::MergeRequest) + end + + expose :notes do |counts| + approximate_count_with_delimiters(counts, ::Note) + end + + expose :snippets do |counts| + approximate_count_with_delimiters(counts, ::Snippet) + end + + expose :ssh_keys do |counts| + approximate_count_with_delimiters(counts, ::Key) + end + + expose :milestones do |counts| + approximate_count_with_delimiters(counts, ::Milestone) + end + + expose :users do |counts| + approximate_count_with_delimiters(counts, ::User) + end + + expose :projects do |counts| + approximate_count_with_delimiters(counts, ::Project) + end + + expose :groups do |counts| + approximate_count_with_delimiters(counts, ::Group) + end + + expose :active_users do |_| + number_with_delimiter(::User.active.count) + end + end + class ApplicationSetting < Grape::Entity def self.exposed_attributes attributes = ::ApplicationSettingsHelper.visible_attributes diff --git a/lib/api/statistics.rb b/lib/api/statistics.rb new file mode 100644 index 00000000000..d2dce34dfa5 --- /dev/null +++ b/lib/api/statistics.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module API + class Statistics < Grape::API + before { authenticated_as_admin! } + + COUNTED_ITEMS = [Project, User, Group, ForkNetworkMember, ForkNetwork, Issue, + MergeRequest, Note, Snippet, Key, Milestone].freeze + + desc 'Get the current application statistics' do + success Entities::ApplicationStatistics + end + get "application/statistics" do + counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS) + present counts, with: Entities::ApplicationStatistics + end + end +end |