Skip to content

Commit daf4751

Browse files
derekarguetamattklein123
authored andcommitted
misc: cleanup - const-ness and more use of abseil string utilities (envoyproxy#9596)
Signed-off-by: Derek Argueta <[email protected]>
1 parent a9f0965 commit daf4751

File tree

78 files changed

+291
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+291
-272
lines changed

include/envoy/network/connection_handler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConnectionHandler {
2222
/**
2323
* @return uint64_t the number of active connections owned by the handler.
2424
*/
25-
virtual uint64_t numConnections() PURE;
25+
virtual uint64_t numConnections() const PURE;
2626

2727
/**
2828
* Increment the return value of numConnections() by one.
@@ -77,7 +77,7 @@ class ConnectionHandler {
7777
/**
7878
* @return the stat prefix used for per-handler stats.
7979
*/
80-
virtual const std::string& statPrefix() PURE;
80+
virtual const std::string& statPrefix() const PURE;
8181

8282
/**
8383
* Used by ConnectionHandler to manage listeners.

include/envoy/router/route_config_update_receiver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class RouteConfigUpdateReceiver {
5353
/**
5454
* @return std::string& the version of RouteConfiguration.
5555
*/
56-
virtual const std::string& configVersion() PURE;
56+
virtual const std::string& configVersion() const PURE;
5757

5858
/**
5959
* @return uint64_t the hash value of RouteConfiguration.

include/envoy/server/configuration.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ class Admin {
8282
/**
8383
* @return const std::string& the admin access log path.
8484
*/
85-
virtual const std::string& accessLogPath() PURE;
85+
virtual const std::string& accessLogPath() const PURE;
8686

8787
/**
8888
* @return const std::string& profiler output path.
8989
*/
90-
virtual const std::string& profilePath() PURE;
90+
virtual const std::string& profilePath() const PURE;
9191

9292
/**
9393
* @return Network::Address::InstanceConstSharedPtr the server address.
@@ -115,7 +115,7 @@ class Initial {
115115
/**
116116
* @return absl::optional<std::string> the path to look for flag files.
117117
*/
118-
virtual absl::optional<std::string> flagsPath() PURE;
118+
virtual absl::optional<std::string> flagsPath() const PURE;
119119

120120
/**
121121
* @return const envoy::config::bootstrap::v2::LayeredRuntime& runtime

include/envoy/server/listener_manager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ListenerManager {
169169
/**
170170
* @return uint64_t the total number of connections owned by all listeners across all workers.
171171
*/
172-
virtual uint64_t numConnections() PURE;
172+
virtual uint64_t numConnections() const PURE;
173173

174174
/**
175175
* Remove a listener by name.

include/envoy/server/worker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Worker {
3535
/**
3636
* @return uint64_t the number of connections across all listeners that the worker owns.
3737
*/
38-
virtual uint64_t numConnections() PURE;
38+
virtual uint64_t numConnections() const PURE;
3939

4040
/**
4141
* Start the worker thread.

source/common/access_log/access_log_formatter.cc

+18-18
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ std::string JsonFormatterImpl::format(const Http::HeaderMap& request_headers,
9999
const auto output_struct =
100100
toStruct(request_headers, response_headers, response_trailers, stream_info);
101101

102-
std::string log_line = MessageUtil::getJsonStringFromMessage(output_struct, false, true);
102+
const std::string log_line = MessageUtil::getJsonStringFromMessage(output_struct, false, true);
103103
return absl::StrCat(log_line, "\n");
104104
}
105105

@@ -115,11 +115,11 @@ ProtobufWkt::Struct JsonFormatterImpl::toStruct(const Http::HeaderMap& request_h
115115

116116
if (providers.size() == 1) {
117117
const auto& provider = providers.front();
118-
auto val = preserve_types_
119-
? provider->formatValue(request_headers, response_headers, response_trailers,
120-
stream_info)
121-
: ValueUtil::stringValue(provider->format(request_headers, response_headers,
122-
response_trailers, stream_info));
118+
const auto val =
119+
preserve_types_ ? provider->formatValue(request_headers, response_headers,
120+
response_trailers, stream_info)
121+
: ValueUtil::stringValue(provider->format(
122+
request_headers, response_headers, response_trailers, stream_info));
123123

124124
(*fields)[pair.first] = val;
125125
} else {
@@ -144,7 +144,7 @@ void AccessLogFormatParser::parseCommandHeader(const std::string& token, const s
144144
throw EnvoyException(
145145
// Header format rules support only one alternative header.
146146
// docs/root/configuration/access_log.rst#format-rules
147-
fmt::format("More than 1 alternative header specified in token: {}", token));
147+
absl::StrCat("More than 1 alternative header specified in token: ", token));
148148
}
149149
if (subs.size() == 1) {
150150
alternative_header = subs.front();
@@ -163,24 +163,24 @@ void AccessLogFormatParser::parseCommand(const std::string& token, const size_t
163163
std::vector<std::string>& sub_items,
164164
absl::optional<size_t>& max_length) {
165165
// TODO(dnoe): Convert this to use string_view throughout.
166-
size_t end_request = token.find(')', start);
166+
const size_t end_request = token.find(')', start);
167167
sub_items.clear();
168168
if (end_request != token.length() - 1) {
169169
// Closing bracket is not found.
170170
if (end_request == std::string::npos) {
171-
throw EnvoyException(fmt::format("Closing bracket is missing in token: {}", token));
171+
throw EnvoyException(absl::StrCat("Closing bracket is missing in token: ", token));
172172
}
173173

174174
// Closing bracket should be either last one or followed by ':' to denote limitation.
175175
if (token[end_request + 1] != ':') {
176-
throw EnvoyException(fmt::format("Incorrect position of ')' in token: {}", token));
176+
throw EnvoyException(absl::StrCat("Incorrect position of ')' in token: ", token));
177177
}
178178

179179
const auto length_str = absl::string_view(token).substr(end_request + 2);
180180
uint64_t length_value;
181181

182182
if (!absl::SimpleAtoi(length_str, &length_value)) {
183-
throw EnvoyException(fmt::format("Length must be an integer, given: {}", length_str));
183+
throw EnvoyException(absl::StrCat("Length must be an integer, given: ", length_str));
184184
}
185185

186186
max_length = length_value;
@@ -218,7 +218,7 @@ std::vector<FormatterProviderPtr> AccessLogFormatParser::parse(const std::string
218218
}
219219

220220
std::smatch m;
221-
std::string search_space = format.substr(pos);
221+
const std::string search_space = format.substr(pos);
222222
if (!(std::regex_search(search_space, m, command_w_args_regex) || m.position() == 0)) {
223223
throw EnvoyException(
224224
fmt::format("Incorrect configuration: {}. Couldn't find valid command at position {}",
@@ -228,7 +228,7 @@ std::vector<FormatterProviderPtr> AccessLogFormatParser::parse(const std::string
228228
const std::string match = m.str(0);
229229
const std::string token = match.substr(1, match.length() - 2);
230230
pos += 1;
231-
int command_end_position = pos + token.length();
231+
const int command_end_position = pos + token.length();
232232

233233
if (absl::StartsWith(token, "REQ(")) {
234234
std::string main_header, alternative_header;
@@ -332,15 +332,15 @@ class StreamInfoOptionalStringFieldExtractor : public StreamInfoFormatter::Field
332332

333333
// StreamInfoFormatter::FieldExtractor
334334
std::string extract(const StreamInfo::StreamInfo& stream_info) const override {
335-
auto str = field_extractor_(stream_info);
335+
const auto str = field_extractor_(stream_info);
336336
if (!str) {
337337
return UnspecifiedValueString;
338338
}
339339

340340
return str.value();
341341
}
342342
ProtobufWkt::Value extractValue(const StreamInfo::StreamInfo& stream_info) const override {
343-
auto str = field_extractor_(stream_info);
343+
const auto str = field_extractor_(stream_info);
344344
if (!str) {
345345
return unspecifiedValue();
346346
}
@@ -362,15 +362,15 @@ class StreamInfoDurationFieldExtractor : public StreamInfoFormatter::FieldExtrac
362362

363363
// StreamInfoFormatter::FieldExtractor
364364
std::string extract(const StreamInfo::StreamInfo& stream_info) const override {
365-
auto millis = extractMillis(stream_info);
365+
const auto millis = extractMillis(stream_info);
366366
if (!millis) {
367367
return UnspecifiedValueString;
368368
}
369369

370370
return fmt::format_int(millis.value()).str();
371371
}
372372
ProtobufWkt::Value extractValue(const StreamInfo::StreamInfo& stream_info) const override {
373-
auto millis = extractMillis(stream_info);
373+
const auto millis = extractMillis(stream_info);
374374
if (!millis) {
375375
return unspecifiedValue();
376376
}
@@ -380,7 +380,7 @@ class StreamInfoDurationFieldExtractor : public StreamInfoFormatter::FieldExtrac
380380

381381
private:
382382
absl::optional<uint32_t> extractMillis(const StreamInfo::StreamInfo& stream_info) const {
383-
auto time = field_extractor_(stream_info);
383+
const auto time = field_extractor_(stream_info);
384384
if (time) {
385385
return std::chrono::duration_cast<std::chrono::milliseconds>(time.value()).count();
386386
}

source/common/common/perf_annotation.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::string PerfAnnotationContext::toString() {
108108
: std::to_string(
109109
std::chrono::duration_cast<std::chrono::nanoseconds>(stats.total_).count() /
110110
count));
111-
columns[3].push_back(fmt::format("{}", stats.stddev_.computeStandardDeviation()));
111+
columns[3].push_back(absl::StrCat("", stats.stddev_.computeStandardDeviation()));
112112
columns[4].push_back(nanoseconds_string(stats.min_));
113113
columns[5].push_back(nanoseconds_string(stats.max_));
114114
const CategoryDescription& category_description = p->first;

source/common/config/config_provider_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ConfigSubscriptionCommonBase : protected Logger::Loggable<Logger::Id::conf
204204
ConfigProviderManagerImplBase& config_provider_manager,
205205
Server::Configuration::FactoryContext& factory_context)
206206
: name_(name), tls_(factory_context.threadLocal().allocateSlot()),
207-
init_target_(fmt::format("ConfigSubscriptionCommonBase {}", name_), [this]() { start(); }),
207+
init_target_(absl::StrCat("ConfigSubscriptionCommonBase ", name_), [this]() { start(); }),
208208
manager_identifier_(manager_identifier), config_provider_manager_(config_provider_manager),
209209
time_source_(factory_context.timeSource()),
210210
last_updated_(factory_context.timeSource().systemTime()) {

source/common/filesystem/inotify/watcher_impl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void WatcherImpl::addWatch(const std::string& path, uint32_t events, OnChangedCb
3535
// and then synthetically raise per file events.
3636
size_t last_slash = path.rfind('/');
3737
if (last_slash == std::string::npos) {
38-
throw EnvoyException(fmt::format("invalid watch path {}", path));
38+
throw EnvoyException(absl::StrCat("invalid watch path ", path));
3939
}
4040

4141
std::string directory = last_slash != 0 ? path.substr(0, last_slash) : "/";

source/common/filesystem/kqueue/watcher_impl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ WatcherImpl::~WatcherImpl() {
3434
void WatcherImpl::addWatch(const std::string& path, uint32_t events, Watcher::OnChangedCb cb) {
3535
FileWatchPtr watch = addWatch(path, events, cb, false);
3636
if (watch == nullptr) {
37-
throw EnvoyException(fmt::format("invalid watch path {}", path));
37+
throw EnvoyException(absl::StrCat("invalid watch path ", path));
3838
}
3939
}
4040

source/common/filesystem/posix/filesystem_impl.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "common/filesystem/filesystem_impl.h"
1818

1919
#include "absl/strings/match.h"
20+
#include "absl/strings/str_cat.h"
2021

2122
namespace Envoy {
2223
namespace Filesystem {
@@ -91,14 +92,14 @@ ssize_t InstanceImplPosix::fileSize(const std::string& path) {
9192

9293
std::string InstanceImplPosix::fileReadToEnd(const std::string& path) {
9394
if (illegalPath(path)) {
94-
throw EnvoyException(fmt::format("Invalid path: {}", path));
95+
throw EnvoyException(absl::StrCat("Invalid path: ", path));
9596
}
9697

9798
std::ios::sync_with_stdio(false);
9899

99100
std::ifstream file(path);
100101
if (file.fail()) {
101-
throw EnvoyException(fmt::format("unable to read file: {}", path));
102+
throw EnvoyException(absl::StrCat("unable to read file: ", path));
102103
}
103104

104105
std::stringstream file_string;

source/common/filesystem/win32/filesystem_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ssize_t InstanceImplWin32::fileSize(const std::string& path) {
8484

8585
std::string InstanceImplWin32::fileReadToEnd(const std::string& path) {
8686
if (illegalPath(path)) {
87-
throw EnvoyException(fmt::format("Invalid path: {}", path));
87+
throw EnvoyException(absl::StrCat("Invalid path: ", path));
8888
}
8989

9090
std::ios::sync_with_stdio(false);
@@ -93,7 +93,7 @@ std::string InstanceImplWin32::fileReadToEnd(const std::string& path) {
9393
// 0x1a will be treated as EOF
9494
std::ifstream file(path, std::ios_base::binary);
9595
if (file.fail()) {
96-
throw EnvoyException(fmt::format("unable to read file: {}", path));
96+
throw EnvoyException(absl::StrCat("unable to read file: ", path));
9797
}
9898

9999
std::stringstream file_string;

source/common/grpc/google_async_client_impl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ GoogleAsyncClientImpl::GoogleAsyncClientImpl(
8484
// Initialize client stats.
8585
stats_.streams_total_ = &scope_->counter("streams_total");
8686
for (uint32_t i = 0; i <= Status::WellKnownGrpcStatus::MaximumKnown; ++i) {
87-
stats_.streams_closed_[i] = &scope_->counter(fmt::format("streams_closed_{}", i));
87+
stats_.streams_closed_[i] = &scope_->counter(absl::StrCat("streams_closed_", i));
8888
}
8989
}
9090

source/common/grpc/google_grpc_creds_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ getGoogleGrpcChannelCredentials(const envoy::config::core::v3alpha::GrpcService&
166166
google_grpc_credentials_factory_name);
167167
}
168168
if (credentials_factory == nullptr) {
169-
throw EnvoyException(fmt::format("Unknown google grpc credentials factory: {}",
170-
google_grpc_credentials_factory_name));
169+
throw EnvoyException(absl::StrCat("Unknown google grpc credentials factory: ",
170+
google_grpc_credentials_factory_name));
171171
}
172172
return credentials_factory->getChannelCredentials(grpc_service, api);
173173
}

source/common/http/conn_manager_config.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class ConnectionManagerConfig {
209209
* @return the time in milliseconds the connection manager will wait between issuing a "shutdown
210210
* notice" to the time it will issue a full GOAWAY and not accept any new streams.
211211
*/
212-
virtual std::chrono::milliseconds drainTimeout() PURE;
212+
virtual std::chrono::milliseconds drainTimeout() const PURE;
213213

214214
/**
215215
* @return FilterChainFactory& the HTTP level filter factory to build the connection's filter
@@ -221,7 +221,7 @@ class ConnectionManagerConfig {
221221
* @return whether the connection manager will generate a fresh x-request-id if the request does
222222
* not have one.
223223
*/
224-
virtual bool generateRequestId() PURE;
224+
virtual bool generateRequestId() const PURE;
225225

226226
/**
227227
* @return whether the x-request-id should not be reset on edge entry inside mesh
@@ -289,12 +289,13 @@ class ConnectionManagerConfig {
289289
/**
290290
* @return const std::string& the server name to write into responses.
291291
*/
292-
virtual const std::string& serverName() PURE;
292+
virtual const std::string& serverName() const PURE;
293293

294294
/**
295295
* @return ServerHeaderTransformation the transformation to apply to Server response headers.
296296
*/
297-
virtual HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() PURE;
297+
virtual HttpConnectionManagerProto::ServerHeaderTransformation
298+
serverHeaderTransformation() const PURE;
298299

299300
/**
300301
* @return ConnectionManagerStats& the stats to write to.
@@ -310,7 +311,7 @@ class ConnectionManagerConfig {
310311
* @return bool whether to use the remote address for populating XFF, determining internal request
311312
* status, etc. or to assume that XFF will already be populated with the remote address.
312313
*/
313-
virtual bool useRemoteAddress() PURE;
314+
virtual bool useRemoteAddress() const PURE;
314315

315316
/**
316317
* @return InternalAddressConfig configuration for user defined internal addresses.
@@ -339,7 +340,7 @@ class ConnectionManagerConfig {
339340
/**
340341
* @return ForwardClientCertType the configuration of how to forward the client cert information.
341342
*/
342-
virtual ForwardClientCertType forwardClientCert() PURE;
343+
virtual ForwardClientCertType forwardClientCert() const PURE;
343344

344345
/**
345346
* @return vector of ClientCertDetailsType the configuration of the current client cert's details

source/common/http/conn_manager_impl.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include "absl/strings/escaping.h"
4444
#include "absl/strings/match.h"
45+
#include "absl/strings/str_cat.h"
4546

4647
namespace Envoy {
4748
namespace Http {
@@ -483,7 +484,7 @@ void ConnectionManagerImpl::chargeTracingStats(const Tracing::Reason& tracing_re
483484
break;
484485
default:
485486
throw std::invalid_argument(
486-
fmt::format("invalid tracing reason, value: {}", static_cast<int32_t>(tracing_reason)));
487+
absl::StrCat("invalid tracing reason, value: ", static_cast<int32_t>(tracing_reason)));
487488
}
488489
}
489490

source/common/http/hash_policy.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "common/http/utility.h"
66

7+
#include "absl/strings/str_cat.h"
8+
79
namespace Envoy {
810
namespace Http {
911

@@ -143,7 +145,7 @@ HashPolicyImpl::HashPolicyImpl(
143145
break;
144146
default:
145147
throw EnvoyException(
146-
fmt::format("Unsupported hash policy {}", hash_policy->policy_specifier_case()));
148+
absl::StrCat("Unsupported hash policy ", hash_policy->policy_specifier_case()));
147149
}
148150
}
149151
}

source/common/http/http2/codec_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void ConnectionImpl::sendPendingFrames() {
825825
return;
826826
}
827827

828-
int rc = nghttp2_session_send(session_);
828+
const int rc = nghttp2_session_send(session_);
829829
if (rc != 0) {
830830
ASSERT(rc == NGHTTP2_ERR_CALLBACK_FAILURE);
831831
// For errors caused by the pending outbound frame flood the FrameFloodException has
@@ -837,7 +837,7 @@ void ConnectionImpl::sendPendingFrames() {
837837
throw FrameFloodException("Too many frames in the outbound queue.");
838838
}
839839

840-
throw CodecProtocolException(fmt::format("{}", nghttp2_strerror(rc)));
840+
throw CodecProtocolException(std::string(nghttp2_strerror(rc)));
841841
}
842842

843843
// See ConnectionImpl::StreamImpl::resetStream() for why we do this. This is an uncommon event,

0 commit comments

Comments
 (0)