Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
quzard committed Jan 9, 2025
1 parent f7ff434 commit 725918e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/common/MachineInfoUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,7 @@ bool ParseECSMeta(const std::string& meta, ECSMeta& metaObj) {
if (doc.isMember(sRegionIdKey) && doc[sRegionIdKey].isString()) {
metaObj.SetRegionID(doc[sRegionIdKey].asString());
}
if (!metaObj.GetInstanceID().empty() && !metaObj.GetUserID().empty() && !metaObj.GetRegionID().empty()) {
return true;
}
return false;
return metaObj.IsValid();
}

HostIdentifier::HostIdentifier() {
Expand Down Expand Up @@ -591,8 +588,8 @@ bool HostIdentifier::UpdateInstanceIdentity(const ECSMeta& meta) {
// 如果 instanceID 发生变化,则更新ecs元数据
if (mMetadata.GetInstanceID() != meta.GetInstanceID()) {
LOG_INFO(sLogger,
("ecs instanceID changed, old instanceID",
mMetadata.GetInstanceID().to_string())("new instanceID", meta.GetInstanceID().to_string()));
("ecs instanceID changed, old instanceID", mMetadata.GetInstanceID())("new instanceID",
meta.GetInstanceID()));
mMetadata = meta;
updateHostId();
mInstanceIdentity.getWriteBuffer().SetReady(true);
Expand Down Expand Up @@ -623,7 +620,7 @@ void HostIdentifier::DumpInstanceIdentity() {

void HostIdentifier::updateHostId() {
Hostid newId;
if (mMetadata.IsValid() && !mMetadata.GetInstanceID().empty()) {
if (mMetadata.IsValid()) {
newId = {mMetadata.GetInstanceID().to_string(), Type::ECS};
} else {
getSerialNumberFromEcsAssist();
Expand Down
3 changes: 3 additions & 0 deletions core/unittest/common/InstanceIdentityUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ void InstanceIdentityUnittest::TestECSMeta() {
meta.SetRegionID("cn-hangzhou");
APSARA_TEST_TRUE(meta.IsValid());
APSARA_TEST_EQUAL(meta.GetInstanceID().to_string(), "i-1234567890");
APSARA_TEST_EQUAL(meta.instanceIDLen, 12);
APSARA_TEST_EQUAL(meta.GetUserID().to_string(), "1234567890");
APSARA_TEST_EQUAL(meta.userIDLen, 10);
APSARA_TEST_EQUAL(meta.GetRegionID().to_string(), "cn-hangzhou");
APSARA_TEST_EQUAL(meta.regionIDLen, 11);
}
{
ECSMeta meta;
Expand Down

0 comments on commit 725918e

Please sign in to comment.