Consolidate transport related parameters into a struct.
Also, replace leftover cast with getMainConf().
This commit is contained in:
parent
3b6667c808
commit
a23ffa955c
3 changed files with 20 additions and 11 deletions
|
|
@ -111,10 +111,10 @@ public:
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -17,18 +23,18 @@ public:
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue