Skip to content

Commit

Permalink
Drop the suffix after the first left parenthesis from UserAgent (stab…
Browse files Browse the repository at this point in the history
…le-24-3) (ydb-platform#11259)
  • Loading branch information
qyryq authored and uzhastik committed Nov 8, 2024
1 parent 9e75b3a commit 7317a6a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ void TReadSessionActor::SetupBytesReadByUserAgentCounter() {
->GetSubgroup("host", "")
->GetSubgroup("protocol", "pqv0")
->GetSubgroup("consumer", ClientPath)
->GetSubgroup("user_agent", V1::CleanupCounterValueString(UserAgent))
->GetSubgroup("user_agent", V1::DropUserAgentSuffix(V1::CleanupCounterValueString(UserAgent)))
->GetExpiringNamedCounter("sensor", "BytesReadByUserAgent", true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void TWriteSessionActor::SetupBytesWrittenByUserAgentCounter() {
->GetSubgroup("host", "")
->GetSubgroup("protocol", "pqv0")
->GetSubgroup("topic", FullConverter->GetFederationPath())
->GetSubgroup("user_agent", V1::CleanupCounterValueString(UserAgent))
->GetSubgroup("user_agent", V1::DropUserAgentSuffix(V1::CleanupCounterValueString(UserAgent)))
->GetExpiringNamedCounter("sensor", "BytesWrittenByUserAgent", true);
}

Expand Down
13 changes: 12 additions & 1 deletion ydb/services/persqueue_v1/actors/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool HasMessages(const Topic::StreamReadMessage::ReadResponse& data) {


TString CleanupCounterValueString(const TString& value) {
// Internal Monitoring system requires metrics values to no longer than 200 characters
// Internal Monitoring system requires metrics values to be no longer than 200 characters
// and prohibits some ASCII characters.

TString clean;
Expand All @@ -55,4 +55,15 @@ TString CleanupCounterValueString(const TString& value) {
return clean;
}


TString DropUserAgentSuffix(const TString& userAgent) {
auto ua = TStringBuf(userAgent);
TStringBuf beforeParen, afterParen;
ua.Split('(', beforeParen, afterParen);
while (beforeParen.ends_with(' ')) {
beforeParen.Chop(1);
}
return TString(beforeParen);
}

}
1 change: 1 addition & 0 deletions ydb/services/persqueue_v1/actors/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ bool HasMessages(const PersQueue::V1::MigrationStreamingReadServerMessage::DataB
bool HasMessages(const Topic::StreamReadMessage::ReadResponse& data);

TString CleanupCounterValueString(const TString& value);
TString DropUserAgentSuffix(const TString& userAgent);

}
2 changes: 1 addition & 1 deletion ydb/services/persqueue_v1/actors/read_session_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void TReadSessionActor<UseMigrationProtocol>::SetupBytesReadByUserAgentCounter()
->GetSubgroup("protocol", protocol)
->GetSubgroup("consumer", ClientPath)
->GetSubgroup("sdk_build_info", CleanupCounterValueString(SdkBuildInfo))
->GetSubgroup("user_agent", CleanupCounterValueString(UserAgent))
->GetSubgroup("user_agent", DropUserAgentSuffix(CleanupCounterValueString(UserAgent)))
->GetExpiringNamedCounter("sensor", "BytesReadByUserAgent", true);
}

Expand Down
2 changes: 1 addition & 1 deletion ydb/services/persqueue_v1/actors/write_session_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void TWriteSessionActor<UseMigrationProtocol>::SetupBytesWrittenByUserAgentCount
->GetSubgroup("protocol", protocol)
->GetSubgroup("topic", topicPath)
->GetSubgroup("sdk_build_info", CleanupCounterValueString(SdkBuildInfo))
->GetSubgroup("user_agent", CleanupCounterValueString(UserAgent))
->GetSubgroup("user_agent", DropUserAgentSuffix(CleanupCounterValueString(UserAgent)))
->GetExpiringNamedCounter("sensor", "BytesWrittenByUserAgent", true);
}

Expand Down
8 changes: 4 additions & 4 deletions ydb/services/persqueue_v1/persqueue_new_schemecache_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ namespace NKikimr::NPersQueueTests {
} else {
UNIT_FAIL("Neither topic nor consumer were provided");
}
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::CleanupCounterValueString(userAgent));
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::DropUserAgentSuffix(NGRpcProxy::V1::CleanupCounterValueString(userAgent)));
}
};

Expand All @@ -439,7 +439,7 @@ namespace NKikimr::NPersQueueTests {
UNIT_ASSERT(result.IsSuccess());
}

static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| ";
static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| (some build info (codename); os 1.0)";

{
auto newDriverCfg = driverCfg;
Expand Down Expand Up @@ -624,7 +624,7 @@ namespace NKikimr::NPersQueueTests {
} else {
UNIT_FAIL("Neither topic nor consumer were provided");
}
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::CleanupCounterValueString(userAgent));
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::DropUserAgentSuffix(NGRpcProxy::V1::CleanupCounterValueString(userAgent)));
}
};

Expand All @@ -638,7 +638,7 @@ namespace NKikimr::NPersQueueTests {
UNIT_ASSERT(result.IsSuccess());
}

static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| ";
static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| (some build info (codename); os 1.0)";

{
auto newDriverCfg = driverCfg;
Expand Down
8 changes: 4 additions & 4 deletions ydb/services/persqueue_v1/persqueue_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3676,7 +3676,8 @@ TPersQueueV1TestServer server{{.CheckACL=true, .NodeCount=1}};
} else {
UNIT_FAIL("Neither topic nor consumer were provided");
}
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::CleanupCounterValueString(userAgent));
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), "test-client/v0.1");
UNIT_ASSERT_VALUES_EQUAL(labels["user_agent"].GetString(), NGRpcProxy::V1::DropUserAgentSuffix(NGRpcProxy::V1::CleanupCounterValueString(userAgent)));
}
};

Expand Down Expand Up @@ -3711,7 +3712,7 @@ TPersQueueV1TestServer server{{.CheckACL=true, .NodeCount=1}};

auto driver = server.AnnoyingClient->GetDriver();

static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| ";
static constexpr auto userAgent = "test-client/v0.1 ' ?*'\"`| (some build info (codename); os 1.0)";

auto writer = CreateWriter(
*driver,
Expand Down Expand Up @@ -3865,8 +3866,7 @@ TPersQueueV1TestServer server{{.CheckACL=true, .NodeCount=1}};
"", "Dc1", consumerName, consumerPath
);

checkUserAgentCounters(server.CleverServer->GetRuntime()->GetMonPort(),
"BytesReadByUserAgent", "pqv1", userAgent, "", consumerPath);
checkUserAgentCounters(monPort, "BytesReadByUserAgent", "pqv1", userAgent, "", consumerPath);
}
};

Expand Down

0 comments on commit 7317a6a

Please sign in to comment.