@@ -4,6 +4,7 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
44 RSpec . describe PackStats do
55 before do
66 ParsePackwerk . bust_cache!
7+ write_file ( 'config/code_ownership.yml' , YAML . dump ( { } ) )
78 end
89
910 describe 'PackStats.report_to_datadog!' do
@@ -33,7 +34,7 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
3334 'modularization.some_metric' ,
3435 [ [ report_time , 11 ] ] ,
3536 type : 'gauge' ,
36- tags : [ 'mykey:myvalue' , 'myotherkey:myothervalue' ]
37+ tags : [ 'mykey:myvalue' , 'myotherkey:myothervalue' , 'max_enforcements:false' ]
3738 )
3839 report_to_datadog
3940 end
@@ -1073,6 +1074,71 @@ module PackStats # rubocop:disable RSpec/DescribedClassModuleWrapping
10731074 expect ( metrics ) . to include_metric GaugeMetric . for ( 'all_packages.rubocops.packs_rootnamespaceispackname.exclusions.count' , 6 , Tags . for ( [ 'app:MyApp' ] ) )
10741075 end
10751076 end
1077+
1078+ context 'when getting metrics after turning all protections to max' do
1079+ let ( :subject ) do
1080+ PackStats . get_metrics (
1081+ app_name : 'MyApp' ,
1082+ source_code_pathnames : Pathname . glob ( '**/**.rb' ) ,
1083+ componentized_source_code_locations : [ Pathname . new ( 'components' ) ] ,
1084+ max_enforcements_tag_value : true
1085+ )
1086+ end
1087+
1088+ include_context 'only one team'
1089+
1090+ before do
1091+ write_file ( 'empty_file.rb' )
1092+ write_file ( 'packs/only_package/app/some_package_file.rb' )
1093+ write_file ( 'packs/only_package/package.yml' , <<~CONTENTS )
1094+ enforce_dependencies: true
1095+ enforce_privacy: true
1096+ CONTENTS
1097+
1098+ write_file ( 'packs/only_package/spec/some_package_file_spec.rb' )
1099+ end
1100+
1101+ it 'emits the right metrics' do
1102+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.component_files.by_team' , count : 0 , tags : Tags . for ( [ 'team:Some team' , 'app:MyApp' , 'max_enforcements:true' ] ) )
1103+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.packaged_files.by_team' , count : 2 , tags : Tags . for ( [ 'team:Some team' , 'app:MyApp' , 'max_enforcements:true' ] ) )
1104+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_files.by_team' , count : 3 , tags : Tags . for ( [ 'team:Some team' , 'app:MyApp' , 'max_enforcements:true' ] ) )
1105+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.component_files.totals' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1106+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.packaged_files.totals' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1107+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_files.totals' , count : 3 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1108+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1109+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.dependencies.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1110+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.dependency_violations.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1111+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.privacy_violations.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1112+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.enforcing_dependencies.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1113+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.enforcing_privacy.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1114+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.with_violations.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1115+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.packwerk_checkers.enforce_dependencies.strict.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1116+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.packwerk_checkers.enforce_dependencies.true.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1117+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.packwerk_checkers.enforce_privacy.strict.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1118+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.packwerk_checkers.enforce_privacy.true.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1119+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.rubocops.packs_typedpublicapis.strict.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1120+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.rubocops.packs_typedpublicapis.true.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1121+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.rubocops.packs_rootnamespaceispackname.strict.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1122+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.package_based_file_ownership.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1123+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.using_public_directory.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1124+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.dependency_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1125+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.privacy_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1126+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.outbound_dependency_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1127+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.inbound_dependency_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1128+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.outbound_privacy_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1129+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.inbound_privacy_violations.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1130+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.outbound_explicit_dependencies.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1131+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.inbound_explicit_dependencies.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1132+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.using_public_directory.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1133+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.all_files.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1134+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.all_packages.public_files.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'max_enforcements:true' ] ) )
1135+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_team.using_public_directory.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1136+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_team.all_files.count' , count : 2 , tags : Tags . for ( [ 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1137+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_team.public_files.count' , count : 0 , tags : Tags . for ( [ 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1138+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.using_public_directory.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1139+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.all_files.count' , count : 2 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) )
1140+ expect ( metrics ) . to include_metric GaugeMetric . new ( name : 'modularization.by_package.public_files.count' , count : 0 , tags : Tags . for ( [ 'package:packs/only_package' , 'app:MyApp' , 'team:Unknown' , 'max_enforcements:true' ] ) ) end
1141+ end
10761142 end
10771143 end
10781144end
0 commit comments