Class: Dropsonde::Metrics::Dependencies

Inherits:
Object
  • Object
show all
Defined in:
lib/dropsonde/metrics/dependencies.rb

Overview

dependencies plugin

Class Method Summary collapse

Class Method Details

.cleanupObject



87
88
89
# File 'lib/dropsonde/metrics/dependencies.rb', line 87

def self.cleanup
  # run just after generating this metric
end

.descriptionObject



10
11
12
13
14
15
# File 'lib/dropsonde/metrics/dependencies.rb', line 10

def self.description
  <<~DESCRIPTION
    This group of metrics discovers dependencies between modules in all
    environments. It will omit dependencies on private modules.
  DESCRIPTION
end

.exampleObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dropsonde/metrics/dependencies.rb', line 69

def self.example
  # this method is used to generate a table filled with randomized data to
  # make it easier to write data aggregation queries without access to the
  # actual private data that users have submitted.

  versions = ['>= 1.5.2', '>= 4.3.2', '>= 3.0.0 < 4.0.0', '>= 2.2.1 < 5.0.0', '>= 5.0.0 < 7.0.0', '>= 4.11.0']
  [
    dependencies: Dropsonde::Cache.modules
                                  .sample(rand(250))
                                  .map do |item|
                    {
                      name: item,
                      version_requirement: versions.sample,
                    }
                  end,
  ]
end

.initialize_dependenciesObject



5
6
7
8
# File 'lib/dropsonde/metrics/dependencies.rb', line 5

def self.initialize_dependencies
  # require any libraries needed here -- no need to load puppet; it's already initialized
  # All plugins are initialized before any metrics are generated.
end

.run(_puppetdb_session = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dropsonde/metrics/dependencies.rb', line 48

def self.run(_puppetdb_session = nil)
  # return an array of hashes representing the data to be merged into the combined checkin
  environments = Puppet.lookup(:environments).list.map { |e| e.name }
  modules = environments.map { |env|
    Puppet.lookup(:environments).get(env).modules
  }.flatten

  # we want only PUBLIC modules that PRIVATE modules depend on
  dependencies = modules.map { |mod|
    next unless mod.dependencies
    next if Dropsonde::Cache.forge_module? mod # skip unless this is a private module

    # and return a list of all public modules it depends on
    mod.dependencies.select { |dep| Dropsonde::Cache.forge_module? dep }
  }.flatten.compact

  [
    { dependencies: dependencies },
  ]
end

.schemaObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dropsonde/metrics/dependencies.rb', line 17

def self.schema
  # return an array of hashes of a partial schema to be merged into the complete schema
  # See https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file
  [
    {
      "fields": [
        {
          "description": 'The depended on module name',
          "mode": 'NULLABLE',
          "name": 'name',
          "type": 'STRING',
        },
        {
          "description": 'The depended on module version requirement',
          "mode": 'NULLABLE',
          "name": 'version_requirement',
          "type": 'STRING',
        },
      ],
      "description": 'List of modules that private modules in all environments depend on.',
      "mode": 'REPEATED',
      "name": 'dependencies',
      "type": 'RECORD',
    },
  ]
end

.setupObject



44
45
46
# File 'lib/dropsonde/metrics/dependencies.rb', line 44

def self.setup
  # run just before generating this metric
end