Skip to content

Commit

Permalink
Consolidate transport related parameters into a struct.
Browse files Browse the repository at this point in the history
Also, replace leftover cast with getMainConf().
  • Loading branch information
p-pautov committed Dec 19, 2024
1 parent c1883a5 commit 026a78e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/batch_exporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class BatchExporter {
int attrSize{0};
};

BatchExporter(StrView target, bool ssl, const std::string& trustedCert,
BatchExporter(const Target& target,
size_t batchSize, size_t batchCount,
const std::map<StrView, StrView>& resourceAttrs) :
batchSize(batchSize), client(std::string(target), ssl, trustedCert)
batchSize(batchSize), client(target)
{
free.reserve(batchCount);
while (batchCount-- > 0) {
Expand Down
11 changes: 7 additions & 4 deletions src/http_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,13 @@ ngx_int_t initWorkerProcess(ngx_cycle_t* cycle)
}

try {
Target target;
target.endpoint = std::string(toStrView(mcf->endpoint));
target.ssl = mcf->ssl;
target.trustedCert = mcf->trustedCert;

gExporter.reset(new BatchExporter(
toStrView(mcf->endpoint),
mcf->ssl,
mcf->trustedCert,
target,
mcf->batchSize,
mcf->batchCount,
mcf->resourceAttrs));
Expand Down Expand Up @@ -772,7 +775,7 @@ void* createMainConf(ngx_conf_t* cf)

char* initMainConf(ngx_conf_t* cf, void* conf)
{
auto mcf = (MainConf*)conf;
auto mcf = getMainConf(cf);

ngx_conf_init_msec_value(mcf->interval, 5000);
ngx_conf_init_size_value(mcf->batchSize, 512);
Expand Down
16 changes: 11 additions & 5 deletions src/trace_service_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

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

struct Target {
std::string endpoint;
bool ssl;
std::string trustedCert;
};

class TraceServiceClient {
public:
typedef otel_proto_trace::ExportTraceServiceRequest Request;
Expand All @@ -17,18 +23,18 @@ class TraceServiceClient {
typedef std::function<void (Request, Response, grpc::Status)>
ResponseCb;

TraceServiceClient(const std::string& target, bool ssl,
const std::string& trustedCert)
TraceServiceClient(const Target& target)
{
std::shared_ptr<grpc::ChannelCredentials> creds;
if (ssl) {
if (target.ssl) {
grpc::SslCredentialsOptions options;
options.pem_root_certs = trustedCert;
options.pem_root_certs = target.trustedCert;

creds = grpc::SslCredentials(options);
} else {
creds = grpc::InsecureChannelCredentials();
}
auto channel = grpc::CreateChannel(target, creds);
auto channel = grpc::CreateChannel(target.endpoint, creds);
channel->GetState(true); // trigger 'connecting' state

stub = TraceService::NewStub(channel);
Expand Down

0 comments on commit 026a78e

Please sign in to comment.