Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support follow_redirects, tls #1896

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

catdogpandas
Copy link
Contributor

No description provided.

@catdogpandas catdogpandas changed the title feat: support follow_redirections, tls feat: support follow_redirects, tls Nov 18, 2024
core/prometheus/Constants.h Show resolved Hide resolved
core/prometheus/schedulers/ScrapeConfig.cpp Show resolved Hide resolved
core/prometheus/schedulers/ScrapeConfig.cpp Show resolved Hide resolved
if (httpsFlag) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
}

if (tls != nullptr) {
if (!tls->mCaFile.empty()) {
curl_easy_setopt(curl, CURLOPT_CAINFO, tls->mCaFile.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

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

tls配置了值,但是不合法。会是什么影响?这里需要有容错能力

Copy link
Contributor Author

Choose a reason for hiding this comment

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

curl 会执行失败报错 failed to send http request:retry immediately request address:0x60d000000c70 try cnt:2 errMsg:Problem with the local SSL certificate,在重试后返回给调用方。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

增加了一个保证不会出现 core dump 的不合法验证 tls 的 ut

core/prometheus/async/PromHttpRequest.cpp Outdated Show resolved Hide resolved
Comment on lines 29 to 35
struct CurlTLS {
std::string mCaFile;
std::string mCertFile;
std::string mKeyFile;
bool mInsecureSkipVerify = true;
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个放到HttpRequest文件

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个放到 HttpRequest 会和 HttpResponse 出现相互引用

@@ -43,6 +43,8 @@ struct HttpRequest {
int32_t mPort;
uint32_t mTimeout = static_cast<uint32_t>(INT32_FLAG(default_http_request_timeout_secs));
uint32_t mMaxTryCnt = static_cast<uint32_t>(INT32_FLAG(default_http_request_max_try_cnt));
bool mFollowRedirects = false;
CurlTLS* mTls = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

这边能保证指针是有效的吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

由 Prom 传入的 mTls 生命周期可以保证有效,在 Job 取消时,会首先通过锁把每个采集通过 PromFuture 关闭,然后再是 Job shared_ptr 析构。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants