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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-11-27 18:09:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-27 18:09:20 +0300
commit362c8e8462d38d529d2357649cbb2836cad2452c (patch)
treeb304d6531095f2cbc6c43cf8db1800c338b0e11b /lib/gitlab/tracking
parent55abfc8a0c81b95b532b243bd701033aa0aa2b07 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/tracking')
-rw-r--r--lib/gitlab/tracking/service_ping_context.rb43
1 files changed, 33 insertions, 10 deletions
diff --git a/lib/gitlab/tracking/service_ping_context.rb b/lib/gitlab/tracking/service_ping_context.rb
index 3177dca4ef7..d31ca69a10c 100644
--- a/lib/gitlab/tracking/service_ping_context.rb
+++ b/lib/gitlab/tracking/service_ping_context.rb
@@ -4,21 +4,22 @@ module Gitlab
module Tracking
class ServicePingContext
SCHEMA_URL = 'iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-0'
- ALLOWED_SOURCES = %i[redis_hll].freeze
+ REDISHLL_SOURCE = :redis_hll
+ REDIS_SOURCE = :redis
- def initialize(data_source:, event:)
- unless ALLOWED_SOURCES.include?(data_source)
- raise ArgumentError, "#{data_source} is not acceptable data source for ServicePingContext"
- end
+ ALLOWED_SOURCES = [REDISHLL_SOURCE, REDIS_SOURCE].freeze
- @payload = {
- data_source: data_source,
- event_name: event
- }
+ def initialize(data_source:, event: nil, key_path: nil)
+ check_configuration(data_source, event, key_path)
+
+ @payload = { data_source: data_source }
+
+ payload[:event_name] = event if data_source.eql? REDISHLL_SOURCE
+ payload[:key_path] = key_path if data_source.eql? REDIS_SOURCE
end
def to_context
- SnowplowTracker::SelfDescribingJson.new(SCHEMA_URL, @payload)
+ SnowplowTracker::SelfDescribingJson.new(SCHEMA_URL, payload)
end
def to_h
@@ -27,6 +28,28 @@ module Gitlab
data: @payload
}
end
+
+ private
+
+ attr_reader :payload
+
+ def check_configuration(data_source, event, key_path)
+ unless ALLOWED_SOURCES.include?(data_source)
+ configuration_error("#{data_source} is not acceptable data source for ServicePingContext")
+ end
+
+ if REDISHLL_SOURCE.eql?(data_source) && event.nil?
+ configuration_error("event attribute can not be missing for #{REDISHLL_SOURCE} data source")
+ end
+
+ return unless REDIS_SOURCE.eql?(data_source) && key_path.nil?
+
+ configuration_error("key_path attribute can not be missing for #{REDIS_SOURCE} data source")
+ end
+
+ def configuration_error(message)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(ArgumentError.new(message))
+ end
end
end
end