Skip to content

Commit 3298107

Browse files
authored
Merge pull request #63 from open-telemetry/main
[Code Health] Clang Tidy cleanup, Part 2 (open-telemetry#3038)
2 parents 151e31f + a71642f commit 3298107

34 files changed

+127
-125
lines changed

.clang-tidy

+3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ Checks: >
3131
-misc-unused-alias-decls,
3232
-misc-use-anonymous-namespace,
3333
cppcoreguidelines-*,
34+
-cppcoreguidelines-owning-memory,
35+
-cppcoreguidelines-avoid-do-while,
3436
-cppcoreguidelines-avoid-c-arrays,
3537
-cppcoreguidelines-avoid-magic-numbers,
3638
-cppcoreguidelines-init-variables,
3739
-cppcoreguidelines-macro-usage,
3840
-cppcoreguidelines-non-private-member-variables-in-classes,
41+
-cppcoreguidelines-avoid-non-const-global-variables,
3942
-cppcoreguidelines-pro-*

.github/workflows/clang-tidy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Run clang-tidy
6969
run: |
7070
cd build
71-
make -j$(nproc) 2>&1 | tee -a clang-tidy.log || exit 1
71+
make 2>&1 | tee -a clang-tidy.log || exit 1
7272
7373
- uses: actions/upload-artifact@v4
7474
with:

api/test/baggage/propagation/baggage_propagator_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BaggageCarrierTest : public context::propagation::TextMapCarrier
1515
{
1616
public:
1717
BaggageCarrierTest() = default;
18-
virtual nostd::string_view Get(nostd::string_view key) const noexcept override
18+
nostd::string_view Get(nostd::string_view key) const noexcept override
1919
{
2020
auto it = headers_.find(std::string(key));
2121
if (it != headers_.end())
@@ -24,7 +24,7 @@ class BaggageCarrierTest : public context::propagation::TextMapCarrier
2424
}
2525
return "";
2626
}
27-
virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override
27+
void Set(nostd::string_view key, nostd::string_view value) noexcept override
2828
{
2929
headers_[std::string(key)] = std::string(value);
3030
}

api/test/context/propagation/composite_propagator_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static std::string Hex(const T &id_item)
3131
class TextMapCarrierTest : public context::propagation::TextMapCarrier
3232
{
3333
public:
34-
virtual nostd::string_view Get(nostd::string_view key) const noexcept override
34+
nostd::string_view Get(nostd::string_view key) const noexcept override
3535
{
3636
auto it = headers_.find(std::string(key));
3737
if (it != headers_.end())
@@ -40,7 +40,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier
4040
}
4141
return "";
4242
}
43-
virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override
43+
void Set(nostd::string_view key, nostd::string_view value) noexcept override
4444
{
4545
headers_[std::string(key)] = std::string(value);
4646
}
@@ -66,7 +66,7 @@ class CompositePropagatorTest : public ::testing::Test
6666
new context::propagation::CompositePropagator(std::move(propogator_list));
6767
}
6868

69-
~CompositePropagatorTest() { delete composite_propagator_; }
69+
~CompositePropagatorTest() override { delete composite_propagator_; }
7070

7171
protected:
7272
context::propagation::CompositePropagator *composite_propagator_;

api/test/logs/logger_benchmark.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ constexpr int64_t kMaxIterations = 1000000000;
3232
class Barrier
3333
{
3434
public:
35-
explicit Barrier(std::size_t iCount) : mThreshold(iCount), mCount(iCount), mGeneration(0) {}
35+
explicit Barrier(std::size_t iCount) : mThreshold(iCount), mCount(iCount) {}
3636

3737
void Wait()
3838
{
@@ -55,7 +55,7 @@ class Barrier
5555
std::condition_variable mCond;
5656
std::size_t mThreshold;
5757
std::size_t mCount;
58-
std::size_t mGeneration;
58+
std::size_t mGeneration{0};
5959
};
6060

6161
static void ThreadRoutine(Barrier &barrier,
@@ -84,14 +84,14 @@ static void ThreadRoutine(Barrier &barrier,
8484

8585
void MultiThreadRunner(benchmark::State &state, const std::function<void()> &func)
8686
{
87-
int num_threads = std::thread::hardware_concurrency();
87+
uint32_t num_threads = std::thread::hardware_concurrency();
8888

8989
Barrier barrier(num_threads);
9090

9191
std::vector<std::thread> threads;
9292

9393
threads.reserve(num_threads);
94-
for (int i = 0; i < num_threads; i++)
94+
for (uint32_t i = 0; i < num_threads; i++)
9595
{
9696
threads.emplace_back(ThreadRoutine, std::ref(barrier), std::ref(state), i, func);
9797
}

api/test/nostd/shared_ptr_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class C
3535
class D : public C
3636
{
3737
public:
38-
virtual ~D() {}
38+
~D() override {}
3939
};
4040

4141
TEST(SharedPtrTest, DefaultConstruction)

api/test/trace/propagation/b3_propagation_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace opentelemetry;
1515
class TextMapCarrierTest : public context::propagation::TextMapCarrier
1616
{
1717
public:
18-
virtual nostd::string_view Get(nostd::string_view key) const noexcept override
18+
nostd::string_view Get(nostd::string_view key) const noexcept override
1919
{
2020
auto it = headers_.find(std::string(key));
2121
if (it != headers_.end())
@@ -24,7 +24,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier
2424
}
2525
return "";
2626
}
27-
virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override
27+
void Set(nostd::string_view key, nostd::string_view value) noexcept override
2828
{
2929
headers_[std::string(key)] = std::string(value);
3030
}

api/test/trace/propagation/http_text_format_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace opentelemetry;
1818
class TextMapCarrierTest : public context::propagation::TextMapCarrier
1919
{
2020
public:
21-
virtual nostd::string_view Get(nostd::string_view key) const noexcept override
21+
nostd::string_view Get(nostd::string_view key) const noexcept override
2222
{
2323
auto it = headers_.find(std::string(key));
2424
if (it != headers_.end())
@@ -27,7 +27,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier
2727
}
2828
return "";
2929
}
30-
virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override
30+
void Set(nostd::string_view key, nostd::string_view value) noexcept override
3131
{
3232
headers_[std::string(key)] = std::string(value);
3333
}

api/test/trace/propagation/jaeger_propagation_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace opentelemetry;
1414
class TextMapCarrierTest : public context::propagation::TextMapCarrier
1515
{
1616
public:
17-
virtual nostd::string_view Get(nostd::string_view key) const noexcept override
17+
nostd::string_view Get(nostd::string_view key) const noexcept override
1818
{
1919
auto it = headers_.find(std::string(key));
2020
if (it != headers_.end())
@@ -23,7 +23,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier
2323
}
2424
return "";
2525
}
26-
virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override
26+
void Set(nostd::string_view key, nostd::string_view value) noexcept override
2727
{
2828
headers_[std::string(key)] = std::string(value);
2929
}

examples/http/server.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ constexpr const char *server_name = "localhost";
2121
class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback
2222
{
2323
public:
24-
virtual int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request,
25-
HTTP_SERVER_NS::HttpResponse &response) override
24+
int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request,
25+
HTTP_SERVER_NS::HttpResponse &response) override
2626
{
2727
StartSpanOptions options;
2828
options.kind = SpanKind::kServer; // server

exporters/otlp/src/otlp_file_client.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
966966
{
967967
public:
968968
explicit OtlpFileSystemBackend(const OtlpFileClientFileSystemOptions &options)
969-
: options_(options), is_initialized_{false}, check_file_path_interval_{0}
969+
: options_(options), is_initialized_{false}
970970
{
971971
file_ = std::make_shared<FileStats>();
972972
file_->is_shutdown.store(false);
@@ -1539,7 +1539,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
15391539
std::shared_ptr<FileStats> file_;
15401540

15411541
std::atomic<bool> is_initialized_;
1542-
std::time_t check_file_path_interval_;
1542+
std::time_t check_file_path_interval_{0};
15431543
};
15441544

15451545
class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppender
@@ -1568,7 +1568,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppende
15681568
};
15691569

15701570
OtlpFileClient::OtlpFileClient(OtlpFileClientOptions &&options)
1571-
: is_shutdown_(false), options_(options)
1571+
: is_shutdown_(false), options_(std::move(options))
15721572
{
15731573
if (nostd::holds_alternative<OtlpFileClientFileSystemOptions>(options_.backend_options))
15741574
{

exporters/otlp/src/otlp_file_metric_exporter_options.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace otlp
1313
{
1414

1515
OtlpFileMetricExporterOptions::OtlpFileMetricExporterOptions()
16+
: aggregation_temporality(PreferredAggregationTemporality::kCumulative)
1617
{
1718
console_debug = false;
1819

@@ -25,8 +26,6 @@ OtlpFileMetricExporterOptions::OtlpFileMetricExporterOptions()
2526
fs_options.rotate_size = 10;
2627

2728
backend_options = fs_options;
28-
29-
aggregation_temporality = PreferredAggregationTemporality::kCumulative;
3029
}
3130

3231
OtlpFileMetricExporterOptions::~OtlpFileMetricExporterOptions() {}

exporters/otlp/src/otlp_grpc_metric_exporter_options.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace otlp
1111
{
1212

1313
OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions()
14+
: aggregation_temporality(PreferredAggregationTemporality::kCumulative)
1415
{
1516
endpoint = GetOtlpDefaultGrpcMetricsEndpoint();
1617
use_ssl_credentials = !GetOtlpDefaultGrpcMetricsIsInsecure(); /* negation intended. */
@@ -28,8 +29,6 @@ OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions()
2829
metadata = GetOtlpDefaultMetricsHeaders();
2930
user_agent = GetOtlpDefaultUserAgent();
3031

31-
aggregation_temporality = PreferredAggregationTemporality::kCumulative;
32-
3332
max_threads = 0;
3433

3534
compression = GetOtlpDefaultMetricsCompression();

exporters/otlp/src/otlp_http_client.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ OtlpHttpClient::~OtlpHttpClient()
708708
OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options,
709709
std::shared_ptr<ext::http::client::HttpClient> http_client)
710710
: is_shutdown_(false),
711-
options_(options),
711+
options_(std::move(options)),
712712
http_client_(std::move(http_client)),
713713
start_session_counter_(0),
714714
finished_session_counter_(0)

exporters/otlp/src/otlp_http_exporter_options.cc

+15-14
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,28 @@ namespace otlp
1616
{
1717

1818
OtlpHttpExporterOptions::OtlpHttpExporterOptions()
19+
: json_bytes_mapping(JsonBytesMappingKind::kHexId),
20+
use_json_name(false),
21+
console_debug(false),
22+
ssl_insecure_skip_verify(false)
1923
{
20-
url = GetOtlpDefaultHttpTracesEndpoint();
21-
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpTracesProtocol());
22-
json_bytes_mapping = JsonBytesMappingKind::kHexId;
23-
use_json_name = false;
24-
console_debug = false;
25-
timeout = GetOtlpDefaultTracesTimeout();
26-
http_headers = GetOtlpDefaultTracesHeaders();
24+
url = GetOtlpDefaultHttpTracesEndpoint();
25+
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpTracesProtocol());
26+
27+
timeout = GetOtlpDefaultTracesTimeout();
28+
http_headers = GetOtlpDefaultTracesHeaders();
2729

2830
#ifdef ENABLE_ASYNC_EXPORT
2931
max_concurrent_requests = 64;
3032
max_requests_per_connection = 8;
3133
#endif /* ENABLE_ASYNC_EXPORT */
3234

33-
ssl_insecure_skip_verify = false;
34-
ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath();
35-
ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString();
36-
ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath();
37-
ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString();
38-
ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath();
39-
ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString();
35+
ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath();
36+
ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString();
37+
ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath();
38+
ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString();
39+
ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath();
40+
ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString();
4041

4142
ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion();
4243
ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion();

exporters/otlp/src/otlp_http_log_record_exporter_options.cc

+15-14
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,28 @@ namespace otlp
1616
{
1717

1818
OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions()
19+
: json_bytes_mapping(JsonBytesMappingKind::kHexId),
20+
use_json_name(false),
21+
console_debug(false),
22+
ssl_insecure_skip_verify(false)
1923
{
20-
url = GetOtlpDefaultHttpLogsEndpoint();
21-
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpLogsProtocol());
22-
json_bytes_mapping = JsonBytesMappingKind::kHexId;
23-
use_json_name = false;
24-
console_debug = false;
25-
timeout = GetOtlpDefaultLogsTimeout();
26-
http_headers = GetOtlpDefaultLogsHeaders();
24+
url = GetOtlpDefaultHttpLogsEndpoint();
25+
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpLogsProtocol());
26+
27+
timeout = GetOtlpDefaultLogsTimeout();
28+
http_headers = GetOtlpDefaultLogsHeaders();
2729

2830
#ifdef ENABLE_ASYNC_EXPORT
2931
max_concurrent_requests = 64;
3032
max_requests_per_connection = 8;
3133
#endif
3234

33-
ssl_insecure_skip_verify = false;
34-
ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath();
35-
ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString();
36-
ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath();
37-
ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString();
38-
ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath();
39-
ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString();
35+
ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath();
36+
ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString();
37+
ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath();
38+
ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString();
39+
ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath();
40+
ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString();
4041

4142
ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion();
4243
ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion();

exporters/otlp/src/otlp_http_metric_exporter_options.cc

+16-15
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@ namespace otlp
1717
{
1818

1919
OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions()
20+
: json_bytes_mapping(JsonBytesMappingKind::kHexId),
21+
use_json_name(false),
22+
console_debug(false),
23+
aggregation_temporality(PreferredAggregationTemporality::kCumulative),
24+
ssl_insecure_skip_verify(false)
2025
{
21-
url = GetOtlpDefaultMetricsEndpoint();
22-
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpMetricsProtocol());
23-
json_bytes_mapping = JsonBytesMappingKind::kHexId;
24-
use_json_name = false;
25-
console_debug = false;
26-
timeout = GetOtlpDefaultMetricsTimeout();
27-
http_headers = GetOtlpDefaultMetricsHeaders();
28-
aggregation_temporality = PreferredAggregationTemporality::kCumulative;
26+
url = GetOtlpDefaultMetricsEndpoint();
27+
content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpMetricsProtocol());
28+
29+
timeout = GetOtlpDefaultMetricsTimeout();
30+
http_headers = GetOtlpDefaultMetricsHeaders();
2931

3032
#ifdef ENABLE_ASYNC_EXPORT
3133
max_concurrent_requests = 64;
3234
max_requests_per_connection = 8;
3335
#endif
3436

35-
ssl_insecure_skip_verify = false;
36-
ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath();
37-
ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString();
38-
ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath();
39-
ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString();
40-
ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath();
41-
ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString();
37+
ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath();
38+
ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString();
39+
ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath();
40+
ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString();
41+
ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath();
42+
ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString();
4243

4344
ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion();
4445
ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion();

0 commit comments

Comments
 (0)