Skip to content

Commit d4868fc

Browse files
authored
ignore_suffix as skywalking CDS target (#66)
1 parent c50b82d commit d4868fc

File tree

8 files changed

+71
-48
lines changed

8 files changed

+71
-48
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,27 @@ tracer->report(std::move(tracing_context));
136136
#### Skywalking CDS
137137
138138
C++ agent implements Skywalking CDS feature it allows to change bootstrap config dynamically from the response of sync request, invoked from this periodically.
139+
Dynamically configurable values are described in description of properties on `docs/README.md'.
139140
140141
```cpp
141142
TracerConfig config;
142143
// If you set this value as zero, CDS request won't occur.
143144
config.set_cds_request_interval(5); // CDS request interval should be 5sec
144145
```
145146

146-
Currently, Configurable values dynamically are like below.
147+
If you are using Consul KVS as backend, we could put configuration value through HTTP request.
147148

148-
| Config Key | Value Description |
149-
|:----:|:----:|
150-
|instance_name| Instance name of this agent |
149+
```yaml
150+
configurations:
151+
service_name:
152+
ignore_suffix: '/ignore, /hoge'
153+
```
154+
155+
After setup configurations, try to put values with
151156
157+
```
158+
curl --request PUT --data-binary "@./config.yaml" http://localhost:8500/v1/kv/configuration-discovery.default.agentConfigurations
159+
```
152160

153161
## Security
154162

cpp2sky/config.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,35 @@ enum Protocol {
99

1010
message TracerConfig {
1111
// Tracer protocol.
12+
// | Static config only
1213
Protocol protocol = 1;
1314

1415
// Service name
16+
// | Static config only
1517
string service_name = 2;
1618

1719
// Instance name
20+
// | Static config only
1821
string instance_name = 3;
1922

2023
// OAP address.
24+
// | Static config only
2125
string address = 4;
2226

2327
// OAP token.
28+
// | Static config only
2429
string token = 5;
2530

2631
// The size of buffer it stores pending messages.
32+
// | Static config only
2733
uint32 delayed_buffer_size = 6;
2834

2935
// If the operation name of the first span is included in this set,
3036
// this segment should be ignored.
37+
// | This value can be changed with SkyWalking CDS.
3138
repeated string ignore_operation_name_suffix = 8;
3239

3340
// CDS sync request interval. If this value is zero, CDS feature will be disabled.
41+
// | Static config only
3442
uint32 cds_request_interval = 7;
3543
}

docs/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
| Field | Description | Type | C++ |
77
| ----- | ----------- | ---- | --- |
8-
| protocol | Tracer protocol. | Protocol | |
9-
| service_name | Service name | string | string |
10-
| instance_name | Instance name | string | string |
11-
| address | OAP address. | string | string |
12-
| token | OAP token. | string | string |
13-
| delayed_buffer_size | The size of buffer it stores pending messages. | uint32 | uint32 |
14-
| ignore_operation_name_suffix | If the operation name of the first span is included in this set, this segment should be ignored. | (slice of) string | (slice of) string |
15-
| cds_request_interval | CDS sync request interval. If this value is zero, CDS feature will be disabled. | uint32 | uint32 |
8+
| protocol | Tracer protocol. | Static config only | Protocol | |
9+
| service_name | Service name | Static config only | string | string |
10+
| instance_name | Instance name | Static config only | string | string |
11+
| address | OAP address. | Static config only | string | string |
12+
| token | OAP token. | Static config only | string | string |
13+
| delayed_buffer_size | The size of buffer it stores pending messages. | Static config only | uint32 | uint32 |
14+
| ignore_operation_name_suffix | If the operation name of the first span is included in this set, this segment should be ignored. | This value can be changed with SkyWalking CDS. | (slice of) string | (slice of) string |
15+
| cds_request_interval | CDS sync request interval. If this value is zero, CDS feature will be disabled. | Static config only | uint32 | uint32 |
1616

1717

1818

source/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cc_library(
2525
"@skywalking_data_collect_protocol//language-agent:configuration_discovery_service_cc_grpc",
2626
"@com_github_grpc_grpc//:grpc++",
2727
"@com_github_gabime_spdlog//:spdlog",
28+
"@com_github_abseil-cpp//absl/strings:strings",
2829
"//cpp2sky/internal:async_client_interface",
2930
"//cpp2sky/internal:stream_builder_interface",
3031
"//cpp2sky/internal:matcher_interface",
@@ -50,6 +51,7 @@ cc_library(
5051
"@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_grpc",
5152
"@com_github_grpc_grpc//:grpc++",
5253
"@com_github_gabime_spdlog//:spdlog",
54+
"@com_github_abseil-cpp//absl/strings:strings",
5355
"//cpp2sky/internal:async_client_interface",
5456
"//cpp2sky/internal:stream_builder_interface",
5557
"//cpp2sky/internal:matcher_interface",
@@ -75,6 +77,7 @@ cc_library(
7577
deps = [
7678
"@skywalking_data_collect_protocol//language-agent:configuration_discovery_service_cc_proto",
7779
"@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_proto",
80+
"@com_github_abseil-cpp//absl/strings:strings",
7881
"//cpp2sky:config_cc_proto",
7982
"//cpp2sky:cpp2sky_interface",
8083
"//source/utils:util_lib",

source/dynamic_config.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414

1515
#include "dynamic_config.h"
1616

17+
#include <string>
18+
19+
#include "absl/strings/str_split.h"
20+
#include "absl/strings/strip.h"
1721
#include "spdlog/spdlog.h"
1822

1923
namespace cpp2sky {
2024

2125
namespace { // well known fields on response commands.
2226
static constexpr std::string_view UUID_FIELD = "UUID";
2327
static constexpr std::string_view SERIAL_NUMBER_FIELD = "SerialNumber";
24-
static constexpr std::string_view INSTANCE_FIELD = "instance_name";
28+
static constexpr std::string_view IGNORE_SUFFIX = "ignore_suffix";
2529
} // namespace
2630

2731
using namespace spdlog;
2832

2933
DynamicConfig::DynamicConfig(TracerConfig& config) : config_(config) {
30-
target_fields_.emplace(INSTANCE_FIELD.data());
34+
target_fields_.emplace(IGNORE_SUFFIX.data());
3135

3236
ignore_fields_.emplace(UUID_FIELD.data());
3337
ignore_fields_.emplace(SERIAL_NUMBER_FIELD.data());
@@ -59,13 +63,24 @@ void DynamicConfig::onConfigChange(skywalking::v3::Commands commands) {
5963
continue;
6064
}
6165

62-
const auto* reflection = config_.GetReflection();
63-
info("{} updated from {} to {}", INSTANCE_FIELD.data(),
64-
config_.instance_name(), target.value());
65-
reflection->SetString(
66-
static_cast<google::protobuf::Message*>(&config_),
67-
config_.GetDescriptor()->FindFieldByName(INSTANCE_FIELD.data()),
68-
target.value());
66+
if (target.key() == IGNORE_SUFFIX) {
67+
std::string will_destroy_suffixes;
68+
for (const auto& current_suffix :
69+
config_.ignore_operation_name_suffix()) {
70+
will_destroy_suffixes += current_suffix + ",";
71+
}
72+
will_destroy_suffixes = absl::StripSuffix(will_destroy_suffixes, ",");
73+
74+
config_.clear_ignore_operation_name_suffix();
75+
76+
for (const auto& next_suffix : absl::StrSplit(target.value(), ",")) {
77+
*config_.add_ignore_operation_name_suffix() = next_suffix;
78+
}
79+
80+
info("{} updated from {} to {}", IGNORE_SUFFIX.data(),
81+
will_destroy_suffixes, target.value());
82+
}
83+
6984
config_changed = true;
7085
}
7186

test/cds/config.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/cds/setup.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/dynamic_config_test.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ namespace cpp2sky {
2424
using testing::_;
2525

2626
skywalking::v3::Commands setCommands(std::string uuid_value,
27-
std::string instance_name) {
27+
std::string suffixes) {
2828
skywalking::v3::Commands commands;
2929
auto* command = commands.add_commands();
3030
auto* uuid = command->add_args();
3131
uuid->set_key("UUID");
3232
uuid->set_value(uuid_value);
33-
auto* instance = command->add_args();
34-
instance->set_key("instance_name");
35-
instance->set_value(instance_name);
33+
auto* suffix = command->add_args();
34+
suffix->set_key("ignore_suffix");
35+
suffix->set_value(suffixes);
3636
return commands;
3737
}
3838

@@ -70,7 +70,7 @@ class DynamicConfigTest : public testing::Test {
7070
TEST_F(DynamicConfigTest, ConfigChange) {
7171
setup();
7272

73-
skywalking::v3::Commands commands1 = setCommands("uuid", "instance-updated");
73+
skywalking::v3::Commands commands1 = setCommands("uuid", "ignore1");
7474
update(commands1);
7575
shouldChanged();
7676

@@ -79,24 +79,23 @@ TEST_F(DynamicConfigTest, ConfigChange) {
7979
shouldNotChanged();
8080

8181
// Config updated
82-
skywalking::v3::Commands commands2 =
83-
setCommands("uuid2", "instance-updated-2");
82+
skywalking::v3::Commands commands2 = setCommands("uuid2", "ignore2");
8483
update(commands2);
8584
shouldChanged();
8685

8786
// UUID not set
8887
{
8988
skywalking::v3::Commands commands3;
9089
auto* command = commands3.add_commands();
91-
auto* instance = command->add_args();
92-
instance->set_key("instance_name");
93-
instance->set_value("instance-updated-3");
90+
auto* suffixes = command->add_args();
91+
suffixes->set_key("ignore_suffix");
92+
suffixes->set_value("ignore3");
9493

9594
update(commands3);
9695
shouldNotChanged();
9796
}
9897

99-
// UUID updated but instance name doesn't changed with unknown field
98+
// UUID updated but suffixes name doesn't changed with unknown field
10099
{
101100
skywalking::v3::Commands commands4;
102101
auto* command = commands4.add_commands();
@@ -105,13 +104,13 @@ TEST_F(DynamicConfigTest, ConfigChange) {
105104
uuid->set_value("uuid3");
106105
auto* unknown = command->add_args();
107106
unknown->set_key("unknown");
108-
unknown->set_value("instance-updated-3");
107+
unknown->set_value("suffixes-updated-3");
109108

110109
update(commands4);
111110
shouldNotChanged();
112111
}
113112

114-
// UUID upgraded and instance name changed, with unknown field addition
113+
// UUID upgraded and suffixes name changed, with unknown field addition
115114
{
116115
skywalking::v3::Commands commands5;
117116
auto* command = commands5.add_commands();
@@ -120,10 +119,10 @@ TEST_F(DynamicConfigTest, ConfigChange) {
120119
uuid->set_value("uuid4");
121120
auto* unknown = command->add_args();
122121
unknown->set_key("unknown");
123-
unknown->set_value("instance-updated-3");
124-
auto* instance = command->add_args();
125-
instance->set_key("instance_name");
126-
instance->set_value("instance-updated-3");
122+
unknown->set_value("suffixes-updated-3");
123+
auto* suffixes = command->add_args();
124+
suffixes->set_key("ignore_suffix");
125+
suffixes->set_value("ignore-3");
127126

128127
update(commands5);
129128
shouldChanged();

0 commit comments

Comments
 (0)