Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 21:08:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 21:08:58 +0300
commit1ca9950d5f890cd8f185e1eda158b969a7244fe2 (patch)
tree6f62715938a4b2b001705c51c697609a8e0850ae /lib
parentbcc77054ee9aefd1e332e04a4189390fd5a3112e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/services.rb2
-rw-r--r--lib/gitlab/import_export/import_export.yml2
-rw-r--r--lib/gitlab/serverless/service.rb98
-rw-r--r--lib/gitlab/usage_data.rb2
4 files changed, 101 insertions, 3 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb
index e6b48274989..a3b5d2cc4b7 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -132,7 +132,7 @@ module API
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def slash_command_service(project, service_slug, params)
- project.services.active.where(instance: false).find do |service|
+ project.services.active.where(template: false).find do |service|
service.try(:token) == params[:token] && service.to_param == service_slug.underscore
end
end
diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml
index 9acc2098823..afa575241a1 100644
--- a/lib/gitlab/import_export/import_export.yml
+++ b/lib/gitlab/import_export/import_export.yml
@@ -257,7 +257,7 @@ excluded_attributes:
- :token
- :token_encrypted
services:
- - :instance
+ - :template
error_tracking_setting:
- :encrypted_token
- :encrypted_token_iv
diff --git a/lib/gitlab/serverless/service.rb b/lib/gitlab/serverless/service.rb
new file mode 100644
index 00000000000..643e076c587
--- /dev/null
+++ b/lib/gitlab/serverless/service.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+class Gitlab::Serverless::Service
+ include Gitlab::Utils::StrongMemoize
+
+ def initialize(attributes)
+ @attributes = attributes
+ end
+
+ def name
+ @attributes.dig('metadata', 'name')
+ end
+
+ def namespace
+ @attributes.dig('metadata', 'namespace')
+ end
+
+ def environment_scope
+ @attributes.dig('environment_scope')
+ end
+
+ def environment
+ @attributes.dig('environment')
+ end
+
+ def podcount
+ @attributes.dig('podcount')
+ end
+
+ def created_at
+ strong_memoize(:created_at) do
+ timestamp = @attributes.dig('metadata', 'creationTimestamp')
+ DateTime.parse(timestamp) if timestamp
+ end
+ end
+
+ def image
+ @attributes.dig(
+ 'spec',
+ 'runLatest',
+ 'configuration',
+ 'build',
+ 'template',
+ 'name')
+ end
+
+ def description
+ knative_07_description || knative_05_06_description
+ end
+
+ def cluster
+ @attributes.dig('cluster')
+ end
+
+ def url
+ proxy_url || knative_06_07_url || knative_05_url
+ end
+
+ private
+
+ def proxy_url
+ if cluster&.serverless_domain
+ Gitlab::Serverless::FunctionURI.new(function: name, cluster: cluster.serverless_domain, environment: environment)
+ end
+ end
+
+ def knative_07_description
+ @attributes.dig(
+ 'spec',
+ 'template',
+ 'metadata',
+ 'annotations',
+ 'Description'
+ )
+ end
+
+ def knative_05_06_description
+ @attributes.dig(
+ 'spec',
+ 'runLatest',
+ 'configuration',
+ 'revisionTemplate',
+ 'metadata',
+ 'annotations',
+ 'Description')
+ end
+
+ def knative_05_url
+ domain = @attributes.dig('status', 'domain')
+ return unless domain
+
+ "http://#{domain}"
+ end
+
+ def knative_06_07_url
+ @attributes.dig('status', 'url')
+ end
+end
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index 75fa3f4c718..f10eb82e03e 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -179,7 +179,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def services_usage
- service_counts = count(Service.active.where(instance: false).where.not(type: 'JiraService').group(:type), fallback: Hash.new(-1))
+ service_counts = count(Service.active.where(template: false).where.not(type: 'JiraService').group(:type), fallback: Hash.new(-1))
results = Service.available_services_names.each_with_object({}) do |service_name, response|
response["projects_#{service_name}_active".to_sym] = service_counts["#{service_name}_service".camelize] || 0