Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
cd3711f5
Commit
cd3711f5
authored
May 21, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transmit discovery metadata into tag field of ServerNode
parent
751b3696
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
discovery_naming_service.cpp
src/brpc/policy/discovery_naming_service.cpp
+13
-0
brpc_naming_service_unittest.cpp
test/brpc_naming_service_unittest.cpp
+5
-2
No files found.
src/brpc/policy/discovery_naming_service.cpp
View file @
cd3711f5
...
...
@@ -16,6 +16,8 @@
#include <gflags/gflags.h>
#include "butil/third_party/rapidjson/document.h"
#include "butil/third_party/rapidjson/stringbuffer.h"
#include "butil/third_party/rapidjson/writer.h"
#include "butil/string_printf.h"
#include "butil/fast_rand.h"
#include "bthread/bthread.h"
...
...
@@ -163,6 +165,16 @@ int ParseFetchsResult(const butil::IOBuf& buf,
}
for
(
BUTIL_RAPIDJSON_NAMESPACE
::
SizeType
i
=
0
;
i
<
instances
.
Size
();
++
i
)
{
std
::
string
metadata
;
// convert metadata in object to string
auto
itr_metadata
=
instances
[
i
].
FindMember
(
"metadata"
);
if
(
itr_metadata
!=
instances
[
i
].
MemberEnd
())
{
BUTIL_RAPIDJSON_NAMESPACE
::
StringBuffer
buffer
;
BUTIL_RAPIDJSON_NAMESPACE
::
Writer
<
BUTIL_RAPIDJSON_NAMESPACE
::
StringBuffer
>
writer
(
buffer
);
itr_metadata
->
value
.
Accept
(
writer
);
metadata
=
buffer
.
GetString
();
}
auto
itr
=
instances
[
i
].
FindMember
(
"addrs"
);
if
(
itr
==
instances
[
i
].
MemberEnd
()
||
!
itr
->
value
.
IsArray
())
{
LOG
(
ERROR
)
<<
"Fail to find addrs or addrs is not an array"
;
...
...
@@ -186,6 +198,7 @@ int ParseFetchsResult(const butil::IOBuf& buf,
addr
.
remove_prefix
(
pos
+
3
);
}
ServerNode
node
;
node
.
tag
=
metadata
;
// Variable addr contains data from addrs[j].GetString(), it is a
// null-terminated string, so it is safe to pass addr.data() as the
// first parameter to str2endpoint.
...
...
test/brpc_naming_service_unittest.cpp
View file @
cd3711f5
...
...
@@ -448,7 +448,8 @@ static const std::string s_fetchs_result = R"({
"rpc":"",
"version":"123",
"metadata":{
"weight": "10",
"cluster": ""
},
"addrs":[
"http://127.0.0.1:8999",
...
...
@@ -475,7 +476,8 @@ static const std::string s_fetchs_result = R"({
"rpc":"",
"version":"123",
"metadata":{
"weight": "10",
"cluster": ""
},
"addrs":[
"http://127.0.0.1:8999",
...
...
@@ -525,6 +527,7 @@ TEST(NamingServiceTest, discovery_parse_function) {
buf
.
append
(
s_fetchs_result
);
ASSERT_EQ
(
0
,
brpc
::
policy
::
ParseFetchsResult
(
buf
,
"admin.test"
,
&
servers
));
ASSERT_EQ
((
size_t
)
1
,
servers
.
size
());
ASSERT_EQ
(
servers
[
0
].
tag
,
"{
\"
weight
\"
:
\"
10
\"
,
\"
cluster
\"
:
\"\"
}"
);
buf
.
clear
();
buf
.
append
(
s_nodes_result
);
std
::
string
server
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment