Skip to content

Commit

Permalink
Add layer tag to package specific metrics (#41)
Browse files Browse the repository at this point in the history
* bump rbis for parse_packwerk

* add layer tags

* fix tests

* bump version
  • Loading branch information
Alex Evanczuk committed May 12, 2023
1 parent f41e345 commit 55aef74
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pack_stats (0.1.0)
pack_stats (0.1.1)
code_ownership
code_teams
dogapi
Expand Down
10 changes: 9 additions & 1 deletion lib/pack_stats/private/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ def self.tags_for_team(team_name)

sig { params(package: ParsePackwerk::Package, app_name: String).returns(T::Array[Tag]) }
def self.tags_for_package(package, app_name)
[

tags = [
Tag.new(key: 'package', value: humanized_package_name(package.name)),
Tag.new(key: 'app', value: app_name),
*Metrics.tags_for_team(Private.package_owner(package)),
]

layer = package.config['layer']
if layer
tags << Tag.new(key: 'layer', value: layer)
end

tags
end

sig { params(team_name: T.nilable(String)).returns(T::Array[Tag]) }
Expand Down
2 changes: 1 addition & 1 deletion pack_stats.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'pack_stats'
spec.version = '0.1.0'
spec.version = '0.1.1'
spec.authors = ['Gusto Engineers']
spec.email = ['dev@gusto.com']

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions spec/pack_stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,14 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
enforce_privacy: false
enforce_architecture: true
enforce_visibility: true
layer: utilities
metadata:
owner: Bar Team
CONTENTS

write_file('packs/other_pack/package.yml', <<~CONTENTS)
enforce_dependencies: false
layer: product
metadata:
owner: Foo Team
CONTENTS
Expand Down Expand Up @@ -1077,15 +1079,15 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'violation_type:architecture']))
expect(metrics).to include_metric GaugeMetric.for('by_team.violations.count', 1, Tags.for(['app:MyApp', 'team:Bar Team', 'violation_type:visibility']))

expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'team:Bar Team', 'violation_type:architecture']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'team:Bar Team', 'violation_type:visibility']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'team:Foo Team', 'violation_type:architecture']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'team:Foo Team', 'violation_type:visibility']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'team:Bar Team', 'violation_type:architecture', 'layer:utilities']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 1, Tags.for(['app:MyApp', 'package:packs/my_pack', 'team:Bar Team', 'violation_type:visibility', 'layer:utilities']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'team:Foo Team', 'violation_type:architecture', 'layer:product']))
expect(metrics).to include_metric GaugeMetric.for('by_package.violations.count', 0, Tags.for(['app:MyApp', 'package:packs/other_pack', 'team:Foo Team', 'violation_type:visibility', 'layer:product']))

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']))
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']))
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']))
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']))
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']))
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']))
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']))
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']))

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']))
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']))
Expand Down

0 comments on commit 55aef74

Please sign in to comment.