Class: Kumonos::Envoy::EnvoyConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/kumonos/envoy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adminObject

Returns the value of attribute admin

Returns:

  • (Object)

    the current value of admin



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def admin
  @admin
end

#clusterObject

Returns the value of attribute cluster

Returns:

  • (Object)

    the current value of cluster



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def cluster
  @cluster
end

#discovery_serviceObject

Returns the value of attribute discovery_service

Returns:

  • (Object)

    the current value of discovery_service



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def discovery_service
  @discovery_service
end

#listenerObject

Returns the value of attribute listener

Returns:

  • (Object)

    the current value of listener



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def listener
  @listener
end

#nodeObject

Returns the value of attribute node

Returns:

  • (Object)

    the current value of node



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def node
  @node
end

#runtimeObject

Returns the value of attribute runtime

Returns:

  • (Object)

    the current value of runtime



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def runtime
  @runtime
end

#sdsObject

Returns the value of attribute sds

Returns:

  • (Object)

    the current value of sds



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def sds
  @sds
end

#statsdObject

Returns the value of attribute statsd

Returns:

  • (Object)

    the current value of statsd



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def statsd
  @statsd
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



14
15
16
# File 'lib/kumonos/envoy.rb', line 14

def version
  @version
end

Class Method Details

.build(h, cluster:, node:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kumonos/envoy.rb', line 16

def build(h, cluster:, node:)
  discovery_service = DiscoverService.build(h.fetch('discovery_service'))
  sds = DiscoverService.build(h.fetch('sds'))
  new(
    h.fetch('version'),
    discovery_service,
    h['statsd'] ? h['statsd'].fetch('address') : nil,
    Listener.build(h.fetch('listener'), discovery_service),
    Admin.build(h.fetch('admin')),
    cluster,
    node,
    sds,
    h['runtime']
  )
end

Instance Method Details

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/kumonos/envoy.rb', line 46

def to_h
  h = super
  h.delete(:version)
  h.delete(:discovery_service)
  h.delete(:sds)
  h.delete(:statsd)
  h.delete(:listener)
  h.delete(:cluster)
  h.delete(:node)
  h.delete(:runtime)
  h[:admin] = admin.to_h
  h[:runtime] = runtime.to_h if runtime
  h[:static_resources] = {
    listeners: [listener.to_h],
    clusters: [discovery_service.cluster.to_h, sds.cluster.to_h]
  }
  h[:dynamic_resources] = {
    cds_config: {
      api_config_source: {
        cluster_names: [discovery_service.cluster.name],
        refresh_delay: {
          seconds: discovery_service.refresh_delay_ms / 1000.0
        }
      }
    },
    deprecated_v1: {
      sds_config: {
        api_config_source: {
          cluster_names: [sds.cluster.name],
          refresh_delay: {
            seconds: sds.refresh_delay_ms / 1000.0
          }
        }
      }
    }
  }

  if statsd
    statsd_address, statsd_port = statsd.split(':')
    h[:stats_sinks] = [
      {
        name: 'envoy.dog_statsd',
        config: {
          address: {
            socket_address: {
              protocol: 'UDP',
              address: statsd_address,
              port_value: Integer(statsd_port)
            }
          }
        }
      }
    ]
    h[:stats_config] = {
      use_all_default_tags: true,
      stats_tags: [
        { tag_name: 'service-cluster', fixed_value: cluster },
        { tag_name: 'service-node', fixed_value: node }
      ]
    }
  end

  h
end