Skip to content

Commit

Permalink
Fix URL in ES exporter, fix ipv6 supporting for http client. (#3081)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Oct 7, 2024
1 parent 7b82473 commit 3910b04
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
}

// Create a connection to the ElasticSearch instance
auto session = http_client_->CreateSession(options_.host_ + std::to_string(options_.port_));
auto session = http_client_->CreateSession(options_.host_ + ":" + std::to_string(options_.port_));
auto request = session->CreateRequest();

// Populate the request with headers and methods
Expand Down
36 changes: 35 additions & 1 deletion ext/include/opentelemetry/ext/http/common/url_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UrlParser
cpos = pos1 + 1;
}
}
pos = url_.find_first_of(":", cpos);
pos = FindPortPosition(url_, cpos);
bool is_port = false;
if (pos == std::string::npos)
{
Expand Down Expand Up @@ -130,6 +130,40 @@ class UrlParser
query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length());
}
}

private:
static std::string::size_type FindPortPosition(const std::string &url,
std::string::size_type offset)
{
// @see https://www.rfc-editor.org/rfc/rfc3986#page-18
size_t sub_expression_counter = 0;
for (std::string::size_type i = offset; i < url.size(); ++i)
{
char c = url[i];
if (0 == sub_expression_counter && c == ':')
{
return i;
}

if (c == '[')
{
++sub_expression_counter;
}
else if (c == ']')
{
if (sub_expression_counter > 0)
{
--sub_expression_counter;
}
}
else if (0 == sub_expression_counter && c == '/')
{
break;
}
}

return std::string::npos;
}
};

class UrlDecoder
Expand Down
57 changes: 56 additions & 1 deletion ext/test/http/url_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,62 @@ TEST(UrlParserTests, BasicTests)
{"path", "/path1@bbb/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},

{"http://1.2.3.4/path1/path2?q1=a1&q2=a2",
{{"host", "1.2.3.4"},
{"port", "80"},
{"scheme", "http"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"user:[email protected]:8080/path1/path2?q1=a1&q2=a2",
{{"host", "1.2.3.4"},
{"port", "8080"},
{"scheme", "http"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"https://[email protected]/path1/path2?q1=a1&q2=a2",
{{"host", "1.2.3.4"},
{"port", "443"},
{"scheme", "https"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"http://1.2.3.4/path1@bbb/path2?q1=a1&q2=a2",
{{"host", "1.2.3.4"},
{"port", "80"},
{"scheme", "http"},
{"path", "/path1@bbb/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"http://[fe80::225:93da:bfde:b5f5]/path1/path2?q1=a1&q2=a2",
{{"host", "[fe80::225:93da:bfde:b5f5]"},
{"port", "80"},
{"scheme", "http"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"user:password@[fe80::225:93da:bfde:b5f5]:8080/path1/path2?q1=a1&q2=a2",
{{"host", "[fe80::225:93da:bfde:b5f5]"},
{"port", "8080"},
{"scheme", "http"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"https://user@[fe80::225:93da:bfde:b5f5]/path1/path2?q1=a1&q2=a2",
{{"host", "[fe80::225:93da:bfde:b5f5]"},
{"port", "443"},
{"scheme", "https"},
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"http://[fe80::225:93da:bfde:b5f5]/path1@bbb/path2?q1=a1&q2=a2",
{{"host", "[fe80::225:93da:bfde:b5f5]"},
{"port", "80"},
{"scheme", "http"},
{"path", "/path1@bbb/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
};
for (auto &url_map : urls_map)
{
Expand Down

1 comment on commit 3910b04

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 3910b04 Previous: 7b82473 Ratio
BM_SpinLockThrashing/1/process_time/real_time 1.6807089460656999 ms/iter 0.08150736490885417 ms/iter 20.62
BM_SpinLockThrashing/2/process_time/real_time 0.4759903390507037 ms/iter 0.22357382230310632 ms/iter 2.13

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.