Class: Kumonos::Envoy::Cluster

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

Constant Summary collapse

ONE_SECONDS_IN_NANOS =
1_000_000_000
ONE_MSEC_IN_NANOS =
1_000_000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connect_timeout_msObject

Returns the value of attribute connect_timeout_ms

Returns:

  • (Object)

    the current value of connect_timeout_ms



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def connect_timeout_ms
  @connect_timeout_ms
end

#hostsObject

Returns the value of attribute hosts

Returns:

  • (Object)

    the current value of hosts



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def hosts
  @hosts
end

#lb_typeObject

Returns the value of attribute lb_type

Returns:

  • (Object)

    the current value of lb_type



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def lb_type
  @lb_type
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def name
  @name
end

#tlsObject

Returns the value of attribute tls

Returns:

  • (Object)

    the current value of tls



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def tls
  @tls
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



190
191
192
# File 'lib/kumonos/envoy.rb', line 190

def type
  @type
end

Class Method Details

.build(h) ⇒ Object



192
193
194
195
# File 'lib/kumonos/envoy.rb', line 192

def build(h)
  new(h.fetch('name'), h.fetch('type'), h.fetch('tls'), h.fetch('connect_timeout_ms'),
      h.fetch('lb_type'), h.fetch('hosts'))
end

Instance Method Details

#to_hObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/kumonos/envoy.rb', line 200

def to_h
  h = super
  h[:type] = type.upcase
  h.delete(:lb_type)
  h[:lb_policy] = lb_type.upcase
  h.delete(:tls)
  h[:tls_context] = {} if tls

  sec, nanos = (connect_timeout_ms * ONE_MSEC_IN_NANOS).divmod(ONE_SECONDS_IN_NANOS)
  h.delete(:connect_timeout_ms)
  h[:connect_timeout] = {
    seconds: sec,
    nanos: nanos
  }

  # Just work-around, it could be configurable.
  h[:dns_lookup_family] = 'V4_ONLY'
  h
end