Skip to content

Commit c50b82d

Browse files
authored
implement operation name suffix ignore matcher (#64)
1 parent 697a5ba commit c50b82d

File tree

16 files changed

+355
-26
lines changed

16 files changed

+355
-26
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ cc_binary(
3131
)
3232
```
3333

34+
#### Docs
35+
36+
cpp2sky configration is based on protobuf, and docs are generated by [protodoc](https://github.com/etcd-io/protodoc). If you have any API change, you should run below.
37+
38+
```
39+
protodoc --directory=./cpp2sky --parse="message" --languages="C++" --title=cpp2sky config --output=docs/README.md
40+
```
41+
3442
## Basic usage
3543

3644
#### Config
3745

38-
cpp2sky provides simple configuration for tracer.
46+
cpp2sky provides simple configuration for tracer. API docs are available at `docs/README.md`.
3947
The detail information is described in [official protobuf definition](https://github.com/apache/skywalking-data-collect-protocol/blob/master/language-agent/Tracing.proto#L57-L67).
4048

4149
```cpp

bazel/repositories.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def cpp2sky_dependencies():
88
com_google_protobuf()
99
com_github_httplib()
1010
com_github_fmtlib_fmt()
11+
com_google_abseil()
1112
com_github_gabime_spdlog()
1213

1314
def skywalking_data_collect_protocol():
@@ -81,3 +82,11 @@ def com_github_gabime_spdlog():
8182
build_file = "//bazel:spdlog.BUILD",
8283
urls = ["https://github.com/gabime/spdlog/archive/v1.7.0.tar.gz"]
8384
)
85+
86+
def com_google_abseil():
87+
http_archive(
88+
name = "com_github_abseil-cpp",
89+
sha256 = "e3812f256dd7347a33bf9d93a950cf356c61c0596842ff07d8154cd415145d83",
90+
strip_prefix = "abseil-cpp-5d8fc9192245f0ea67094af57399d7931d6bd53f",
91+
urls = ["https://github.com/abseil/abseil-cpp/archive/5d8fc9192245f0ea67094af57399d7931d6bd53f.tar.gz"],
92+
)

cpp2sky/config.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ message TracerConfig {
2626
// The size of buffer it stores pending messages.
2727
uint32 delayed_buffer_size = 6;
2828

29+
// If the operation name of the first span is included in this set,
30+
// this segment should be ignored.
31+
repeated string ignore_operation_name_suffix = 8;
32+
2933
// CDS sync request interval. If this value is zero, CDS feature will be disabled.
3034
uint32 cds_request_interval = 7;
3135
}

cpp2sky/internal/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ cc_library(
2828
hdrs = ["stream_builder.h"],
2929
visibility = ["//visibility:public"],
3030
)
31+
32+
cc_library(
33+
name = "matcher_interface",
34+
hdrs = ["matcher.h"],
35+
visibility = ["//visibility:public"],
36+
)

cpp2sky/internal/matcher.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2021 SkyAPM
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <memory>
18+
#include <string_view>
19+
20+
namespace cpp2sky {
21+
22+
class Matcher {
23+
public:
24+
virtual ~Matcher() = default;
25+
26+
/**
27+
* Check whether to match rule.
28+
*/
29+
virtual bool match(std::string_view target) = 0;
30+
};
31+
32+
using MatcherPtr = std::unique_ptr<Matcher>;
33+
34+
} // namespace cpp2sky

cpp2sky/tracer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Tracer {
3535
/**
3636
* Send SegmentContext to the collector.
3737
*/
38-
virtual void report(TracingContextPtr obj) = 0;
38+
virtual bool report(TracingContextPtr obj) = 0;
3939
};
4040

4141
using TracerPtr = std::unique_ptr<Tracer>;

docs/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### cpp2sky
2+
3+
4+
##### message `TracerConfig` (cpp2sky/config.proto)
5+
6+
| Field | Description | Type | C++ |
7+
| ----- | ----------- | ---- | --- |
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 |
16+
17+
18+

source/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ cc_library(
2727
"@com_github_gabime_spdlog//:spdlog",
2828
"//cpp2sky/internal:async_client_interface",
2929
"//cpp2sky/internal:stream_builder_interface",
30+
"//cpp2sky/internal:matcher_interface",
3031
"//cpp2sky:cpp2sky_interface",
3132
"//source/utils:util_lib",
33+
"//source/matchers:suffix_matcher_lib",
3234
],
3335
visibility = ["//visibility:public"],
3436
)
@@ -50,16 +52,18 @@ cc_library(
5052
"@com_github_gabime_spdlog//:spdlog",
5153
"//cpp2sky/internal:async_client_interface",
5254
"//cpp2sky/internal:stream_builder_interface",
55+
"//cpp2sky/internal:matcher_interface",
5356
"//cpp2sky:cpp2sky_interface",
5457
"//source/utils:util_lib",
58+
"//source/matchers:suffix_matcher_lib",
5559
],
5660
copts = ["-DGRPC_TEST"],
5761
visibility = ["//visibility:public"],
5862
)
5963

6064
cc_library(
6165
name = "cpp2sky_data_lib",
62-
hdrs =[
66+
hdrs = [
6367
"propagation_impl.h",
6468
"tracing_context_impl.h",
6569
"dynamic_config.h",

source/matchers/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "suffix_matcher_lib",
5+
hdrs = ["suffix_matcher.h"],
6+
srcs = ["suffix_matcher.cc"],
7+
deps = [
8+
"@com_github_abseil-cpp//absl/strings:strings",
9+
"//cpp2sky/internal:matcher_interface",
10+
],
11+
visibility = ["//visibility:public"],
12+
)

source/matchers/suffix_matcher.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2021 SkyAPM
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "suffix_matcher.h"
16+
17+
#include "absl/strings/match.h"
18+
19+
namespace cpp2sky {
20+
21+
bool SuffixMatcher::match(std::string_view target) {
22+
for (const auto& ignore_suffix : target_suffixes_) {
23+
if (absl::EndsWith(target, ignore_suffix)) {
24+
return true;
25+
}
26+
}
27+
28+
return false;
29+
}
30+
31+
} // namespace cpp2sky

0 commit comments

Comments
 (0)