Skip to content

Commit 88a64bb

Browse files
committed
Consolidate transport related parameters into a struct.
Also, replace leftover cast with getMainConf().
1 parent f633a8e commit 88a64bb

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/batch_exporter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ class BatchExporter {
111111
int attrSize{0};
112112
};
113113

114-
BatchExporter(StrView target, bool ssl, const std::string& trustedCert,
114+
BatchExporter(const Target& target,
115115
size_t batchSize, size_t batchCount,
116116
const std::map<StrView, StrView>& resourceAttrs) :
117-
batchSize(batchSize), client(std::string(target), ssl, trustedCert)
117+
batchSize(batchSize), client(target)
118118
{
119119
free.reserve(batchCount);
120120
while (batchCount-- > 0) {

src/http_module.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,13 @@ ngx_int_t initWorkerProcess(ngx_cycle_t* cycle)
576576
}
577577

578578
try {
579+
Target target;
580+
target.endpoint = std::string(toStrView(mcf->endpoint));
581+
target.ssl = mcf->ssl;
582+
target.trustedCert = mcf->trustedCert;
583+
579584
gExporter.reset(new BatchExporter(
580-
toStrView(mcf->endpoint),
581-
mcf->ssl,
582-
mcf->trustedCert,
585+
target,
583586
mcf->batchSize,
584587
mcf->batchCount,
585588
mcf->resourceAttrs));
@@ -772,7 +775,7 @@ void* createMainConf(ngx_conf_t* cf)
772775

773776
char* initMainConf(ngx_conf_t* cf, void* conf)
774777
{
775-
auto mcf = (MainConf*)conf;
778+
auto mcf = getMainConf(cf);
776779

777780
ngx_conf_init_msec_value(mcf->interval, 5000);
778781
ngx_conf_init_size_value(mcf->batchSize, 512);

src/trace_service_client.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
namespace otel_proto_trace = opentelemetry::proto::collector::trace::v1;
1010

11+
struct Target {
12+
std::string endpoint;
13+
bool ssl;
14+
std::string trustedCert;
15+
};
16+
1117
class TraceServiceClient {
1218
public:
1319
typedef otel_proto_trace::ExportTraceServiceRequest Request;
@@ -17,18 +23,18 @@ class TraceServiceClient {
1723
typedef std::function<void (Request, Response, grpc::Status)>
1824
ResponseCb;
1925

20-
TraceServiceClient(const std::string& target, bool ssl,
21-
const std::string& trustedCert)
26+
TraceServiceClient(const Target& target)
2227
{
2328
std::shared_ptr<grpc::ChannelCredentials> creds;
24-
if (ssl) {
29+
if (target.ssl) {
2530
grpc::SslCredentialsOptions options;
26-
options.pem_root_certs = trustedCert;
31+
options.pem_root_certs = target.trustedCert;
32+
2733
creds = grpc::SslCredentials(options);
2834
} else {
2935
creds = grpc::InsecureChannelCredentials();
3036
}
31-
auto channel = grpc::CreateChannel(target, creds);
37+
auto channel = grpc::CreateChannel(target.endpoint, creds);
3238
channel->GetState(true); // trigger 'connecting' state
3339

3440
stub = TraceService::NewStub(channel);

0 commit comments

Comments
 (0)