fix: add better keys and fuller values to influxDB analytics
This commit is contained in:
parent
42a2a8e5c7
commit
50e9247da4
@ -111,7 +111,7 @@ module Cask
|
||||
install_artifacts
|
||||
|
||||
if @cask.tap&.should_report_analytics?
|
||||
::Utils::Analytics.report_event("cask_install", @cask.token, on_request: true)
|
||||
::Utils::Analytics.report_event(:cask_install, @cask.token, on_request: true)
|
||||
end
|
||||
|
||||
purge_backed_up_versioned_files
|
||||
|
||||
@ -8,20 +8,16 @@ module Utils
|
||||
|
||||
sig { params(verbose: T::Boolean).returns(String) }
|
||||
def custom_prefix_label(verbose: false)
|
||||
return generic_custom_prefix_label if Hardware::CPU.arm?
|
||||
return generic_custom_prefix_label(verbose: verbose) if Hardware::CPU.arm?
|
||||
|
||||
"non-/usr/local"
|
||||
end
|
||||
|
||||
sig { params(verbose: T::Boolean).returns(String) }
|
||||
def arch_label(verbose: false)
|
||||
if Hardware::CPU.arm?
|
||||
"ARM"
|
||||
elsif Hardware::CPU.in_rosetta2?
|
||||
"Rosetta"
|
||||
else
|
||||
""
|
||||
end
|
||||
return "Rosetta" if Hardware::CPU.in_rosetta2?
|
||||
|
||||
generic_arch_label(verbose: verbose)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -416,7 +416,7 @@ class FormulaInstaller
|
||||
|
||||
if formula.tap&.should_report_analytics?
|
||||
action = "#{formula.full_name} #{options}".strip
|
||||
Utils::Analytics.report_event("install", action, on_request: installed_on_request?)
|
||||
Utils::Analytics.report_event(:formula_install, action, on_request: installed_on_request?)
|
||||
end
|
||||
|
||||
self.class.attempted << formula
|
||||
|
||||
@ -17,8 +17,10 @@ describe Utils::Analytics do
|
||||
allow(Hardware::CPU).to receive(:type).and_return(:intel)
|
||||
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false)
|
||||
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:google_prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:google_prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq HOMEBREW_PREFIX.to_s
|
||||
end
|
||||
|
||||
it "returns OS_VERSION, ARM and prefix when HOMEBREW_PREFIX is a custom prefix on arm" do
|
||||
@ -27,27 +29,38 @@ describe Utils::Analytics do
|
||||
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:arch)
|
||||
expect(described_class.os_arch_prefix_ci[:arch]).to eq described_class.arch_label
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:google_prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:google_prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq HOMEBREW_PREFIX.to_s
|
||||
end
|
||||
|
||||
it "returns OS_VERSION, Rosetta and prefix when HOMEBREW_PREFIX is a custom prefix on Rosetta", :needs_macos do
|
||||
allow(Hardware::CPU).to receive(:type).and_return(:intel)
|
||||
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(true)
|
||||
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:google_prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:google_prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq described_class.custom_prefix_label
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq HOMEBREW_PREFIX.to_s
|
||||
end
|
||||
|
||||
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
|
||||
allow(Homebrew).to receive(:default_prefix?).and_return(true)
|
||||
expect(described_class.os_arch_prefix_ci).not_to have_key(:prefix)
|
||||
expect(described_class.os_arch_prefix_ci).not_to have_key(:google_prefix)
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:prefix)
|
||||
expect(described_class.os_arch_prefix_ci[:prefix]).to eq :default
|
||||
end
|
||||
|
||||
it "includes CI when ENV['CI'] is set" do
|
||||
ENV["CI"] = "true"
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:ci)
|
||||
end
|
||||
|
||||
it "includes developer when ENV['CI'] is set" do
|
||||
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true)
|
||||
expect(described_class.os_arch_prefix_ci).to have_key(:developer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -61,14 +74,14 @@ describe Utils::Analytics do
|
||||
ENV["HOMEBREW_NO_ANALYTICS"] = "true"
|
||||
expect(described_class).not_to receive(:report_google)
|
||||
expect(described_class).not_to receive(:report_influx)
|
||||
described_class.report_event("install", action)
|
||||
described_class.report_event(:install, action)
|
||||
end
|
||||
|
||||
it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do
|
||||
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true"
|
||||
expect(described_class).not_to receive(:report_google)
|
||||
expect(described_class).not_to receive(:report_influx)
|
||||
described_class.report_event("install", action)
|
||||
described_class.report_event(:install, action)
|
||||
end
|
||||
|
||||
it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do
|
||||
@ -78,7 +91,7 @@ describe Utils::Analytics do
|
||||
expect(described_class).to receive(:report_google)
|
||||
expect(described_class).to receive(:report_influx)
|
||||
|
||||
described_class.report_event("install", action)
|
||||
described_class.report_event(:install, action)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ module Utils
|
||||
def report_google(type, metadata = {})
|
||||
os = metadata[:el][:os]
|
||||
arch = ", #{metadata[:el][:arch]}" if metadata[:el][:arch].present?
|
||||
prefix = ", #{metadata[:el][:prefix]}" if metadata[:el][:prefix].present?
|
||||
prefix = ", #{metadata[:el][:google_prefix]}" if metadata[:el][:google_prefix].present?
|
||||
ci = ", CI" if metadata[:el][:CI] == true
|
||||
|
||||
metadata[:el] = "#{os}#{arch}#{prefix}#{ci}"
|
||||
@ -86,7 +86,7 @@ module Utils
|
||||
return unless ENV["HOMEBREW_ANALYTICS_ENABLE_INFLUX"]
|
||||
|
||||
# Append general information to device information
|
||||
tags = additional_tags.merge(action: action, on_request: !on_request.nil?)
|
||||
tags = additional_tags.merge(package_and_options: action, on_request: !on_request.nil?)
|
||||
.compact_blank
|
||||
.map { |k, v| "#{k}=#{v.to_s.sub(" ", "\\ ")}" } # convert to key/value parameters
|
||||
.join(",")
|
||||
@ -117,15 +117,16 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(category: T.any(String, Symbol), action: String, on_request: T::Boolean).void }
|
||||
sig { params(category: Symbol, action: String, on_request: T::Boolean).void }
|
||||
def report_event(category, action, on_request: false)
|
||||
return if not_this_run?
|
||||
return if disabled?
|
||||
|
||||
google_label = os_arch_prefix_ci(verbose: false)
|
||||
google_category = (category == :formula_install) ? "install" : category
|
||||
|
||||
report_google(:event,
|
||||
ec: category,
|
||||
ec: google_category,
|
||||
ea: action,
|
||||
el: google_label,
|
||||
ev: nil)
|
||||
@ -150,7 +151,7 @@ module Utils
|
||||
if (options = exception.options.to_a.map(&:to_s).join(" ").presence)
|
||||
action = "#{action} #{options}".strip
|
||||
end
|
||||
report_event("BuildError", action)
|
||||
report_event(:build_error, action)
|
||||
end
|
||||
|
||||
def messages_displayed?
|
||||
@ -290,10 +291,21 @@ module Utils
|
||||
def arch_label(verbose: false)
|
||||
if Hardware::CPU.arm?
|
||||
"ARM"
|
||||
elsif verbose
|
||||
"x86_64"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
alias generic_arch_label arch_label
|
||||
|
||||
sig { returns(String) }
|
||||
def homebrew_version
|
||||
version = HOMEBREW_VERSION.match(/^([\d.]*)-?/)[1]
|
||||
return "#{version}-dev" if HOMEBREW_VERSION.include?("-")
|
||||
|
||||
version
|
||||
end
|
||||
|
||||
def clear_os_arch_prefix_ci
|
||||
return unless instance_variable_defined?(:@os_arch_prefix_ci)
|
||||
@ -305,17 +317,20 @@ module Utils
|
||||
def os_arch_prefix_ci(verbose: false)
|
||||
@os_arch_prefix_ci ||= begin
|
||||
data = {
|
||||
os: OS_VERSION,
|
||||
developer: Homebrew::EnvConfig.developer?,
|
||||
version: HOMEBREW_VERSION,
|
||||
system: HOMEBREW_SYSTEM,
|
||||
version: homebrew_version,
|
||||
google_prefix: custom_prefix_label(verbose: verbose),
|
||||
prefix: HOMEBREW_PREFIX.to_s,
|
||||
ci: ENV["CI"].present?,
|
||||
developer: Homebrew::EnvConfig.developer?,
|
||||
arch: arch_label(verbose: verbose),
|
||||
prefix: custom_prefix_label(verbose: verbose),
|
||||
os: HOMEBREW_SYSTEM,
|
||||
os_name_and_version: OS_VERSION,
|
||||
}
|
||||
|
||||
unless verbose
|
||||
data.delete(:arch) if data[:arch].blank?
|
||||
data.delete(:prefix) if Homebrew.default_prefix?
|
||||
data.delete(:google_prefix) if Homebrew.default_prefix?
|
||||
data[:prefix] = :default if Homebrew.default_prefix?
|
||||
end
|
||||
|
||||
data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user