blob: 2135101e0e386ef33f8e2b5137b7349ff90e45da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# frozen_string_literal: true
module Gitlab
module Tracking
class ServicePingContext
SCHEMA_URL = 'iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-1'
REDISHLL_SOURCE = :redis_hll
REDIS_SOURCE = :redis
ALLOWED_SOURCES = [REDISHLL_SOURCE, REDIS_SOURCE].freeze
def initialize(data_source:, event: nil)
check_configuration(data_source, event)
@payload = { data_source: data_source }
payload[:event_name] = event
end
def to_context
SnowplowTracker::SelfDescribingJson.new(SCHEMA_URL, payload)
end
def to_h
{
schema: SCHEMA_URL,
data: @payload
}
end
private
attr_reader :payload
def check_configuration(data_source, event)
unless ALLOWED_SOURCES.include?(data_source.to_sym)
configuration_error("#{data_source} is not acceptable data source for ServicePingContext")
end
return unless event.nil?
configuration_error("event attribute is required")
end
def configuration_error(message)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(ArgumentError.new(message))
end
end
end
end
|