Welcome to mirror list, hosted at ThFree Co, Russian Federation.

payload_keys_processor.rb « service_ping « usage « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89931d8c012760698133add73172fc429647d355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

# Process the UsageData payload to get the keys that have a metric defintion
# Get the missing keys from the payload
module Gitlab
  module Usage
    module ServicePing
      class PayloadKeysProcessor
        attr_reader :old_payload

        def initialize(old_payload)
          @old_payload = old_payload
        end

        def key_paths
          @key_paths ||= payload_keys.to_a.flatten.compact
        end

        def missing_instrumented_metrics_key_paths
          @missing_key_paths ||= metrics_with_instrumentation.map(&:key) - key_paths
        end

        private

        def payload_keys(payload = old_payload, parents = [])
          return unless payload.is_a?(Hash)

          payload.map do |key, value|
            if has_metric_definition?(key, parents)
              parents.dup.append(key).join('.')
            elsif value.is_a?(Hash)
              payload_keys(value, parents.dup << key)
            end
          end
        end

        def has_metric_definition?(key, parent_keys)
          key_path = parent_keys.dup.append(key).join('.')
          metric_definitions.key?(key_path)
        end

        def metric_definitions
          ::Gitlab::Usage::MetricDefinition.not_removed
        end

        def metrics_with_instrumentation
          ::Gitlab::Usage::MetricDefinition.with_instrumentation_class
        end
      end
    end
  end
end

Gitlab::Usage::ServicePing::PayloadKeysProcessor.prepend_mod_with('Gitlab::Usage::ServicePing::PayloadKeysProcessor')