Skip to content

Commit

Permalink
refactor sls client manager
Browse files Browse the repository at this point in the history
本次代码评审主要增加了对企业配置提供者中区域端点的支持,引入了新的类和方法来管理端点信息,并优化了一些现有功能以提高性能和可靠性。
Link: https://code.alibaba-inc.com/sls/ilogtail/codereview/19609308
  • Loading branch information
zhanghaoxiang.zhx committed Dec 31, 2024
1 parent f740f0a commit c75af25
Show file tree
Hide file tree
Showing 16 changed files with 3,350 additions and 326 deletions.
81 changes: 81 additions & 0 deletions core/common/EnterpriseEndpointUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2024 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/EnterpriseEndpointUtil.h"

#include "common/EndpointUtil.h"
#include "common/StringTools.h"
#include "logger/Logger.h"

using namespace std;

namespace logtail {

const string kLogEndpointSuffix = ".log.aliyuncs.com";
const string kAccelerationDataEndpoint = "log-global.aliyuncs.com";

bool IsCustomEndpoint(const string& endpoint) {
if (StartWith(endpoint, "log.") || StartWith(endpoint, "log-intranet.") || StartWith(endpoint, "log-internal.")
|| EndWith(endpoint, ".aliyuncs.com") || EndWith(endpoint, ".aliyun-inc.com")) {
return false;
}
return true;
}

EndpointAddressType GetEndpointAddressType(const string& address) {
// 一国一云 OXS区访问 & VPC访问
if (StartWith(address, "log-intranet.") || StartWith(address, "log-internal.")) {
return EndpointAddressType::INTRANET;
}
// 一国一云 公网访问
if (StartWith(address, "log.")) {
return EndpointAddressType::PUBLIC;
}
if (EndWith(address, "-intranet" + kLogEndpointSuffix) || EndWith(address, "-internal" + kLogEndpointSuffix)) {
return EndpointAddressType::INTRANET;
}
if (!EndWith(address, "-share" + kLogEndpointSuffix) && EndWith(address, kLogEndpointSuffix)) {
return EndpointAddressType::PUBLIC;
}
return EndpointAddressType::INNER;
}

string CheckAddress(const string& definedAddress, const string& defaultAddress) {
// Domain name aliyun.com is going done, do not use it any more.
// Aone: https://aone.alibaba-inc.com/req/24401254.
if (definedAddress.find(".aliyun.com") != string::npos) {
const char* recommendedAddress = "http://cn-hangzhou-corp.sls.aliyuncs.com";
LOG_INFO(sLogger, ("*.aliyun.com is deprecated", definedAddress)("new", recommendedAddress));
return recommendedAddress;
}

return StandardizeHost(definedAddress, defaultAddress);
}

string CheckDataServerEndpoint(const string& endpoint) {
constexpr size_t logtailPrefixLen = sizeof("logtail.") - 1;
constexpr size_t configPrefixLen = sizeof("config.") - 1;

size_t index = endpoint.find("logtail.");
if (index == 0) {
return endpoint.substr(logtailPrefixLen);
}
index = endpoint.find("config.");
if (index == 0) {
return endpoint.substr(configPrefixLen);
}
return endpoint;
}

} // namespace logtail
33 changes: 33 additions & 0 deletions core/common/EnterpriseEndpointUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 iLogtail Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <string>

namespace logtail {

enum class EndpointAddressType { INNER, INTRANET, PUBLIC };

extern const std::string kLogEndpointSuffix;
extern const std::string kAccelerationDataEndpoint;

bool IsCustomEndpoint(const std::string& endpoint);
EndpointAddressType GetEndpointAddressType(const std::string& address);
std::string CheckAddress(const std::string& definedAddress, const std::string& defaultAddress);
std::string CheckDataServerEndpoint(const std::string& definedAddress);

} // namespace logtail
Loading

0 comments on commit c75af25

Please sign in to comment.