debian-mirror-gitlab/app/experiments/application_experiment.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
2022-04-04 11:22:00 +05:30
class ApplicationExperiment < Gitlab::Experiment
2022-05-07 20:08:51 +05:30
control { nil } # provide a default control for anonymous experiments
2021-02-22 17:27:13 +05:30
2021-06-08 01:23:25 +05:30
def control_behavior
# define a default nil control behavior so we can omit it when not needed
end
2021-09-30 23:02:18 +05:30
# This is deprecated logic as of v0.6.0 and should eventually be removed, but
# needs to stay intact for actively running experiments. The new strategy
# utilizes Digest::SHA2, a secret seed, and generates a 64-byte string.
2022-06-21 17:19:12 +05:30
#
# https://gitlab.com/gitlab-org/gitlab/-/issues/334590
#
# @deprecated
2021-09-30 23:02:18 +05:30
def key_for(source, seed = name)
2022-07-23 23:45:48 +05:30
# If FIPS is enabled, we simply call the method available in the gem, which
# uses SHA2.
return super if Gitlab::FIPS.enabled?
2021-09-30 23:02:18 +05:30
2022-07-23 23:45:48 +05:30
# If FIPS isn't enabled, we use the legacy MD5 logic to keep existing
# experiment events working.
source = source.keys + source.values if source.is_a?(Hash)
Digest::MD5.hexdigest(Array(source).map { |v| identify(v) }.unshift(seed).join('|'))
2021-09-30 23:02:18 +05:30
end
2022-01-26 12:08:38 +05:30
def nest_experiment(other)
instance_exec(:nested, { label: other.name }, &Configuration.tracking_behavior)
end
2021-02-22 17:27:13 +05:30
private
2022-04-04 11:22:00 +05:30
def tracking_context(event_args)
2022-01-26 12:08:38 +05:30
{
namespace: context.try(:namespace) || context.try(:group),
project: context.try(:project),
user: user_or_actor
2022-04-04 11:22:00 +05:30
}.merge(event_args)
2022-01-26 12:08:38 +05:30
end
def user_or_actor
actor = context.try(:actor)
actor.respond_to?(:id) ? actor : context.try(:user)
end
2021-02-22 17:27:13 +05:30
end