semian
semian copied to clipboard
Feature: support static config for Semian::NetHTTP and Semian::GRPC
Background
MySQL and Redis supports static config, while NetHTTP and GRPC currently only Proc. e.g. https://github.com/Shopify/semian/blob/1d4b53be7819707f9c6eebc17bb9b50b46619271/lib/semian/mysql2.rb#L137-L140 https://github.com/Shopify/semian/blob/1d4b53be7819707f9c6eebc17bb9b50b46619271/lib/semian/net_http.rb#L67-L69 https://github.com/Shopify/semian/blob/1d4b53be7819707f9c6eebc17bb9b50b46619271/lib/semian/grpc.rb#L48-L50
Problem
If pass a static config to NetHTTP and GRPC, semian is disabled because retrieve_semian_configuration
returns nil
.
Proposal
allow static config if it is not callable
def retrieve_semian_configuration(host, port)
return @semian_configuration unless @semian_configuration.respond_to?(:call)
@semian_configuration.call(host, port)
end
Alternative
Add validation to semian_configuration
setter, assert whether static config or Proc is expected
https://github.com/Shopify/semian/blob/1d4b53be7819707f9c6eebc17bb9b50b46619271/lib/semian/net_http.rb#L61-L64