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
8fe8640e
Unverified
Commit
8fe8640e
authored
May 23, 2019
by
Ge Jun
Committed by
GitHub
May 23, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #776 from zyearn/dicovery_metadata
transmit discovery metadata into tag field of ServerNode
parents
b627d16f
b4c943f8
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 @
8fe8640e
...
...
@@ -16,6 +16,8 @@
#include <gflags/gflags.h>
#include "butil/third_party/rapidjson/document.h"
#include "butil/third_party/rapidjson/memorybuffer.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
::
MemoryBuffer
buffer
;
BUTIL_RAPIDJSON_NAMESPACE
::
Writer
<
BUTIL_RAPIDJSON_NAMESPACE
::
MemoryBuffer
>
writer
(
buffer
);
itr_metadata
->
value
.
Accept
(
writer
);
metadata
.
assign
(
buffer
.
GetBuffer
(),
buffer
.
GetSize
());
}
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 @
8fe8640e
...
...
@@ -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