summaryrefslogtreecommitdiff
path: root/lib/api/internal/kubernetes.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/api/internal/kubernetes.rb
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/api/internal/kubernetes.rb')
-rw-r--r--lib/api/internal/kubernetes.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/api/internal/kubernetes.rb b/lib/api/internal/kubernetes.rb
index 7f64fd7efe3..6d5dfd086e7 100644
--- a/lib/api/internal/kubernetes.rb
+++ b/lib/api/internal/kubernetes.rb
@@ -4,7 +4,16 @@ module API
# Kubernetes Internal API
module Internal
class Kubernetes < Grape::API::Instance
+ before do
+ check_feature_enabled
+ authenticate_gitlab_kas_request!
+ end
+
helpers do
+ def authenticate_gitlab_kas_request!
+ unauthorized! unless Gitlab::Kas.verify_api_request(headers)
+ end
+
def agent_token
@agent_token ||= cluster_agent_token_from_authorization_token
end
@@ -36,7 +45,7 @@ module API
end
def check_feature_enabled
- not_found! unless Feature.enabled?(:kubernetes_agent_internal_api)
+ not_found! unless Feature.enabled?(:kubernetes_agent_internal_api, default_enabled: true, type: :ops)
end
def check_agent_token
@@ -47,7 +56,6 @@ module API
namespace 'internal' do
namespace 'kubernetes' do
before do
- check_feature_enabled
check_agent_token
end
@@ -89,6 +97,26 @@ module API
}
end
end
+
+ namespace 'kubernetes/usage_metrics' do
+ desc 'POST usage metrics' do
+ detail 'Updates usage metrics for agent'
+ end
+ params do
+ requires :gitops_sync_count, type: Integer, desc: 'The count to increment the gitops_sync metric by'
+ end
+ post '/' do
+ gitops_sync_count = params[:gitops_sync_count]
+
+ if gitops_sync_count < 0
+ bad_request!('gitops_sync_count must be greater than or equal to zero')
+ else
+ Gitlab::UsageDataCounters::KubernetesAgentCounter.increment_gitops_sync(gitops_sync_count)
+
+ no_content!
+ end
+ end
+ end
end
end
end