Skip to content

Commit ae236a6

Browse files
author
Alex Evanczuk
authored
Reduce emitted metric count by not emitting metrics with count 0 (#42)
* Do not emit per package metrics between packs with zero violations * only submit cross team metrics with violation count > 0 * bump version
1 parent 55aef74 commit ae236a6

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pack_stats (0.1.1)
4+
pack_stats (0.1.2)
55
code_ownership
66
code_teams
77
dogapi

lib/pack_stats/private/metrics/packages.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ def self.get_package_metrics(packages, app_name)
5959
checker.violation_type_tag
6060
]
6161

62-
all_metrics << GaugeMetric.for("by_package.violations.by_other_package.count", Metrics.file_count(violations), tags)
62+
count = Metrics.file_count(violations)
63+
if count > 0
64+
all_metrics << GaugeMetric.for("by_package.violations.by_other_package.count", Metrics.file_count(violations), tags)
65+
end
6366
end
6467
when PackwerkCheckerUsage::Direction::Inbound
6568
all_violations_of_type = inbound_violations.select { |v| v.type == checker.violation_type }
@@ -72,7 +75,10 @@ def self.get_package_metrics(packages, app_name)
7275
checker.violation_type_tag
7376
]
7477

75-
all_metrics << GaugeMetric.for("by_package.violations.by_other_package.count", Metrics.file_count(violations), tags)
78+
count = Metrics.file_count(violations)
79+
if count > 0
80+
all_metrics << GaugeMetric.for("by_package.violations.by_other_package.count", count, tags)
81+
end
7682
end
7783
else
7884
T.absurd(direction)

lib/pack_stats/private/metrics/packages_by_team.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def self.get_package_metrics_by_team(all_packages, app_name)
4444
all_packages.group_by { |package| Private.package_owner(package) }.each do |other_team_name, other_teams_packages|
4545
violations = outbound_violations.select{|v| other_teams_packages.map(&:name).include?(v.to_package_name) && v.type == checker.violation_type}
4646
tags = team_tags + Metrics.tags_for_other_team(other_team_name) + [checker.violation_type_tag]
47-
all_metrics << GaugeMetric.for("by_team.violations.by_other_team.count", Metrics.file_count(violations), tags)
47+
count = Metrics.file_count(violations)
48+
if count > 0
49+
all_metrics << GaugeMetric.for("by_team.violations.by_other_team.count", count, tags)
50+
end
4851
end
4952
when PackwerkCheckerUsage::Direction::Inbound
5053
all_violations_of_type = inbound_violations.select { |v| v.type == checker.violation_type }
@@ -56,7 +59,10 @@ def self.get_package_metrics_by_team(all_packages, app_name)
5659
all_packages.group_by { |package| Private.package_owner(package) }.each do |other_team_name, other_teams_packages|
5760
violations = other_teams_packages.flat_map(&:violations).select{|v| packages_for_team.map(&:name).include?(v.to_package_name) && v.type == checker.violation_type}
5861
tags = team_tags + Metrics.tags_for_other_team(other_team_name) + [checker.violation_type_tag]
59-
all_metrics << GaugeMetric.for("by_team.violations.by_other_team.count", Metrics.file_count(violations), tags)
62+
count = Metrics.file_count(violations)
63+
if count > 0
64+
all_metrics << GaugeMetric.for("by_team.violations.by_other_team.count", count, tags)
65+
end
6066
end
6167
else
6268
T.absurd(direction)

pack_stats.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'pack_stats'
3-
spec.version = '0.1.1'
3+
spec.version = '0.1.2'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['dev@gusto.com']
66

spec/pack_stats_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,17 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
453453
expect(metrics).to include_metric GaugeMetric.for('by_team.using_public_directory.count', 0, Tags.for(['team:Unknown', 'app:MyApp']))
454454

455455
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 2, Tags.for(['team:Chefs', 'other_team:Artists', 'violation_type:dependency', 'app:MyApp']))
456-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Chefs', 'other_team:Artists', 'violation_type:privacy', 'app:MyApp']))
456+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Chefs', 'other_team:Artists', 'violation_type:privacy', 'app:MyApp']))
457457
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 1, Tags.for(['team:Chefs', 'other_team:Unknown', 'violation_type:dependency', 'app:MyApp']))
458-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Chefs', 'other_team:Unknown', 'violation_type:privacy', 'app:MyApp']))
458+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Chefs', 'other_team:Unknown', 'violation_type:privacy', 'app:MyApp']))
459459
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 2, Tags.for(['team:Unknown', 'other_team:Chefs', 'violation_type:dependency', 'app:MyApp']))
460-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Chefs', 'violation_type:privacy', 'app:MyApp']))
461-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Artists', 'violation_type:dependency', 'app:MyApp']))
462-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Artists', 'violation_type:privacy', 'app:MyApp']))
463-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Chefs', 'violation_type:dependency', 'app:MyApp']))
464-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Chefs', 'violation_type:privacy', 'app:MyApp']))
465-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Unknown', 'violation_type:dependency', 'app:MyApp']))
466-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Unknown', 'violation_type:privacy', 'app:MyApp']))
460+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Chefs', 'violation_type:privacy', 'app:MyApp']))
461+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Artists', 'violation_type:dependency', 'app:MyApp']))
462+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Unknown', 'other_team:Artists', 'violation_type:privacy', 'app:MyApp']))
463+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Chefs', 'violation_type:dependency', 'app:MyApp']))
464+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Chefs', 'violation_type:privacy', 'app:MyApp']))
465+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Unknown', 'violation_type:dependency', 'app:MyApp']))
466+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['team:Artists', 'other_team:Unknown', 'violation_type:privacy', 'app:MyApp']))
467467
end
468468
end
469469

@@ -685,12 +685,12 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
685685
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 2, Tags.for(['package:root', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:dependency']))
686686
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 3, Tags.for(['package:packs/package_2', 'app:MyApp', 'team:Unknown', 'other_package:packs/package_1', 'other_team:Unknown', 'violation_type:dependency']))
687687
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['package:packs/package_2', 'app:MyApp', 'team:Unknown', 'other_package:root', 'other_team:Unknown', 'violation_type:dependency']))
688-
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:packs/package_1', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:dependency']))
688+
expect(metrics).to_not include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:packs/package_1', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:dependency']))
689689

690-
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:root', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:privacy']))
690+
expect(metrics).to_not include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:root', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:privacy']))
691691
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['package:packs/package_2', 'app:MyApp', 'team:Unknown', 'other_package:packs/package_1', 'other_team:Unknown', 'violation_type:privacy']))
692692
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['package:packs/package_2', 'app:MyApp', 'team:Unknown', 'other_package:root', 'other_team:Unknown', 'violation_type:privacy']))
693-
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:packs/package_1', 'team:Unknown', 'app:MyApp', 'other_package:root', 'other_team:Unknown', 'violation_type:privacy']))
693+
expect(metrics).to_not include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['package:packs/package_1', 'team:Unknown', 'app:MyApp', 'other_package:root', 'other_team:Unknown', 'violation_type:privacy']))
694694
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['package:packs/package_1', 'team:Unknown', 'app:MyApp', 'other_package:packs/package_2', 'other_team:Unknown', 'violation_type:privacy']))
695695
end
696696
end
@@ -1086,11 +1086,11 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
10861086

10871087
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'other_package:packs/other_pack', 'team:Bar Team', 'other_team:Foo Team', 'violation_type:architecture', 'layer:utilities']))
10881088
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'other_package:packs/other_pack', 'team:Bar Team', 'other_team:Foo Team', 'violation_type:visibility', 'layer:utilities']))
1089-
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'other_package:packs/my_pack', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:architecture', 'layer:product']))
1090-
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'other_package:packs/my_pack', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:visibility', 'layer:product']))
1089+
expect(metrics).to_not include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'other_package:packs/my_pack', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:architecture', 'layer:product']))
1090+
expect(metrics).to_not include_metric GaugeMetric.for('by_package.violations.by_other_package.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'other_package:packs/my_pack', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:visibility', 'layer:product']))
10911091

1092-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['app:MyApp', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:architecture']))
1093-
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['app:MyApp', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:visibility']))
1092+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['app:MyApp', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:architecture']))
1093+
expect(metrics).to_not include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 0, Tags.for(['app:MyApp', 'team:Foo Team', 'other_team:Bar Team', 'violation_type:visibility']))
10941094
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'other_team:Foo Team', 'violation_type:architecture']))
10951095
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.by_other_team.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'other_team:Foo Team', 'violation_type:visibility']))
10961096
end

0 commit comments

Comments
 (0)