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
|
install_artifacts
|
||||||
|
|
||||||
if @cask.tap&.should_report_analytics?
|
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
|
end
|
||||||
|
|
||||||
purge_backed_up_versioned_files
|
purge_backed_up_versioned_files
|
||||||
|
|||||||
@ -8,20 +8,16 @@ module Utils
|
|||||||
|
|
||||||
sig { params(verbose: T::Boolean).returns(String) }
|
sig { params(verbose: T::Boolean).returns(String) }
|
||||||
def custom_prefix_label(verbose: false)
|
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"
|
"non-/usr/local"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(verbose: T::Boolean).returns(String) }
|
sig { params(verbose: T::Boolean).returns(String) }
|
||||||
def arch_label(verbose: false)
|
def arch_label(verbose: false)
|
||||||
if Hardware::CPU.arm?
|
return "Rosetta" if Hardware::CPU.in_rosetta2?
|
||||||
"ARM"
|
|
||||||
elsif Hardware::CPU.in_rosetta2?
|
generic_arch_label(verbose: verbose)
|
||||||
"Rosetta"
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -416,7 +416,7 @@ class FormulaInstaller
|
|||||||
|
|
||||||
if formula.tap&.should_report_analytics?
|
if formula.tap&.should_report_analytics?
|
||||||
action = "#{formula.full_name} #{options}".strip
|
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
|
end
|
||||||
|
|
||||||
self.class.attempted << formula
|
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(:type).and_return(:intel)
|
||||||
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false)
|
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false)
|
||||||
allow(Homebrew).to receive(:default_prefix?).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).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
|
end
|
||||||
|
|
||||||
it "returns OS_VERSION, ARM and prefix when HOMEBREW_PREFIX is a custom prefix on arm" do
|
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)
|
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).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[: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).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
|
end
|
||||||
|
|
||||||
it "returns OS_VERSION, Rosetta and prefix when HOMEBREW_PREFIX is a custom prefix on Rosetta", :needs_macos do
|
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(:type).and_return(:intel)
|
||||||
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(true)
|
allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(true)
|
||||||
allow(Homebrew).to receive(:default_prefix?).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).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
|
end
|
||||||
|
|
||||||
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
|
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
|
||||||
allow(Homebrew).to receive(:default_prefix?).and_return(true)
|
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
|
end
|
||||||
|
|
||||||
it "includes CI when ENV['CI'] is set" do
|
it "includes CI when ENV['CI'] is set" do
|
||||||
ENV["CI"] = "true"
|
ENV["CI"] = "true"
|
||||||
expect(described_class.os_arch_prefix_ci).to have_key(:ci)
|
expect(described_class.os_arch_prefix_ci).to have_key(:ci)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,14 +74,14 @@ describe Utils::Analytics do
|
|||||||
ENV["HOMEBREW_NO_ANALYTICS"] = "true"
|
ENV["HOMEBREW_NO_ANALYTICS"] = "true"
|
||||||
expect(described_class).not_to receive(:report_google)
|
expect(described_class).not_to receive(:report_google)
|
||||||
expect(described_class).not_to receive(:report_influx)
|
expect(described_class).not_to receive(:report_influx)
|
||||||
described_class.report_event("install", action)
|
described_class.report_event(:install, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do
|
it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do
|
||||||
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true"
|
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true"
|
||||||
expect(described_class).not_to receive(:report_google)
|
expect(described_class).not_to receive(:report_google)
|
||||||
expect(described_class).not_to receive(:report_influx)
|
expect(described_class).not_to receive(:report_influx)
|
||||||
described_class.report_event("install", action)
|
described_class.report_event(:install, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do
|
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_google)
|
||||||
expect(described_class).to receive(:report_influx)
|
expect(described_class).to receive(:report_influx)
|
||||||
|
|
||||||
described_class.report_event("install", action)
|
described_class.report_event(:install, action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ module Utils
|
|||||||
def report_google(type, metadata = {})
|
def report_google(type, metadata = {})
|
||||||
os = metadata[:el][:os]
|
os = metadata[:el][:os]
|
||||||
arch = ", #{metadata[:el][:arch]}" if metadata[:el][:arch].present?
|
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
|
ci = ", CI" if metadata[:el][:CI] == true
|
||||||
|
|
||||||
metadata[:el] = "#{os}#{arch}#{prefix}#{ci}"
|
metadata[:el] = "#{os}#{arch}#{prefix}#{ci}"
|
||||||
@ -86,7 +86,7 @@ module Utils
|
|||||||
return unless ENV["HOMEBREW_ANALYTICS_ENABLE_INFLUX"]
|
return unless ENV["HOMEBREW_ANALYTICS_ENABLE_INFLUX"]
|
||||||
|
|
||||||
# Append general information to device information
|
# 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
|
.compact_blank
|
||||||
.map { |k, v| "#{k}=#{v.to_s.sub(" ", "\\ ")}" } # convert to key/value parameters
|
.map { |k, v| "#{k}=#{v.to_s.sub(" ", "\\ ")}" } # convert to key/value parameters
|
||||||
.join(",")
|
.join(",")
|
||||||
@ -117,15 +117,16 @@ module Utils
|
|||||||
end
|
end
|
||||||
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)
|
def report_event(category, action, on_request: false)
|
||||||
return if not_this_run?
|
return if not_this_run?
|
||||||
return if disabled?
|
return if disabled?
|
||||||
|
|
||||||
google_label = os_arch_prefix_ci(verbose: false)
|
google_label = os_arch_prefix_ci(verbose: false)
|
||||||
|
google_category = (category == :formula_install) ? "install" : category
|
||||||
|
|
||||||
report_google(:event,
|
report_google(:event,
|
||||||
ec: category,
|
ec: google_category,
|
||||||
ea: action,
|
ea: action,
|
||||||
el: google_label,
|
el: google_label,
|
||||||
ev: nil)
|
ev: nil)
|
||||||
@ -150,7 +151,7 @@ module Utils
|
|||||||
if (options = exception.options.to_a.map(&:to_s).join(" ").presence)
|
if (options = exception.options.to_a.map(&:to_s).join(" ").presence)
|
||||||
action = "#{action} #{options}".strip
|
action = "#{action} #{options}".strip
|
||||||
end
|
end
|
||||||
report_event("BuildError", action)
|
report_event(:build_error, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def messages_displayed?
|
def messages_displayed?
|
||||||
@ -290,10 +291,21 @@ module Utils
|
|||||||
def arch_label(verbose: false)
|
def arch_label(verbose: false)
|
||||||
if Hardware::CPU.arm?
|
if Hardware::CPU.arm?
|
||||||
"ARM"
|
"ARM"
|
||||||
|
elsif verbose
|
||||||
|
"x86_64"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
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
|
def clear_os_arch_prefix_ci
|
||||||
return unless instance_variable_defined?(:@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)
|
def os_arch_prefix_ci(verbose: false)
|
||||||
@os_arch_prefix_ci ||= begin
|
@os_arch_prefix_ci ||= begin
|
||||||
data = {
|
data = {
|
||||||
os: OS_VERSION,
|
version: homebrew_version,
|
||||||
developer: Homebrew::EnvConfig.developer?,
|
google_prefix: custom_prefix_label(verbose: verbose),
|
||||||
version: HOMEBREW_VERSION,
|
prefix: HOMEBREW_PREFIX.to_s,
|
||||||
system: HOMEBREW_SYSTEM,
|
|
||||||
ci: ENV["CI"].present?,
|
ci: ENV["CI"].present?,
|
||||||
|
developer: Homebrew::EnvConfig.developer?,
|
||||||
arch: arch_label(verbose: verbose),
|
arch: arch_label(verbose: verbose),
|
||||||
prefix: custom_prefix_label(verbose: verbose),
|
os: HOMEBREW_SYSTEM,
|
||||||
|
os_name_and_version: OS_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
unless verbose
|
unless verbose
|
||||||
data.delete(:arch) if data[:arch].blank?
|
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
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user