Browse Source

Allow to specify etcd URLs for OSDs with http://, do not die with a strange error if -etcd option is missing for fio

rel-0.5
Vitaliy Filippov 2 months ago
parent
commit
9ac7e75178
  1. 33
      src/etcd_state_client.cpp
  2. 3
      src/etcd_state_client.h
  3. 7
      src/fio_cluster.cpp
  4. 3
      src/http_client.cpp
  5. 2
      src/http_client.h

33
src/etcd_state_client.cpp

@ -56,6 +56,23 @@ void etcd_state_client_t::etcd_call(std::string api, json11::Json payload, int t
http_request_json(tfd, etcd_address, req, timeout, callback);
}
void etcd_state_client_t::add_etcd_url(std::string addr)
{
if (addr.length() > 0)
{
if (strtolower(addr.substr(0, 7)) == "http://")
addr = addr.substr(7);
else if (strtolower(addr.substr(0, 8)) == "https://")
{
printf("HTTPS is unsupported for etcd. Either use plain HTTP or setup a local proxy for etcd interaction\n");
exit(1);
}
if (addr.find('/') < 0)
addr += "/v3";
this->etcd_addresses.push_back(addr);
}
}
void etcd_state_client_t::parse_config(json11::Json & config)
{
this->etcd_addresses.clear();
@ -65,13 +82,7 @@ void etcd_state_client_t::parse_config(json11::Json & config)
while (1)
{
int pos = ea.find(',');
std::string addr = pos >= 0 ? ea.substr(0, pos) : ea;
if (addr.length() > 0)
{
if (addr.find('/') < 0)
addr += "/v3";
this->etcd_addresses.push_back(addr);
}
add_etcd_url(pos >= 0 ? ea.substr(0, pos) : ea);
if (pos >= 0)
ea = ea.substr(pos+1);
else
@ -82,13 +93,7 @@ void etcd_state_client_t::parse_config(json11::Json & config)
{
for (auto & ea: config["etcd_address"].array_items())
{
std::string addr = ea.string_value();
if (addr != "")
{
if (addr.find('/') < 0)
addr += "/v3";
this->etcd_addresses.push_back(addr);
}
add_etcd_url(ea.string_value());
}
}
this->etcd_prefix = config["etcd_prefix"].string_value();

3
src/etcd_state_client.h

@ -54,6 +54,9 @@ struct pool_config_t
struct etcd_state_client_t
{
protected:
void add_etcd_url(std::string);
public:
std::vector<std::string> etcd_addresses;
std::string etcd_prefix;
int log_level = 0;

7
src/fio_cluster.cpp

@ -117,8 +117,15 @@ static struct fio_option options[] = {
static int sec_setup(struct thread_data *td)
{
sec_options *o = (sec_options*)td->eo;
sec_data *bsd;
if (!o->etcd_host)
{
td_verror(td, EINVAL, "etcd address is missing");
return 1;
}
bsd = new sec_data;
if (!bsd)
{

3
src/http_client.cpp

@ -22,7 +22,6 @@
#define READ_BUFFER_SIZE 9000
static int extract_port(std::string & host);
static std::string strtolower(const std::string & in);
static std::string trim(const std::string & in);
static std::string ws_format_frame(int type, uint64_t size);
static bool ws_parse_frame(std::string & buf, int & type, std::string & res);
@ -673,7 +672,7 @@ static int extract_port(std::string & host)
return port;
}
static std::string strtolower(const std::string & in)
std::string strtolower(const std::string & in)
{
std::string s = in;
for (int i = 0; i < s.length(); i++)

2
src/http_client.h

@ -49,6 +49,8 @@ std::vector<std::string> getifaddr_list(bool include_v6 = false);
uint64_t stoull_full(const std::string & str, int base = 10);
std::string strtolower(const std::string & in);
void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
const http_options_t & options, std::function<void(const http_response_t *response)> callback);

Loading…
Cancel
Save