codemonitor 0.3.0 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf55eb8d37288cec3ce8e828f6705c552d78707084648062b303a75bc7d0a063
4
- data.tar.gz: 40a0b1d17eeb986534b812f2668a79eeee4ecf2fb21ec40fe1a672dce8b61a34
3
+ metadata.gz: 9e6c5534fbc28c7134e0d88898112fd0eff5db4c92bb0ac86833bb4daff955d6
4
+ data.tar.gz: c9d7dc28df1e2d07e6b5377b320df7e947bcb72e13b6fa1dfe3981325d1fc9a0
5
5
  SHA512:
6
- metadata.gz: 7fd6aad0e254c9e0efebff094266fa4528bd640a1671a26c8523d86daf4944c72e8116f55bbb87d74bf5f194ada216624f28a3d0de10d962541f768e8c720344
7
- data.tar.gz: 38ae84cbcb7888349e1309d6f0008dd62f6c537818ba93197abbf40eed406222c6bad00e990c193f4d6dcc569038bb81011fe4570b8051ea09a98587d7c3a99a
6
+ metadata.gz: ea0fe2d521164f1386c4d616a2d8a539265c575af18789184672578711207289b506f67b4ed13fa52768389f8df496561206ea7ca73cdb43793f2f31a66dcd6e
7
+ data.tar.gz: 22fcaa2bf3f0c58f565cf055c214ac993cc59b8ea45ff0523d5895060a7adf6cb475bb3db0ec90dbfd22dc8772241c0ee02f5338afb01b7626125f4811ab80c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codemonitor (0.2.0)
4
+ codemonitor (0.3.0)
5
5
  dogapi (~> 1.45)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,9 +1,120 @@
1
- # CodeMonitor
1
+ # 🖥️ CodeMonitor
2
2
 
3
3
  A engine to collect multiple metrics from your repository and push them to a
4
4
  time series provider.
5
5
 
6
6
 
7
- # Inspiration
7
+ # Engines
8
8
 
9
- https://github.com/scribd/github-action-datadog-reporting
9
+ ## Git
10
+
11
+ Collect multiple metrics from the a Git repository.
12
+
13
+ **Requirements / Setup**:
14
+
15
+ You need a `.git` folder present in the current folder:
16
+
17
+ **Options**:
18
+
19
+ `CODEMONITOR_GIT_FILES_THRESHOLD`: Don't emit metrics about number of files, from those that are above of this threshold. (Default: `0`)
20
+
21
+ ## Eslint
22
+
23
+ Collect multiple metrics from the a project with [Eslint](https://eslint.org/) configured.
24
+
25
+ **Requirements / Setup**:
26
+
27
+ You need a `.eslintrc.js` and a `eslint.output.json` file present in the current folder.
28
+
29
+ You can generate the `eslint.output.json` file with this example command:
30
+
31
+ ```
32
+ eslint -f json -o eslint.output.json
33
+ ```
34
+ **Options**:
35
+
36
+ `CODEMONITOR_ESLINT_THRESHOLD`: Don't emit metrics about eslint rules that are above of this threshold. (Default: `10`)
37
+
38
+
39
+ ## Npm
40
+
41
+ Collect multiple metrics from the a NodeJS.
42
+
43
+ **Requirements / Setup**:
44
+
45
+ You need a `package.json` file present in the current folder.
46
+
47
+ ## Packwerk
48
+
49
+ Collect multiple metrics from the a Ruby project with [Packwerk](https://github.com/Shopify/packwerk) configured.
50
+
51
+ **Requirements / Setup**:
52
+
53
+ You need a `deprecated_references.yml` files present in the current project.
54
+
55
+ ## Rubocop
56
+
57
+ Collect multiple metrics from the a Ruby project with [Rubocop](https://github.com/rubocop/rubocop) configured.
58
+
59
+ **Requirements / Setup**:
60
+
61
+ You need a `.rubocop.yml` and a `rubocop.output.json` file present in the current folder.
62
+
63
+ You can generate the `rubocop.output.json` file with this example command:
64
+
65
+ ```
66
+ bundle exec srb tc --metrics-prefix 'codemetrics' --metrics-file sorbet.output.json
67
+ ```
68
+
69
+ **Options**:
70
+
71
+ `CODEMONITOR_RUBOCOP_THRESHOLD`: Don't emit metrics about rubocop cops that are above of this threshold. (Default: `50`)
72
+
73
+
74
+ ## Semgrep
75
+
76
+ Collect multiple metrics from the a with [Semgrep](https://semgrep.dev/) configured.
77
+
78
+ **Requirements / Setup**:
79
+
80
+ You need a `.semgrep.yml` and a `semgrep.output.json` file present in the current folder.
81
+
82
+ You can generate the `semgrep.output.json` file with this example command:
83
+
84
+ ```
85
+ semgrep --json -o semgrep.output.json
86
+ ```
87
+
88
+ **Options**:
89
+
90
+ `CODEMONITOR_SEMGREP_THRESHOLD`: Don't emit metrics about rubocop cops that are above of this threshold. (Default: `50`)
91
+
92
+ ## Sorbet
93
+
94
+ Collect multiple metrics from the a with [Sorbet](https://sorbet.org/) configured.
95
+
96
+ **Requirements / Setup**:
97
+
98
+ You need a `sorbet.output.json` file present in the current folder.
99
+
100
+ You can generate the `sorbet.output.json` file with this example command:
101
+
102
+ ```
103
+ bundle exec srb tc --metrics-prefix 'codemetrics' --metrics-file sorbet.output.json
104
+ ```
105
+
106
+ # Providers
107
+
108
+ ## Console
109
+
110
+ TODO
111
+
112
+ ## Datadog
113
+
114
+ TODO
115
+
116
+ # Contribute
117
+
118
+ This project started as a side project, so I'm sure that is full
119
+ of mistakes and areas to be improve. If you think you can tweak the code to
120
+ make it better, I'll really appreciate a pull request. ;)
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Engines
4
+ module Custom
5
+ class Extractor
6
+ def call(provider)
7
+ return unless requirements?
8
+
9
+ provider.emit(metrics)
10
+ end
11
+
12
+ private
13
+
14
+ def requirements?
15
+ custom_files.length.positive?
16
+ end
17
+
18
+ def custom_files
19
+ Dir.glob('./.codemonitor/*.rb')
20
+ end
21
+
22
+ def metrics
23
+ custom_files.map do |file|
24
+ values = begin
25
+ eval File.read(file)
26
+ rescue SyntaxError => e
27
+ raise "Unable to execute the custom codemonitor script `#{file}` file"
28
+ end
29
+
30
+ raise "Malformed return value from `#{file}` file. It must be a hash of metrics" unless values.is_a?(Hash)
31
+
32
+ values
33
+ end.reduce({}, :merge)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Engines
4
+ module Debug
5
+ class Extractor
6
+ METRICS = %i[
7
+ debug_random
8
+ ].freeze
9
+
10
+ def call(provider)
11
+ return unless requirements?
12
+
13
+ metrics = METRICS.map do |metric|
14
+ [metric, send(metric) || 0]
15
+ end.to_h
16
+
17
+ provider.emit(metrics)
18
+ end
19
+
20
+ private
21
+
22
+ def requirements?
23
+ true
24
+ end
25
+
26
+ def debug_random
27
+ rand(0..100)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -15,6 +15,10 @@ module Engines
15
15
  git_number_of_lines
16
16
  ].freeze
17
17
 
18
+ def initialize
19
+ @threshold = ENV.fetch('CODEMONITOR_GIT_FILES_THRESHOLD', '0').to_i
20
+ end
21
+
18
22
  def call(provider)
19
23
  return unless requirements?
20
24
 
@@ -30,6 +34,8 @@ module Engines
30
34
 
31
35
  private
32
36
 
37
+ attr_reader :threshold
38
+
33
39
  def requirements?
34
40
  File.exist?('.git')
35
41
  end
@@ -84,8 +90,10 @@ module Engines
84
90
  .map do |file|
85
91
  File.extname(file.strip)
86
92
  end.each_with_object(Hash.new(0)) do |type, total|
87
- total["git_file_extensions_#{type.gsub('.', '')}"] += 1
88
- end
93
+ total[type.gsub('.', '')] += 1
94
+ end.map do |key, value|
95
+ ["git_file_extensions_#{key}", value] if value >= threshold
96
+ end.compact.to_h
89
97
  end
90
98
  end
91
99
  end
data/exe/codemonitor CHANGED
@@ -5,12 +5,14 @@ require_relative '../providers/console'
5
5
  require_relative '../providers/datadog'
6
6
 
7
7
  require_relative '../engines/eslint/extractor'
8
+ require_relative '../engines/debug/extractor'
8
9
  require_relative '../engines/git/extractor'
9
10
  require_relative '../engines/npm/extractor'
10
11
  require_relative '../engines/packwerk/extractor'
11
12
  require_relative '../engines/rubocop/extractor'
12
13
  require_relative '../engines/semgrep/extractor'
13
14
  require_relative '../engines/sorbet/extractor'
15
+ require_relative '../engines/custom/extractor'
14
16
 
15
17
  PROVIDERS = {
16
18
  console: Providers::Console,
@@ -19,12 +21,14 @@ PROVIDERS = {
19
21
 
20
22
  EXTRACTORS = {
21
23
  eslint: Engines::Eslint::Extractor,
24
+ debug: Engines::Debug::Extractor,
22
25
  git: Engines::Git::Extractor,
23
26
  npm: Engines::Npm::Extractor,
24
27
  packwerk: Engines::Packwerk::Extractor,
25
28
  rubocop: Engines::Rubocop::Extractor,
26
29
  semgrep: Engines::Semgrep::Extractor,
27
- sorbet: Engines::Sorbet::Extractor
30
+ sorbet: Engines::Sorbet::Extractor,
31
+ custom: Engines::Custom::Extractor
28
32
  }.freeze
29
33
 
30
34
  config_provider = ENV['CODEMONITOR_PROVIDER'] || 'console'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeMonitor
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.4'
5
5
  end
data/providers/datadog.rb CHANGED
@@ -17,7 +17,7 @@ module Providers
17
17
  def send
18
18
  datadog_client.batch_metrics do
19
19
  pending.each do |metric, value|
20
- metric = metric_prefix + metric
20
+ metric = "#{metric_prefix}#{metric}"
21
21
  puts "#{metric}: #{value}"
22
22
  datadog_client.emit_point(metric, value, type: 'gauge')
23
23
  end
@@ -26,6 +26,6 @@ module Providers
26
26
 
27
27
  private
28
28
 
29
- attr_reader :pending, :datadog_client
29
+ attr_reader :pending, :metric_prefix, :datadog_client
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codemonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferran Basora
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-29 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogapi
@@ -115,6 +115,8 @@ files:
115
115
  - bin/console
116
116
  - bin/setup
117
117
  - codemonitor.gemspec
118
+ - engines/custom/extractor.rb
119
+ - engines/debug/extractor.rb
118
120
  - engines/eslint/extractor.rb
119
121
  - engines/git/extractor.rb
120
122
  - engines/npm/extractor.rb